使用媒体源 API...
我意识到这与上面回答的回退无关,但我认为重要的是要指出,如果 MP4 视频编码正确,则不需要回退到 webm。
还可以对 MP4 视频进行编码以支持 Media Source API,它允许在整个文件完成下载之前下载使视频可用的块。
MP4 实现使用更广泛,在大多数浏览器中不需要 webm 后备。
显示Media Source API here的视频格式支持的图表。
FFmpeg 会这样做,它的开源。
见此处:(Encode h.264 and WebM videos for MediaElement.js using FFmpeg) 下方:
Chris Coulson 写道:2012 年 6 月 14 日(Windows)
我最近在客户的网站上添加了一个视频播放器。我发现 John Dyer 的 MediaElement.js 是一个很好的解决方案。只要您同时提供视频的 h.264 和 WebM 编码版本,它就会在几乎所有浏览器上原生播放。对于不受支持的浏览器,它将回退到 Flash。
客户的视频都是wmv的,所以需要转成h.264和WebM。幸运的是,John 还提供了一些使用 FFmpeg 对这些格式进行编码的指导:
http://johndyer.name/ffmpeg-settings-for-html5-codecs-h264mp4-theoraogg-vp8webm/
不幸的是,自发布命令以来,FFmpeg 发生了变化,因此需要进行一些细微的修改。我还进行了一些修改,以便保留视频的纵横比,并以更低的比特率和更快的速度对视频进行编码。同样,一些正在转换的视频非常短,并且会在创建缩略图的 10 秒标记之前完成。为了解决这个问题,我修改了脚本以尝试在 1、2、3、5 和 10 秒标记处捕获缩略图,每次成功捕获都会覆盖最后一次。
这是我使用的更新后的批处理文件:
REM mp4 (H.264 / AAC)
"c:\program files\ffmpeg\bin\ffmpeg.exe" -y -i %1 -vcodec libx264 -pix_fmt yuv420p -vprofile high -preset fast -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=trunc(oh*a/2)*2:480 -threads 0 -acodec libvo_aacenc -b:a 128k %1.mp4
REM webm (VP8 / Vorbis)
"c:\program files\ffmpeg\bin\ffmpeg.exe" -y -i %1 -vcodec libvpx -quality good -cpu-used 5 -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=trunc(oh*a/2)*2:480 -threads 0 -acodec libvorbis -f webm %1.webm
REM jpeg (screenshot at 10 seconds, but just in case of a short video - take a screenshot earlier and overwrite)
"c:\program files\ffmpeg\bin\ffmpeg.exe" -y -i %1 -ss 1 -vframes 1 -r 1 -vf scale=trunc(oh*a/2)*2:480 -f image2 %1.jpg
"c:\program files\ffmpeg\bin\ffmpeg.exe" -y -i %1 -ss 2 -vframes 1 -r 1 -vf scale=trunc(oh*a/2)*2:480 -f image2 %1.jpg
"c:\program files\ffmpeg\bin\ffmpeg.exe" -y -i %1 -ss 3 -vframes 1 -r 1 -vf scale=trunc(oh*a/2)*2:480 -f image2 %1.jpg
"c:\program files\ffmpeg\bin\ffmpeg.exe" -y -i %1 -ss 5 -vframes 1 -r 1 -vf scale=trunc(oh*a/2)*2:480 -f image2 %1.jpg
"c:\program files\ffmpeg\bin\ffmpeg.exe" -y -i %1 -ss 10 -vframes 1 -r 1 -vf scale=trunc(oh*a/2)*2:480 -f image2 %1.jpg
我还创建了一个单独的批处理文件,它将遍历给定目录中的所有 wmv,并对每个文件运行编码器批处理:
for /r %1 %%i in (*.wmv) do "c:\program files\ffmpeg\CreateWebVideos.bat" %
Faron Coder 说:2014 年 9 月 3 日下午 6:52 (*nix)
你好——
对于那些使用基于 unix 的 ffmpeg 的人 - 这是与作者在 unix 名称中的代码(上图)相对应的代码。
ffmpeg -y -i $fileid -vcodec libx264 -pix_fmt yuv420p -vprofile high -preset fast -b:v 500k -maxrate 500k -bufsize 1000k -vf “scale=trunc(oh*a/2)*2:480″ -threads 0 -acodec libvo_aacenc -b:a 128k “$file.mp4″ < /dev/null
ffmpeg -y -i $fileid -vcodec libvpx -quality good -cpu-used 5 -b:v 500k -maxrate 500k -bufsize 1000k -vf "scale=trunc(oh*a/2)*2:480" -threads 0 -acodec libvorbis -f webm "$file.webm" < /dev/null
ffmpeg -y -i $fileid -ss 1 -vframes 1 -r 1 -vf "scale=trunc(oh*a/2)*2:480" -f image2 "$file.jpg" < /dev/null
ffmpeg -y -i $fileid -ss 2 -vframes 1 -r 1 -vf "scale=trunc(oh*a/2)*2:480" -f image2 "$file.jpg" < /dev/null
ffmpeg -y -i $fileid -ss 3 -vframes 1 -r 1 -vf "scale=trunc(oh*a/2)*2:480" -f image2 "$file.jpg" < /dev/null
ffmpeg -y -i $fileid -ss 5 -vframes 1 -r 1 -vf "scale=trunc(oh*a/2)*2:480" -f image2 "$file.jpg" < /dev/null
ffmpeg -y -i $fileid -ss 10 -vframes 1 -r 1 -vf "scale=trunc(oh*a/2)*2:480" -f image2 "$file.jpg" < /dev/null
希望对您有所帮助。