我们使用FFmpeg库git-ee94362 libavformat v55.2.100。 我们的目标是使用HLS将两个流(视频和音频)复合到M3U8播放列表中。 此外,我们希望每个TS段文件的持续时间恰好为3.0秒(帧速率为25 fps)。FFmpeg库:HLS的段持续时间完全不变
为了实现它,我们正在尝试设置几个选项和性能,即: - segment_time
- keyint_min - scenechange_threshold - gop_size - force_key_frames。
我们的代码看起来如下:
AVCodecContext *codec_ctx = NULL;
AVFormatContext *ofmt_ctx = NULL;
int ret = 0, gopSize = (int)(3.0 * 25); // 3 sec * 25 fps
// ofmt_ctx and codec_ctx initialization and filling are OK, but:
codec_ctx->time_base.num = 1;
codec_ctx->time_base.den = 25 // fps
// It seems, that the following three lines have no effect without explisit setting of the "hls_time" property
codec_ctx->keyint_min = gopSize; // in FFMpeg application, the corresponding option is "-keyint_min 3"
codec_ctx->scenechange_threshold = 0; // in FFMpeg application, the corresponding option is "-sc_threshold 0"
codec_ctx->gop_size = gopSize; // in FFMpeg application, the corresponding option is "-g 3"
ret = av_opt_set_double(ofmt_ctx, "hls_time", 3.0, AV_OPT_SEARCH_CHILDREN);
// Any of the following lines causes "Option not found" error.
ret = av_opt_set(codec_ctx->priv_data, "profile", "main", AV_OPT_SEARCH_CHILDREN);
ret = av_opt_set(codec_ctx->priv_data, "preset", "ultrafast", AV_OPT_SEARCH_CHILDREN);
ret = av_opt_get(ofmt_ctx, "segment_time", AV_OPT_SEARCH_CHILDREN, &str);
ret = av_opt_set((ofmt_ctx, "segment_time", "3.0", AV_OPT_SEARCH_CHILDREN);
无论如何,TS文件的持续时间是不同的,(约2-3秒),不完全是3.0秒。 我们的问题:解决问题的最佳方法是什么?
Andrey Mochenov。
你能找到解决这个问题的办法吗? –
你是否解决了这个问题? –