如何使用ffmpeg输出片段mp4? [英] How to output fragmented mp4 with ffmpeg?

查看:1222
本文介绍了如何使用ffmpeg输出片段mp4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ffmpeg -i infile.avi out.mp4 输出无分段MP4。

如何获取碎片mp4?

更新
分散的mp4文件在内部分为几个背靠背的大块或MPEG-4电影片段。每个块都有自己的moof原子 - 所以有几个moof原子交错在文件,而不是一个单一的moov在结束,如在未分片的mp4的情况。这使得在缓慢涉及的缓慢网络中更容易流式传输。

Update A fragmented mp4 file is internally divided into several back-to-back chunks or MPEG-4 movie fragments. Each chunk has its own moof atom - so there are several moof atoms interleaved in the file instead of a single moov at the end as in the case of an unfragmented mp4. This makes it easier to stream over slow networks where buffering is involved

有一些工具,如 mp4box ,将普通mp4转换成片段化的mp4。不幸的是,我们不能使用这样的东西

There are several tools like mp4box that convert a normal mp4 to a fragmented one. Unfortunately we cannot use something like this

ffmpeg <options to output mp4> | mp4box

由于ffmpeg在生成mp4容器时不会产生可寻求的输出。

since ffmpeg does not produce seekable output while producing mp4 containers.

推荐答案

这应该是诀窍:

ffmpeg -re -i infile.ext -g 52 \
-strict experimental -acodec aac -ab 64k -vcodec libx264 -vb 448k \
-f mp4 -movflags frag_keyframe+empty_moov \
output.mp4




  • frag_keyframe 导致分片输出,

  • empty_moov 将导致输出为100%碎片;没有这个,第一个片段将被复制为短片(使用 moov ),其余的媒体片段,

  • -re 在实时流式传输(媒体比特率输出)时非常有用,如果您正在创建文件,请不要使用

  • -g 52 强制(至少)每第52帧成为关键帧

    • frag_keyframe causes fragmented output,
    • empty_moov will cause output to be 100% fragmented; without this the first fragment will be muxed as a short movie (using moov) followed by the rest of the media in fragments,
    • -re is useful when live streaming (output on media bitrate), do not use it if you are creating a file,
    • -g 52 forces (at least) every 52nd frame to be a keyframe
    • 要计算健康的关键帧间隔,请参阅我的文档中有关片段大小的段落流服务器 - 您还可以考虑使用WebM,它是H.264的免费替代品(并且在某些平台上比分散mp4更好的支持)。

      To calculate a healthy keyframe interval please see the paragraphs about fragment sizes in the docs of my streaming server. - You can also consider using WebM which is a free alternative to H.264 (and has better support on some platforms than fragmented mp4).

      重要提示: FFMpeg的muxer将在 tkhd mdhd 原子之间设置持续时间 0xffffffff为每个轨道。这会导致一些玩家出现问题(例如Quicktime不会播放这样的文件)。您应该找到一个工具并将其更改为零(0x00000000)。

      Important note: FFMpeg's muxer will set the Duration in both tkhd and mdhd atoms to 0xffffffff for each track. This causes problems in some players (for example Quicktime will not play such files). You should find a tool and change it to zero (0x00000000).

      这篇关于如何使用ffmpeg输出片段mp4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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