使用javascript从视频流中提取音频

问题描述:

我想使用javascript从视频文件中提取音频,是否可以制作mp3文件或其他任何格式,以便我可以在html5的音频标签中播放它?如果是,怎么办?或者我应该使用什么API?

I want to extract audio from a video file using javascript, is it possible to make a mp3 file or any format so that i can play it in an audio tag in html5 ? if yes how? OR what API should I use ?

那么,这不是最佳解决方案.实际上,这有点可怕,因为您将迫使用户下载视频而看不到它.您可以做的是将文件播放为HTML5视频,然后隐藏视频显示,然后像显示音频一样显示控件.这有点像播放视频,只是在听音频的同时不看视频.

Sooo, this is NOT an optimal solution. It is sort of terrible actually since you will forcing users to download a video without seeing it. What you could do is play the file as HTML5 video and just hide the video display then show controls as if it were just audio. This is sort of like playing a video, but just not watching the video while listening to the audio.

结帐jPlayer: http://jplayer.org/

Checkout jPlayer: http://jplayer.org/

它可以让您基本上在任何浏览器上播放MP4,方法是告诉它使用Flash,然后在需要时使用HTML5.然后,您可以使用CSS/HTML/Images随意设置样式.

It will let you play an MP4 basically on any browser by telling it to use flash then falling back to HTML5 when you need it to. Then you can just style things how you want using CSS/HTML/Images.

您可能想先尝试进行一次小测试,以查看 display:none; css样式是否还会阻止视频音频的播放.如果是这种情况,您还可以使用 height:0; ;

You might want to try a small test first to see if the display:none; css style will also prevent the video's audio from playing. If that is the case you could also use height:0;;

再一次,由于占用了用户的带宽,因此这不是最佳选择.还有其他解决方案可能会在流环境中为您剥离音频.

Once again, this is sub-optimal since you are taking up the user's bandwidth. There are other solutions out there that could potentially strip out just the audio for you in a streaming environment.