如何从HTML5 Javascript视频中提取音轨作为原始音频数据? IE。一系列 sample ?

我对HTML5 Video API完全陌生,因此举个例子非常棒。

最佳答案

Web Audio API正是您想要的。特别是,您要将 MediaElementAudioSourceNode 馈入 AnalyserNode 。不幸的是,Web Audio API仅在Chrome中实现(某种程度上在FF中实现),甚至是Chrome doesn't have full support for MediaElementAudioSourceNode yet

var context = new webkitAudioContext();

// feed video into a MediaElementSourceNode, and feed that into AnalyserNode
// due to a bug in Chrome, this must run after onload
var videoElement = document.querySelector('myVideo');
var mediaSourceNode = context.createMediaElementSource(videoElement);
var analyserNode = context.createAnalyser();
mediaSourceNode.connect(analyserNode);
analyserNode.connect(context.destination);

videoElement.play();

// run this part on loop to sample the current audio position
sample = new Float32Array(analyser.frequencyBinCount);
analyser.getFloatFrequencyData(sample);

09-19 16:26