@@ -2045,9 +2045,12 @@ static int init_output_stream_encode(OutputStream *ost)
ost->filter->filter->inputs[0]->sample_aspect_ratio;
enc_ctx->pix_fmt = ost->filter->filter->inputs[0]->format;
- enc_ctx->framerate = ost->frame_rate;
+ enc_ctx->framerate = ost->avg_frame_rate;
- ost->st->avg_frame_rate = ost->frame_rate;
+ if (ost->frame_rate.num)
+ ost->st->avg_frame_rate = ost->frame_rate;
+ else
+ ost->st->avg_frame_rate = ost->avg_frame_rate;
if (dec_ctx &&
(enc_ctx->width != dec_ctx->width ||
@@ -378,6 +378,8 @@ typedef struct OutputStream {
/* video only */
AVRational frame_rate;
+ /* rate-control hint */
+ AVRational avg_frame_rate;
int force_fps;
int top_field_first;
@@ -1853,6 +1853,7 @@ loop_end:
* in such a case, set ost->frame_rate
*/
if (ost->encoding_needed && ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
+ InputStream *ist = ost->source_index >= 0 ? input_streams[ost->source_index] : NULL;
int format_cfr = !(oc->oformat->flags & (AVFMT_NOTIMESTAMPS | AVFMT_VARIABLE_FPS));
int need_cfr = !!ost->frame_rate.num;
@@ -1861,8 +1862,6 @@ loop_end:
need_cfr = 1;
if (need_cfr && !ost->frame_rate.num) {
- InputStream *ist = ost->source_index >= 0 ? input_streams[ost->source_index] : NULL;
-
if (ist && ist->framerate.num)
ost->frame_rate = ist->framerate;
else if (ist && ist->st->avg_frame_rate.num)
@@ -1882,6 +1881,13 @@ loop_end:
int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates);
ost->frame_rate = ost->enc->supported_framerates[idx];
}
+
+ if (ost->frame_rate.num)
+ ost->avg_frame_rate = ost->frame_rate;
+ else if (ist && ist->framerate.num)
+ ost->avg_frame_rate = ist->framerate;
+ else if (ist && ist->st->avg_frame_rate.num)
+ ost->avg_frame_rate = ist->st->avg_frame_rate;
}
/* set the filter output constraints */