From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 06/18] fftools/ffmpeg_opt: merge init_complex_filters() and check_filter_outputs() Date: Wed, 6 Mar 2024 12:03:07 +0100 Message-ID: <20240306110319.17339-6-anton@khirnov.net> (raw) In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> The first of these binds inputs of complex filtergraphs to demuxer streams (with a misleading comment claiming it *creates* complex filtergraphs). The second ensures that all filtergraph outputs are connected to an encoder. Merge them into a single function, which simplifies the ffmpeg_filter API, is shorter, and will also be useful in following commits. Also, rename misleadingly-named init_input_filter() to fg_complex_bind_input(). --- fftools/ffmpeg.h | 3 +-- fftools/ffmpeg_filter.c | 38 ++++++++++++++++++-------------------- fftools/ffmpeg_opt.c | 32 +++++++++----------------------- 3 files changed, 28 insertions(+), 45 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 6b049e329b..d3e03543ac 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -671,12 +671,11 @@ int find_codec(void *logctx, const char *name, enum AVMediaType type, int encoder, const AVCodec **codec); int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global); -int check_filter_outputs(void); int filtergraph_is_simple(const FilterGraph *fg); int init_simple_filtergraph(InputStream *ist, OutputStream *ost, char *graph_desc, Scheduler *sch, unsigned sch_idx_enc); -int init_complex_filtergraph(FilterGraph *fg); +int fg_finalise_bindings(FilterGraph *fg); /** * Get our axiliary frame data attached to the frame, allocating it diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 37705297fb..7425e3d2ed 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1096,7 +1096,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, return 0; } -static int init_input_filter(FilterGraph *fg, InputFilter *ifilter) +static int fg_complex_bind_input(FilterGraph *fg, InputFilter *ifilter) { FilterGraphPriv *fgp = fgp_from_fg(fg); InputFilterPriv *ifp = ifp_from_ifilter(ifilter); @@ -1162,14 +1162,29 @@ static int init_input_filter(FilterGraph *fg, InputFilter *ifilter) return 0; } -int init_complex_filtergraph(FilterGraph *fg) +int fg_finalise_bindings(FilterGraph *fg) { // bind filtergraph inputs to input streams for (int i = 0; i < fg->nb_inputs; i++) { - int ret = init_input_filter(fg, fg->inputs[i]); + InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); + int ret; + + if (ifp->bound) + continue; + + ret = fg_complex_bind_input(fg, &ifp->ifilter); if (ret < 0) return ret; } + + for (int i = 0; i < fg->nb_outputs; i++) { + OutputFilter *output = fg->outputs[i]; + if (!output->ost) { + av_log(filtergraphs[i], AV_LOG_FATAL, + "Filter %s has an unconnected output\n", output->name); + return AVERROR(EINVAL); + } + } return 0; } @@ -1436,23 +1451,6 @@ static int configure_output_filter(FilterGraph *fg, AVFilterGraph *graph, } } -int check_filter_outputs(void) -{ - for (int i = 0; i < nb_filtergraphs; i++) { - int n; - for (n = 0; n < filtergraphs[i]->nb_outputs; n++) { - OutputFilter *output = filtergraphs[i]->outputs[n]; - if (!output->ost) { - av_log(filtergraphs[i], AV_LOG_FATAL, - "Filter %s has an unconnected output\n", output->name); - return AVERROR(EINVAL); - } - } - } - - return 0; -} - static void sub2video_prepare(InputFilterPriv *ifp) { ifp->sub2video.last_pts = INT64_MIN; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index a9a785a0ac..b550382b4c 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -674,18 +674,6 @@ static int opt_streamid(void *optctx, const char *opt, const char *arg) return av_dict_set(&o->streamid, idx_str, p, 0); } -static int init_complex_filters(void) -{ - int i, ret = 0; - - for (i = 0; i < nb_filtergraphs; i++) { - ret = init_complex_filtergraph(filtergraphs[i]); - if (ret < 0) - return ret; - } - return 0; -} - static int opt_target(void *optctx, const char *opt, const char *arg) { OptionsContext *o = optctx; @@ -1264,13 +1252,6 @@ int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch) goto fail; } - /* create the complex filtergraphs */ - ret = init_complex_filters(); - if (ret < 0) { - errmsg = "initializing complex filters"; - goto fail; - } - /* open output files */ ret = open_files(&octx.groups[GROUP_OUTFILE], "output", sch, of_open); if (ret < 0) { @@ -1278,16 +1259,21 @@ int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch) goto fail; } + // bind unbound filtegraph inputs/outputs and check consistency + for (int i = 0; i < nb_filtergraphs; i++) { + ret = fg_finalise_bindings(filtergraphs[i]); + if (ret < 0) { + errmsg = "binding filtergraph inputs/outputs"; + goto fail; + } + } + correct_input_start_times(); ret = apply_sync_offsets(); if (ret < 0) goto fail; - ret = check_filter_outputs(); - if (ret < 0) - goto fail; - fail: uninit_parse_context(&octx); if (ret < 0 && ret != AVERROR_EXIT) { -- 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-03-06 11:06 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-03-06 11:03 [FFmpeg-devel] [PATCH 01/18] fftools/cmdutils: fix printing group name in split_commandline() Anton Khirnov 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 02/18] fftools/ffmpeg_filter: refactor setting input timebase Anton Khirnov 2024-03-07 20:37 ` Michael Niedermayer 2024-03-08 5:34 ` Anton Khirnov 2024-03-10 3:36 ` Michael Niedermayer 2024-03-10 6:13 ` Anton Khirnov 2024-03-10 19:21 ` Michael Niedermayer 2024-03-10 22:24 ` Anton Khirnov 2024-03-10 22:29 ` James Almer 2024-03-10 22:49 ` Anton Khirnov 2024-03-10 23:37 ` Michael Niedermayer 2024-03-11 6:03 ` Anton Khirnov 2024-03-11 10:12 ` Tobias Rapp 2024-03-11 12:23 ` Anton Khirnov 2024-03-11 12:29 ` Martin Storsjö 2024-03-11 13:28 ` Anton Khirnov 2024-03-11 14:03 ` Martin Storsjö via ffmpeg-devel 2024-03-11 14:32 ` Anton Khirnov 2024-03-11 14:37 ` Martin Storsjö 2024-03-11 14:31 ` Tobias Rapp 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 03/18] fftools/ffmpeg_filter: drop unused InputFilterPriv.ist Anton Khirnov 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 04/18] fftools/ffmpeg_dec: move scheduler registration from dec_open() to dec_alloc() Anton Khirnov 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 05/18] fftools/ffmpeg_dec: factor opening the decoder out of dec_open() Anton Khirnov 2024-03-06 11:03 ` Anton Khirnov [this message] 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 07/18] fftools/ffmpeg_filter: move filtergraph input type check to a better place Anton Khirnov 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 08/18] fftools/ffmpeg_filter: add logging for binding inputs to demuxer streams Anton Khirnov 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 09/18] fftools/ffmpeg: simplify propagating fallback parameters from decoders to filters Anton Khirnov 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 10/18] fftools/ffmpeg: remove unncessary casts for *_thread() return values Anton Khirnov 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 11/18] fftools/ffmpeg_enc: drop unnecessary parameter from forced_kf_apply() Anton Khirnov 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 12/18] fftools/ffmpeg_enc: merge do_{audio, video}_out into frame_encode() Anton Khirnov 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 13/18] fftools/ffmpeg_sched: allow encoders to send to multiple destinations Anton Khirnov 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 14/18] fftools/ffmpeg_sched: factor initializing nodes into separate function Anton Khirnov 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 15/18] fftools/ffmpeg_sched: allow connecting encoder output to decoders Anton Khirnov 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 16/18] fftools/ffmpeg: prepare FrameData for having allocated fields Anton Khirnov 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 17/18] fftools/ffmpeg: add loopback decoding Anton Khirnov 2024-03-07 14:42 ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov 2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 18/18] fftools/ffmpeg_enc: set AV_PKT_FLAG_TRUSTED on encoded packets Anton Khirnov 2024-03-09 19:08 ` [FFmpeg-devel] [PATCH 01/18] fftools/cmdutils: fix printing group name in split_commandline() 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=20240306110319.17339-6-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