<div dir="ltr"><p>Hi, </p>
<p>We are using FFmpeg libraries git-ee94362 libavformat v55.2.100.<br>Our purpose is to mux two streams (video and audio) into M3U8 playlist using HLS.<br>In addition, we want the duration of every TS segment file be exactly 3.0 sec (frame rate is 25 fps).<br>
To reach it, we are trying to set several options and properties, namely: <br>- segment_time  <br>- keyint_min<br>- scenechange_threshold<br>- gop_size<br>- force_key_frames.</p>
<p>And our code looks as below:</p>
<p>AVCodecContext *codec_ctx = NULL;<br>AVFormatContext *ofmt_ctx = NULL;<br>int ret = 0, gopSize = (int)(3.0 * 25);   // 3 sec * 25 fps</p>
<p>// ofmt_ctx and codec_ctx initialization and filling are OK, but: </p>
<p>codec_ctx->time_base.num = 1;<br>codec_ctx->time_base.den = 25 // fps</p>
<p>// It seems, that the following three lines have no effect without explisit setting of the "hls_time" property<br>codec_ctx->keyint_min = gopSize;       // in FFMpeg application, the corresponding option is "-keyint_min 3"<br>
codec_ctx->scenechange_threshold = 0;  // in FFMpeg application, the corresponding option is "-sc_threshold 0"<br>codec_ctx->gop_size = gopSize;         // in FFMpeg application, the corresponding option is "-g 3"</p>

<p>ret = av_opt_set_double(ofmt_ctx, "hls_time", 3.0, AV_OPT_SEARCH_CHILDREN);</p>
<p>// Any of the following lines causes "Option not found" error.<br>ret = av_opt_set(codec_ctx->priv_data, "profile", "main", AV_OPT_SEARCH_CHILDREN);<br>ret = av_opt_set(codec_ctx->priv_data, "preset", "ultrafast", AV_OPT_SEARCH_CHILDREN);<br>
ret = av_opt_get(ofmt_ctx, "segment_time",  AV_OPT_SEARCH_CHILDREN, &str);<br>ret = av_opt_set((ofmt_ctx, "segment_time", "3.0", AV_OPT_SEARCH_CHILDREN);</p>
<p>Anyway, the TS files durations are different, (~2-3 sec), and not EXACTLY 3.0 sec. <br>Our question: What is the best way to solve the problem?</p>
<p>Andrey Mochenov.</p></div>