fftools/ffmpeg_enc: only use fallback framerate when encoding CFR

When no output video framerate is specified by the user with -r or can
be inferred from the filtergraph, encoder setup will arbitrarily decide
that the framerate is 25fps. However, making up any framerate value for
VFR encoding is at best unnecessary.

Changes the results of the sub2video tests, where the input timebase is
now used instead of 1/25.
This commit is contained in:
Anton Khirnov
2023-07-21 16:13:58 +02:00
parent 8b6b2518fa
commit 411ada649f
3 changed files with 112 additions and 107 deletions

View File

@@ -231,20 +231,24 @@ static int enc_choose_timebase(OutputStream *ost, AVFrame *frame)
fr = ost->frame_rate;
if (!fr.num)
fr = fd->frame_rate_filter;
if (!fr.num && !ost->max_frame_rate.num) {
fr = (AVRational){25, 1};
av_log(ost, AV_LOG_WARNING,
"No information "
"about the input framerate is available. Falling "
"back to a default value of 25fps. Use the -r option "
"if you want a different framerate.\n");
if (ost->is_cfr) {
if (!fr.num && !ost->max_frame_rate.num) {
fr = (AVRational){25, 1};
av_log(ost, AV_LOG_WARNING,
"No information "
"about the input framerate is available. Falling "
"back to a default value of 25fps. Use the -r option "
"if you want a different framerate.\n");
}
if (ost->max_frame_rate.num &&
(av_q2d(fr) > av_q2d(ost->max_frame_rate) ||
!fr.den))
fr = ost->max_frame_rate;
}
if (ost->max_frame_rate.num &&
(av_q2d(fr) > av_q2d(ost->max_frame_rate) ||
!fr.den))
fr = ost->max_frame_rate;
if (fr.num > 0) {
if (enc->codec->supported_framerates && !ost->force_fps) {
int idx = av_find_nearest_q_idx(fr, enc->codec->supported_framerates);
fr = enc->codec->supported_framerates[idx];
@@ -254,6 +258,7 @@ static int enc_choose_timebase(OutputStream *ost, AVFrame *frame)
av_reduce(&fr.num, &fr.den,
fr.num, fr.den, 65535);
}
}
if (av_q2d(fr) > 1e3 && ost->vsync_method != VSYNC_PASSTHROUGH &&
(ost->vsync_method == VSYNC_CFR || ost->vsync_method == VSYNC_VSCFR ||