在C ++中使用ffmpeg编码视频时如何设置moov原子位置

Zhi*_* Li 5 c++ mp4 ffmpeg h.264

我正在使用c ++中的ffmpeg将一些h264视频编码到mp4容器中。但是结果视频将moov原子(或元数据?)放在视频文件的末尾,这对于Internet流传输是不利的。那么如何将moov原子的位置设置在前面呢?

Cal*_*602 5

MOVMuxContext 是一个内部头文件,不应直接访问。它的实现不是 API 的一部分,它可以更改。官方方法是通过 AVDictionary 设置选项:

AVDictionary* options = nullptr;
av_dict_set( &options, "movflags", "faststart", 0 );
avio_open2(..., &options);
Run Code Online (Sandbox Code Playgroud)


pra*_*esh 2

您需要使用 ffmpeg 的 faststart 标志将 moov 原子放置在 MP4 文件的开头,是该标志的解释。以编程方式,您需要在输出上下文中设置标志,这是示例代码及其对我有用,

AVFormatContext *outFormatCtx;

// Write MOOV atom at the begining of the MP4 file
MOVMuxContext *mov = NULL;

mov = (MOVMuxContext *)outFormatCtx->priv_data;
mov->flags |= FF_MOV_FLAG_FASTSTART;
Run Code Online (Sandbox Code Playgroud)