0

I am making a video editing tool, where the user loads a local video into the application and edits it. For this I have to extract audio from the local file.

Currently I am loading the video file through a XMLHttpRequest which gives a arraybuffer as output. From this arraybuffer using decodeAudioData from audioContext Object I am getting AudioBuffer, which is used to paint the canvas.

let audioContext =  new (window.AudioContext || window.webkitAudioContext)();
var req = new XMLHttpRequest();
req.open('GET', this.props.videoFileURL, true);
req.responseType = 'arraybuffer';
req.onload = e => {
        audioContext.decodeAudioData(
            req.response,
            buffer => {
              this.currentBuffer = buffer;
              this.props.setAudioBuffer(buffer);
              requestAnimationFrame(this.updateCanvas);
            },
            this.onDecodeError
          );
          console.log(req.response);
        };
req.send(); 

This is working for most mp4 files but I am getting decodeError when I test with MPEG-1/2 encoded video files

Edit 1 : I understand this is a demux issue, I am not able to find demuxer for mpeg-1

StarLord
  • 1,012
  • 1
  • 11
  • 22
  • Can the browser play this audio in a MediaElement (` – Kaiido Feb 01 '18 at 06:22
  • no, browser cant play this container format, If i can get a demux for mpeg-1 then I can separate the audio stream then any mp2 decoder will work for decoding the data. – StarLord Feb 01 '18 at 06:49
  • But if the browser can not play the audio stream, you won't be able to do so using the browser native methods (e.g decodeAudioData). So what you are after is an mp4 parser able to extract the audio stream from your mp4, and then a demux able to convert this stream to something the browser understands or directly to raw PCM. I don't know any such tools for js, but it makes your question fall into the *Question asking us to find or recommend a tool ...* category, which is off-topic for SO. Also, is it possible for you to preprocess these files server-side before you handle them with js? – Kaiido Feb 01 '18 at 06:55

0 Answers0