我们正在使用FFmpeg
库git-ee94362 libavformat v55.2.100
。我们正在尝试HLS
基于muxing.c
标准代码编写一个简单的代码示例。让我们成为两个输入流,视频和音频(它们可以是合成的,没关系)。mux
我们的目的是M3U8
使用HLS
. 假设每个 TS 段文件的持续时间为 3 秒,并且M3U8
输出文件中所需的最大条目数为 100。
从FFmpeg
应用程序源代码中可以看出,Apple HTTP Live Streaming 分段器是在hlsenc.c
文件中实现的。并且相关的选项还有: "hls_list_size"
,"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
(例如)?
谢谢,
安德烈·莫切诺夫。