如何以编程方式生成碎片化的 mp4 文件 [英] How to generate fragmented mp4 files programmatically

查看:35
本文介绍了如何以编程方式生成碎片化的 mp4 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个媒体 .h264 实时流媒体服务器,想将 .h264 帧多路复用为碎片化的 mp4 文件.我想知道是否有任何图书馆可以支持这一点?

I have a media .h264 live streaming server, and want to mux .h264 frames to fragmented mp4 files. I am wondering does any library could support this?

据我所知,ffmpeg.exe 和 Bento4 可以支持这一点,但我想在我的代码中使用一个库来做到这一点,而不是执行另一个进程.

As far as I know, ffmpeg.exe and Bento4 could support this, but I want to use a library to do that in my code, not executing another process.

为了说明我的观点,我想生成碎片化的mp4文件,这可以通过执行如下所示的ffmpeg.exe来实现,

To specify my point, I want to generate fragmented mp4 files, which could be achieved by executing ffmpeg.exe like below,

ffmpeg -i xx.h264 
        -vcodec copy -an -f mp4 -reset_timestamps 0 
        -movflags empty_moov+default_base_moof+frag_keyframe -loglevel quiet 
        xxx.mp4"

我想在我的代码中多路复用 mp4 文件,而不是创建另一个进程来执行此操作.

I want to mux mp4 files in my code, not create another process to do it.

谢谢.

推荐答案

更详细:

AVDictionary* opts = NULL;
av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0);

然后:

//init muxer, write output file header
avformat_write_header(formatContext, &opts);

其中 formatContext 是使用 avformat_alloc_output_context2avio_open 函数打开输出文件时获得的 AVFormatContext 的指针.

where formatContext is pointer of AVFormatContext obtained when output file is opened using: avformat_alloc_output_context2 and avio_open functions.

这篇关于如何以编程方式生成碎片化的 mp4 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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