使用javascript从本地MPEG-1/2文件中获取音频数据

时间:2018-01-31 10:39:44

标签: javascript audio decode mpeg

我正在制作视频编辑工具,用户将本地视频加载到应用程序中并进行编辑。为此,我必须从本地文件中提取音频。

目前我正在通过XMLHttpRequest加载视频文件,它提供了一个arraybuffer作为输出。从这个使用audioContext对象的decodeAudioData的arraybuffer我得到了AudioBuffer,它用于绘制画布。

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(); 

适用于大多数mp4 文件但我在使用 MPEG-1/2编码视频文件进行测试时 decodeError

编辑1: 我知道这是一个demux问题,我无法找到mpeg-1

的demuxer

0 个答案:

没有答案