热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何以编程方式生成碎片mp4文件-Howtogeneratefragmentedmp4filesprogrammatically

Ihaveamedia.h264livestreamingserver,andwanttomux.h264framestofragmentedmp4files.I

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?

我有一个媒体.h264直播服务器,并希望mux .h264帧到碎片mp4文件。我想知道任何图书馆都可以支持吗?

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.

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

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

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

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

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

我想在我的代码中复用mp4文件,而不是创建另一个进程来执行它。

Thanks.

2 个解决方案

#1


2  

libavformat and libavcodec are the underlying libraries of ffmpeg. You probably can accomplish everything you need with libavformat. The documentation on these libraries is sparse, but as I recall, most understanding can be gleamed from the header files.

libavformat和libavcodec是ffmpeg的底层库。您可能可以使用libavformat完成所需的一切。关于这些库的文档很少,但我记得,大多数理解都可以从头文件中找到。

#2


4  

More detailed:

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

and then later:

然后:

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

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

其中formatContext是使用以下命令打开输出文件时获得的AVFormatContext指针:avformat_alloc_output_context2和avio_open函数。


推荐阅读
author-avatar
爱她一生2502876055
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有