ffmpeg压缩H264在HTML5播放器下,必须先下载整个文件的解决

3410阅读 0评论2016-11-17 lsstarboy
分类:网络与安全

现象:
     用ffmpeg压缩的h264文件,可以在线看,FireFox可以顺利解码,但是必须下载完整个文件才能播放。

原因:
      1、http://renaun.com/blog/code/qtindexswapper/,QTindex放在了文件后端,导致播放器必须先读完整个文件才能得到媒体信息。这可以用专用工具解决。
     2、将 MOOV ATOM 放置于文件尾部,
-movflags +faststart
 
完整的例子:

  1. $cmdstr = 'ffmpeg -y -i ' . $file . ' -hide_banner -c:v libx264 -acodec aac -strict -2 -pix_fmt yuv420p -movflags faststart ' . $file_info['filename'] . '_1.mp4'

解释:
1、-y,覆盖不提示;
2、hide_banner:不再提示ffmpeg的编译信息;
3、-c:v libx264,用libx264格式;可改用-v h264
4、-strict -2 ,主要aac使用,aac格式是试验的格式
5、yuv420p,强制使用420p编码,文件更小
6、movflags faststart,把faststart信息移到文件头。



参考:


10 accepted

.h264 is just a raw H.264 bytestream. That's just video content, which can be played back by sophisticated players, but usually you want to put everything into a container format, such as MPEG-4 Part 14 ("MP4").

So, run:

ffmpeg -i file.avi -c:v libx264 -pix_fmt yuv420p file.mp4 

For HTML5 progressive download you may want to move the moov atom of the MP4 container to the beginning of the file, which allows instant playback:

ffmpeg -i file.avi -c:v libx264 -pix_fmt yuv420p -movflags faststart file.mp4 

You may be interested in:


上一篇:PHP的readfile下载大文件时卡住
下一篇:zfs文件系统下使用NFS Server