From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 12/31] fftools/ffmpeg_filter: pass vsync method through OutputFilterOptions Date: Fri, 5 Apr 2024 18:11:53 +0200 Message-ID: <20240405161212.26167-12-anton@khirnov.net> (raw) In-Reply-To: <20240405161212.26167-1-anton@khirnov.net> Do not read it from OutputStream directly. Will allow decoupling filtering from encoding in future commits. --- fftools/ffmpeg.h | 3 ++- fftools/ffmpeg_filter.c | 9 +++++--- fftools/ffmpeg_mux.c | 2 +- fftools/ffmpeg_mux.h | 3 +++ fftools/ffmpeg_mux_init.c | 45 ++++++++++++++++++++++----------------- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 598ca2fa96..fa8f7d8324 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -287,6 +287,8 @@ typedef struct OutputFilterOptions { int width; int height; + enum VideoSyncMethod vsync_method; + int sample_rate; AVChannelLayout ch_layout; } OutputFilterOptions; @@ -549,7 +551,6 @@ typedef struct OutputStream { /* video only */ AVRational frame_rate; AVRational max_frame_rate; - enum VideoSyncMethod vsync_method; int is_cfr; int force_fps; #if FFMPEG_OPT_TOP diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 3c25d2ed65..d906b72576 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -175,6 +175,8 @@ typedef struct FPSConvContext { int last_dropped; int dropped_keyframe; + enum VideoSyncMethod vsync_method; + AVRational framerate; AVRational framerate_max; const AVRational *framerate_supported; @@ -799,6 +801,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, if (!ofp->fps.last_frame) return AVERROR(ENOMEM); + ofp->fps.vsync_method = opts->vsync_method; ofp->fps.framerate = ost->frame_rate; ofp->fps.framerate_max = ost->max_frame_rate; ofp->fps.framerate_supported = ost->force_fps && opts->enc ? @@ -2072,9 +2075,9 @@ static void video_sync_process(OutputFilterPriv *ofp, AVFrame *frame, if (delta0 < 0 && delta > 0 && - ost->vsync_method != VSYNC_PASSTHROUGH + fps->vsync_method != VSYNC_PASSTHROUGH #if FFMPEG_OPT_VSYNC_DROP - && ost->vsync_method != VSYNC_DROP + && fps->vsync_method != VSYNC_DROP #endif ) { if (delta0 < -0.6) { @@ -2086,7 +2089,7 @@ static void video_sync_process(OutputFilterPriv *ofp, AVFrame *frame, delta0 = 0; } - switch (ost->vsync_method) { + switch (fps->vsync_method) { case VSYNC_VSCFR: if (fps->frame_number == 0 && delta0 >= 0.5) { av_log(ost, AV_LOG_DEBUG, "Not duplicating %d initial frames\n", (int)lrintf(delta0)); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index e8e5c677b8..253c2e58d4 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -140,7 +140,7 @@ static int mux_fixup_ts(Muxer *mux, MuxStream *ms, AVPacket *pkt) OutputStream *ost = &ms->ost; #if FFMPEG_OPT_VSYNC_DROP - if (ost->type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == VSYNC_DROP) + if (ost->type == AVMEDIA_TYPE_VIDEO && ms->ts_drop) pkt->pts = pkt->dts = AV_NOPTS_VALUE; #endif diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h index 16af6d38ba..f8b6f7a790 100644 --- a/fftools/ffmpeg_mux.h +++ b/fftools/ffmpeg_mux.h @@ -75,6 +75,9 @@ typedef struct MuxStream { int copy_initial_nonkeyframes; int copy_prior_start; int streamcopy_started; +#if FFMPEG_OPT_VSYNC_DROP + int ts_drop; +#endif } MuxStream; typedef struct Muxer { diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index b031cc59d2..6ffa4b7491 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -580,8 +580,10 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name) } static int new_stream_video(Muxer *mux, const OptionsContext *o, - OutputStream *ost, int *keep_pix_fmt) + OutputStream *ost, int *keep_pix_fmt, + enum VideoSyncMethod *vsync_method) { + MuxStream *ms = ms_from_ost(ost); AVFormatContext *oc = mux->fc; AVStream *st; char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = NULL; @@ -773,49 +775,52 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, #endif #if FFMPEG_OPT_VSYNC - ost->vsync_method = video_sync_method; + *vsync_method = video_sync_method; #else - ost->vsync_method = VSYNC_AUTO; + *vsync_method = VSYNC_AUTO; #endif MATCH_PER_STREAM_OPT(fps_mode, str, fps_mode, oc, st); if (fps_mode) { - ret = parse_and_set_vsync(fps_mode, &ost->vsync_method, ost->file->index, ost->index, 0); + ret = parse_and_set_vsync(fps_mode, vsync_method, ost->file->index, ost->index, 0); if (ret < 0) return ret; } if ((ost->frame_rate.num || ost->max_frame_rate.num) && - !(ost->vsync_method == VSYNC_AUTO || - ost->vsync_method == VSYNC_CFR || ost->vsync_method == VSYNC_VSCFR)) { + !(*vsync_method == VSYNC_AUTO || + *vsync_method == VSYNC_CFR || *vsync_method == VSYNC_VSCFR)) { av_log(ost, AV_LOG_FATAL, "One of -r/-fpsmax was specified " "together a non-CFR -vsync/-fps_mode. This is contradictory.\n"); return AVERROR(EINVAL); } - if (ost->vsync_method == VSYNC_AUTO) { + if (*vsync_method == VSYNC_AUTO) { if (ost->frame_rate.num || ost->max_frame_rate.num) { - ost->vsync_method = VSYNC_CFR; + *vsync_method = VSYNC_CFR; } else if (!strcmp(oc->oformat->name, "avi")) { - ost->vsync_method = VSYNC_VFR; + *vsync_method = VSYNC_VFR; } else { - ost->vsync_method = (oc->oformat->flags & AVFMT_VARIABLE_FPS) ? - ((oc->oformat->flags & AVFMT_NOTIMESTAMPS) ? - VSYNC_PASSTHROUGH : VSYNC_VFR) : - VSYNC_CFR; + *vsync_method = (oc->oformat->flags & AVFMT_VARIABLE_FPS) ? + ((oc->oformat->flags & AVFMT_NOTIMESTAMPS) ? + VSYNC_PASSTHROUGH : VSYNC_VFR) : VSYNC_CFR; } - if (ost->ist && ost->vsync_method == VSYNC_CFR) { + if (ost->ist && *vsync_method == VSYNC_CFR) { const InputFile *ifile = ost->ist->file; if (ifile->nb_streams == 1 && ifile->input_ts_offset == 0) - ost->vsync_method = VSYNC_VSCFR; + *vsync_method = VSYNC_VSCFR; } - if (ost->vsync_method == VSYNC_CFR && copy_ts) { - ost->vsync_method = VSYNC_VSCFR; + if (*vsync_method == VSYNC_CFR && copy_ts) { + *vsync_method = VSYNC_VSCFR; } } - ost->is_cfr = (ost->vsync_method == VSYNC_CFR || ost->vsync_method == VSYNC_VSCFR); + ost->is_cfr = (*vsync_method == VSYNC_CFR || *vsync_method == VSYNC_VSCFR); +#if FFMPEG_OPT_VSYNC_DROP + if (*vsync_method == VSYNC_DROP) + ms->ts_drop = 1; +#endif } return 0; @@ -1043,6 +1048,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, AVStream *st; int ret = 0, keep_pix_fmt = 0; AVRational enc_tb = { 0, 0 }; + enum VideoSyncMethod vsync_method = VSYNC_AUTO; const char *bsfs = NULL, *time_base = NULL; char *filters = NULL, *next, *codec_tag = NULL; double qscale = -1; @@ -1361,7 +1367,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, ms->copy_initial_nonkeyframes, oc, st); switch (type) { - case AVMEDIA_TYPE_VIDEO: ret = new_stream_video (mux, o, ost, &keep_pix_fmt); break; + case AVMEDIA_TYPE_VIDEO: ret = new_stream_video (mux, o, ost, &keep_pix_fmt, &vsync_method); break; case AVMEDIA_TYPE_AUDIO: ret = new_stream_audio (mux, o, ost); break; case AVMEDIA_TYPE_SUBTITLE: ret = new_stream_subtitle (mux, o, ost); break; } @@ -1382,6 +1388,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, ost->enc_ctx->pix_fmt : ost->enc_ctx->sample_fmt, .width = ost->enc_ctx->width, .height = ost->enc_ctx->height, + .vsync_method = vsync_method, .sample_rate = ost->enc_ctx->sample_rate, .ch_layout = ost->enc_ctx->ch_layout, .output_tb = enc_tb, -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-04-05 16:16 UTC|newest] Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-05 16:11 [FFmpeg-devel] [PATCH 01/31] lavfi/vf_scale: fix AVOption flags for "size"/"s" Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 02/31] lavfi/avfilter: add an "auto" constant to the threads option Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 03/31] fftools/ffmpeg_filter: do not pass OutputStream to set_channel_layout() Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 04/31] fftools/ffmpeg_filter: stop accessing AVCodecContext.codec Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 05/31] fftools/ffmpeg_filter: check that filter type matches output stream type Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 06/31] fftools/ffmpeg_filter: pass ts offset through OutputFilterOptions Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 07/31] fftools/ffmpeg_filter: pass keep_pix_fmt " Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 08/31] fftools/ffmpeg: warn about ignored -enc_time_base for subtitles earlier Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 09/31] fftools/ffmpeg_filter: pass enc_timebase through OutputFilterOptions Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 10/31] fftools/ffmpeg_filter: move the MJPEG format selection hack to muxer setup Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 11/31] fftools/ffmpeg_filter: stop accessing encoder AVCodecContext Anton Khirnov 2024-04-05 16:50 ` Dennis Mungai 2024-04-05 16:54 ` Gyan Doshi 2024-04-05 17:07 ` Dennis Mungai 2024-04-05 17:09 ` Anton Khirnov 2024-04-05 16:11 ` Anton Khirnov [this message] 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 13/31] fftools/ffmpeg: drop OutputStream.is_cfr Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 14/31] fftools/ffmpeg_filter: accept a caller-provided output name Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 15/31] fftools/ffmpeg_filter: drop a redundant check Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 16/31] fftools/ffmpeg_filter: simplify retrieving filter type Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 17/31] fftools/ffmpeg_filter: add an AVClass to OutputFilter Anton Khirnov 2024-04-05 16:11 ` [FFmpeg-devel] [PATCH 18/31] fftools/ffmpeg_filter: drop an unnecessary use of OutputStream Anton Khirnov 2024-04-05 16:12 ` [FFmpeg-devel] [PATCH 19/31] fftools/ffmpeg_filter: pass sws/swr opts through OutputFilterOptions Anton Khirnov 2024-04-05 16:12 ` [FFmpeg-devel] [PATCH 20/31] fftools/ffmpeg_filter: pass autoscale " Anton Khirnov 2024-04-05 16:12 ` [FFmpeg-devel] [PATCH 21/31] fftools/ffmpeg_filter: pass trim parameters " Anton Khirnov 2024-04-05 16:12 ` [FFmpeg-devel] [PATCH 22/31] fftools/ffmpeg_filter: move most of -apad logic to the muxer Anton Khirnov 2024-04-05 16:12 ` [FFmpeg-devel] [PATCH 23/31] fftools/ffmpeg_mux: drop OutputFile.shortest Anton Khirnov 2024-04-05 16:12 ` [FFmpeg-devel] [PATCH 24/31] fftools/ffmpeg_mux: drop OutputFile.format Anton Khirnov 2024-04-05 16:12 ` [FFmpeg-devel] [PATCH 25/31] fftools/ffmpeg_filter: accept encoder thread count through OutputFilterOptions Anton Khirnov 2024-04-05 16:12 ` [FFmpeg-devel] [PATCH 26/31] fftools/ffmpeg_filter: drop OutputFilter.ost Anton Khirnov 2024-04-05 16:12 ` [FFmpeg-devel] [PATCH 27/31] fftools/ffmpeg_filter: only store complex filtergraphs in global array Anton Khirnov 2024-04-05 16:12 ` [FFmpeg-devel] [PATCH 28/31] fftools/ffmpeg_filter: change processing order in fg_finalise_bindings() Anton Khirnov 2024-04-05 16:12 ` [FFmpeg-devel] [PATCH 29/31] fftools/ffmpeg_sched: allow filtergraphs to send to filtergraphs Anton Khirnov 2024-04-05 16:12 ` [FFmpeg-devel] [PATCH 30/31] fftools/ffmpeg_filter: implement filtergraph chaining Anton Khirnov 2024-04-05 16:12 ` [FFmpeg-devel] [PATCH 31/31] doc/ffmpeg: document that there can be multiple complex filtergraphs Anton Khirnov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240405161212.26167-12-anton@khirnov.net \ --to=anton@khirnov.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git