是否可以从
HTML5中的mp4或webm视频元素获取音频?
我正在尝试使用https://github.com/corbanbrook/dsp.js来计算音频的FFT,但是,我只有mp4和webm视频.
解决方法
不确定是否回答您的问题,但您可以通过Web Audio API节点图来运行视频的音频.以下代码可以通过改变增益和滤波器参数来证明.我只是在Chrome上测试过.
<!DOCTYPE html> <Meta charset="UTF-8"> <title></title> <body> </body> <script> var video = document.createElement("video"); video.setAttribute("src","ourMovie.mov"); video.controls = true; video.autoplay = true; document.body.appendChild(video); var context = new webkitAudioContext(); var gainNode = context.createGain(); gainNode.gain.value = 1; // Change Gain Value to test filter = context.createBiquadFilter(); filter.type = 2; // Change Filter type to test filter.frequency.value = 5040; // Change frequency to test // Wait for window.onload to fire. See crbug.com/112368 window.addEventListener('load',function(e) { // Our <video> element will be the audio source. var source = context.createMediaElementSource(video); source.connect(gainNode); gainNode.connect(filter); filter.connect(context.destination); },false); </script>
以上代码是这样的修改版本:
http://updates.html5rocks.com/2012/02/HTML5-audio-and-the-Web-Audio-API-are-BFFs
我只是用视频元素替换音频元素.