fftools/ffmpeg_filter: pass framerate through InputFilterOptions

Rather than read it directly from InputStream.

This is a step towards avoiding the assumption that filtergraph inputs
are always fed by demuxers.
This commit is contained in:
Anton Khirnov 2024-02-13 12:18:27 +01:00
parent fef3052df3
commit 826cfd9997
3 changed files with 18 additions and 11 deletions

View File

@ -253,6 +253,7 @@ typedef struct OptionsContext {
enum IFilterFlags {
IFILTER_FLAG_AUTOROTATE = (1 << 0),
IFILTER_FLAG_REINIT = (1 << 1),
IFILTER_FLAG_CFR = (1 << 2),
};
typedef struct InputFilterOptions {
@ -261,6 +262,13 @@ typedef struct InputFilterOptions {
uint8_t *name;
/* When IFILTER_FLAG_CFR is set, the stream is guaranteed to be CFR with
* this framerate.
*
* Otherwise, this is an estimate that should not be relied upon to be
* accurate */
AVRational framerate;
int sub2video_width;
int sub2video_height;
@ -365,8 +373,6 @@ typedef struct InputStream {
Decoder *decoder;
const AVCodec *dec;
AVRational framerate_guessed;
/* framerate forced with -r */
AVRational framerate;
#if FFMPEG_OPT_TOP

View File

@ -992,7 +992,13 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
if (ret < 0)
return ret;
if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
if (ist->framerate.num > 0 && ist->framerate.den > 0) {
opts->framerate = ist->framerate;
opts->flags |= IFILTER_FLAG_CFR;
} else
opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
} else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
/* Compute the size of the canvas for the subtitles stream.
If the subtitles codecpar has set a size, use it. Otherwise use the
maximum dimensions of the video streams in the same file. */
@ -1359,8 +1365,6 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
#endif
ist->framerate_guessed = av_guess_frame_rate(ic, st, NULL);
break;
case AVMEDIA_TYPE_AUDIO: {
int guess_layout_max = INT_MAX;

View File

@ -1486,7 +1486,7 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
const AVPixFmtDescriptor *desc;
InputStream *ist = ifp->ist;
AVRational fr = ist->framerate;
AVRational fr = ifp->opts.framerate;
AVRational sar;
AVBPrint args;
char name[255];
@ -1495,14 +1495,11 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
if (!par)
return AVERROR(ENOMEM);
if (!fr.num)
fr = ist->framerate_guessed;
if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE)
sub2video_prepare(ifp);
ifp->time_base = ist->framerate.num ? av_inv_q(ist->framerate) :
ist->st->time_base;
ifp->time_base = (ifp->opts.flags & IFILTER_FLAG_CFR) ?
av_inv_q(ifp->opts.framerate) : ist->st->time_base;
sar = ifp->sample_aspect_ratio;
if(!sar.den)