Get audio from an html5 video

旧城冷巷雨未停 提交于 2019-12-02 17:46:54

Not sure if this answers your question but you can run the audio of the video through the Web Audio API node graph. The code below can be demonstrated by changing the gain and filter parameters. I only tested this on 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>

The above code is a modified version of this : http://updates.html5rocks.com/2012/02/HTML5-audio-and-the-Web-Audio-API-are-BFFs

I simply replaced the audio element with the video element.

Webm works as an audio source.

<audio controls="controls" class="full-width" preload="metadata">
  <source src="//rack.international/samples/sample.webm" type="audio/mpeg">
</audio>

<video src="https://rack.international/samples/sample.webm" controls>
  <p>Your browser doesn't support HTML5 video. Here is a <a href="rabbit320.webm">link to the video</a> instead.</p> 
</video>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!