我们正在使用FFmpeg
个库git-ee94362 libavformat v55.2.100
。
我们正在尝试编写一个基于HLS
标准版的简单muxing.c
代码示例。
设两个输入流,视频和音频(它们可以是合成的,无所谓)。
我们的目的是mux
使用M3U8
将HLS
个播放列表添加到M3U8
播放列表中。
假设,每个TS段文件的持续时间为3秒,FFmpeg
输出文件中所需的最大条目数为100.
从hlsenc.c
应用程序源,可以看到在"hls_list_size"
文件中实现的Apple HTTP Live Streaming分段器。
还有相关选项:"hls_time"
,// Here is a part of main() program
int64_t i1 = 0;
void *target_obj;
AVFormatContext *ofmt_ctx = NULL;
AVOutputFormat *ofmt = NULL;
avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, "Example_Out.m3u8");
ofmt = ofmt_ctx->oformat;
// The relevant options ("hls_list_size", "hls_time") are located under ofmt->priv_class->option.
// But AVClass *priv_class is not the first member of the AVOutputFormat.
// So, due to the documentation, av_opt_find...(), av_opt_get...() and av_opt_set...()
// cannot be used for options within AVOutputFormat.
// In practice, any of the following three lines causes exception.
const AVOption *o = av_opt_find2(ofmt, "hls_list_size", NULL, 0, AV_OPT_SEARCH_CHILDREN, &target_obj);
av_opt_get_int(ofmt, "hls_list_size", AV_OPT_SEARCH_CHILDREN, &i1);
av_opt_set_int(ofmt, "hls_list_size", 10, AV_OPT_SEARCH_CHILDREN);
等。
问题是我们没有成功地以传统方式设置/获取/查找这些选项,如下面的代码所示:
AVOutputFormat
我们的问题:如果有办法克服这个问题,即为AVCodecContext
设置/获取/查找选项,例如{{1}}(例如)?
谢谢,
Andrey Mochenov。
答案 0 :(得分:1)
尝试传入AVFormatContext(ofmt-> priv_data)的priv_data字段而不是结构本身。它在代码中的这一点将为NULL,但在调用avformat_write_header之后会被填充。
av_opt_set_int(ofmt-> priv_data,“hls_list_size”,10,AV_OPT_SEARCH_CHILDREN)应该在那时工作。
如果在调用avformat_write_header()之前需要设置选项,就像您的Live Streaming选项一样,则应将它们作为AVDictionary **选项参数传递给该函数。