从html5视频获取音频 [英] Get audio from an html5 video

查看:208
本文介绍了从html5视频获取音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从HTML5中的mp4或webm视频元素中获取音频?

Is it possible to get the audio from an mp4 or webm video element in HTML5?

我正在尝试使用 https://github.com/corbanbrook/dsp.js计算音频的FFT,但是,我只有mp4和webm视频.

I'm trying to use https://github.com/corbanbrook/dsp.js to calculate FFTs for audio, however, I only have the mp4 and webm videos.

推荐答案

不确定是否可以回答您的问题,但是您可以通过Web Audio API节点图来运行视频的音频.可以通过更改增益和滤波器参数来演示以下代码.我只在Chrome上测试过.

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>

上面的代码是对此的修改版本: http://updates.html5rocks.com/2012/02/HTML5-音频和网络音频API-BFF

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.

这篇关于从html5视频获取音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆