Skip to content

Commit fddf4bc

Browse files
Adding -force_cfr commandline flag
1 parent aeb8631 commit fddf4bc

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

fftools/ffmpeg.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ typedef struct OptionsContext {
176176
SpecifierOptList hwaccel_output_formats;
177177
SpecifierOptList autorotate;
178178
SpecifierOptList apply_cropping;
179+
SpecifierOptList force_cfr;
179180

180181
/* output options */
181182
StreamMap *stream_maps;
@@ -276,6 +277,9 @@ typedef struct InputFilterOptions {
276277
* accurate */
277278
AVRational framerate;
278279

280+
/* convert input stream to CFR at this framerate before inserting additional filters */
281+
AVRational force_cfr;
282+
279283
unsigned crop_top;
280284
unsigned crop_bottom;
281285
unsigned crop_left;
@@ -451,6 +455,9 @@ typedef struct InputStream {
451455

452456
/* framerate forced with -r */
453457
AVRational framerate;
458+
459+
/* convert input stream to CFR at this framerate before inserting additional filters */
460+
AVRational force_cfr;
454461
#if FFMPEG_OPT_TOP
455462
int top_field_first;
456463
#endif

fftools/ffmpeg_demux.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,10 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
10321032
(opts->crop_top | opts->crop_bottom | opts->crop_left | opts->crop_right))
10331033
opts->flags |= IFILTER_FLAG_CROP;
10341034
}
1035+
if (ist->force_cfr.num > 0 && ist->force_cfr.den > 0) {
1036+
opts->force_cfr = ist->force_cfr;
1037+
opts->flags |= IFILTER_FLAG_CFR;
1038+
}
10351039
} else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
10361040
/* Compute the size of the canvas for the subtitles stream.
10371041
If the subtitles codecpar has set a size, use it. Otherwise use the
@@ -1241,7 +1245,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
12411245
AVCodecParameters *par = st->codecpar;
12421246
DemuxStream *ds;
12431247
InputStream *ist;
1244-
const char *framerate = NULL, *hwaccel_device = NULL;
1248+
const char *framerate = NULL, *hwaccel_device = NULL, *forcecfr = NULL;
12451249
const char *hwaccel = NULL;
12461250
const char *apply_cropping = NULL;
12471251
const char *hwaccel_output_format = NULL;
@@ -1437,6 +1441,15 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
14371441
}
14381442
}
14391443

1444+
opt_match_per_stream_str(ist, &o->force_cfr, ic, st, &forcecfr);
1445+
if (forcecfr) {
1446+
ret = av_parse_video_rate(&ist->force_cfr, forcecfr);
1447+
if (ret < 0) {
1448+
av_log(ist, AV_LOG_ERROR, "Error parsing framerate %s.\n", forcecfr);
1449+
return ret;
1450+
}
1451+
}
1452+
14401453
#if FFMPEG_OPT_TOP
14411454
ist->top_field_first = -1;
14421455
opt_match_per_stream_int(ist, &o->top_field_first, ic, st, &ist->top_field_first);

fftools/ffmpeg_filter.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,15 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
17811781
ifp->displaymatrix_applied = 1;
17821782
}
17831783

1784+
if (ifp->opts.force_cfr.num > 0 && ifp->opts.force_cfr.den > 0) {
1785+
char force_cfr_buf[64];
1786+
snprintf(force_cfr_buf, sizeof(force_cfr_buf), "%d/%d",
1787+
ifp->opts.force_cfr.num, ifp->opts.force_cfr.den);
1788+
ret = insert_filter(&last_filter, &pad_idx, "fps", force_cfr_buf);
1789+
if (ret < 0)
1790+
return ret;
1791+
}
1792+
17841793
snprintf(name, sizeof(name), "trim_in_%s", ifp->opts.name);
17851794
ret = insert_trim(ifp->opts.trim_start_us, ifp->opts.trim_end_us,
17861795
&last_filter, &pad_idx, name);

fftools/ffmpeg_opt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,5 +2033,9 @@ const OptionDef options[] = {
20332033
"set video sync method globally; deprecated, use -fps_mode", "" },
20342034
#endif
20352035

2036+
{ "force_cfr", OPT_TYPE_STRING, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_INPUT,
2037+
{ .off = OFFSET(force_cfr) },
2038+
"set frame rate (Hz value, fraction or abbreviation)", "force_cfr" },
2039+
20362040
{ NULL, },
20372041
};

0 commit comments

Comments
 (0)