Get Audio From An Html5 Video
Is it possible to get the audio from an mp4 or webm video element in HTML5? I'm trying to use https://github.com/corbanbrook/dsp.js to calculate FFTs for audio, however, I only hav
Solution 1:
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><metacharset="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 = newwebkitAudioContext();
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/112368window.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.
Solution 2:
Webm works as an audio source.
<audiocontrols="controls"class="full-width"preload="metadata"><sourcesrc="//rack.international/samples/sample.webm"type="audio/mpeg"></audio>
<videosrc="https://rack.international/samples/sample.webm"controls><p>Your browser doesn't support HTML5 video. Here is a <ahref="rabbit320.webm">link to the video</a> instead.</p></video>
Post a Comment for "Get Audio From An Html5 Video"