From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 29/31] fftools/ffmpeg_sched: allow filtergraphs to send to filtergraphs Date: Fri, 5 Apr 2024 18:12:10 +0200 Message-ID: <20240405161212.26167-29-anton@khirnov.net> (raw) In-Reply-To: <20240405161212.26167-1-anton@khirnov.net> Will be useful for filtergraph chaining that will be added in following commits. --- fftools/ffmpeg_sched.c | 94 ++++++++++++++++++++++++++---------------- fftools/ffmpeg_sched.h | 6 ++- 2 files changed, 63 insertions(+), 37 deletions(-) diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c index f8485db30b..e58b00ea97 100644 --- a/fftools/ffmpeg_sched.c +++ b/fftools/ffmpeg_sched.c @@ -983,20 +983,40 @@ int sch_connect(Scheduler *sch, SchedulerNode src, SchedulerNode dst) } case SCH_NODE_TYPE_FILTER_OUT: { SchFilterOut *fo; - SchEnc *enc; av_assert0(src.idx < sch->nb_filters && src.idx_stream < sch->filters[src.idx].nb_outputs); - // filtered frames go to encoding - av_assert0(dst.type == SCH_NODE_TYPE_ENC && - dst.idx < sch->nb_enc); + fo = &sch->filters[src.idx].outputs[src.idx_stream]; - fo = &sch->filters[src.idx].outputs[src.idx_stream]; - enc = &sch->enc[dst.idx]; + av_assert0(!fo->dst.type); + fo->dst = dst; + + // filtered frames go to encoding or another filtergraph + switch (dst.type) { + case SCH_NODE_TYPE_ENC: { + SchEnc *enc; + + av_assert0(dst.idx < sch->nb_enc); + enc = &sch->enc[dst.idx]; + + av_assert0(!enc->src.type); + enc->src = src; + break; + } + case SCH_NODE_TYPE_FILTER_IN: { + SchFilterIn *fi; + + av_assert0(dst.idx < sch->nb_filters && + dst.idx_stream < sch->filters[dst.idx].nb_inputs); + fi = &sch->filters[dst.idx].inputs[dst.idx_stream]; + + av_assert0(!fi->src.type); + fi->src = src; + break; + } + default: av_assert0(0); + } - av_assert0(!fo->dst.type && !enc->src.type); - fo->dst = dst; - enc->src = src; break; } @@ -1351,24 +1371,13 @@ static int check_acyclic(Scheduler *sch) goto fail; } - // trace the transcoding graph upstream from every output stream - // fed by a filtergraph - for (unsigned i = 0; i < sch->nb_mux; i++) { - SchMux *mux = &sch->mux[i]; - - for (unsigned j = 0; j < mux->nb_streams; j++) { - SchMuxStream *ms = &mux->streams[j]; - SchedulerNode src = ms->src_sched; - - if (src.type != SCH_NODE_TYPE_FILTER_OUT) - continue; - src.idx_stream = 0; - - ret = check_acyclic_for_output(sch, src, filters_visited, filters_stack); - if (ret < 0) { - av_log(mux, AV_LOG_ERROR, "Transcoding graph has a cycle\n"); - goto fail; - } + // trace the transcoding graph upstream from every filtegraph + for (unsigned i = 0; i < sch->nb_filters; i++) { + ret = check_acyclic_for_output(sch, (SchedulerNode){ .idx = i }, + filters_visited, filters_stack); + if (ret < 0) { + av_log(&sch->filters[i], AV_LOG_ERROR, "Transcoding graph has a cycle\n"); + goto fail; } } @@ -1484,13 +1493,18 @@ static int start_prepare(Scheduler *sch) "Filtergraph input %u not connected to a source\n", j); return AVERROR(EINVAL); } - av_assert0(fi->src.type == SCH_NODE_TYPE_DEC); - dec = &sch->dec[fi->src.idx]; - switch (dec->src.type) { - case SCH_NODE_TYPE_DEMUX: fi->src_sched = dec->src; break; - case SCH_NODE_TYPE_ENC: fi->src_sched = sch->enc[dec->src.idx].src; break; - default: av_assert0(0); + if (fi->src.type == SCH_NODE_TYPE_FILTER_OUT) + fi->src_sched = fi->src; + else { + av_assert0(fi->src.type == SCH_NODE_TYPE_DEC); + dec = &sch->dec[fi->src.idx]; + + switch (dec->src.type) { + case SCH_NODE_TYPE_DEMUX: fi->src_sched = dec->src; break; + case SCH_NODE_TYPE_ENC: fi->src_sched = sch->enc[dec->src.idx].src; break; + default: av_assert0(0); + } } } @@ -2379,12 +2393,17 @@ void sch_filter_receive_finish(Scheduler *sch, unsigned fg_idx, unsigned in_idx) int sch_filter_send(Scheduler *sch, unsigned fg_idx, unsigned out_idx, AVFrame *frame) { SchFilterGraph *fg; + SchedulerNode dst; av_assert0(fg_idx < sch->nb_filters); fg = &sch->filters[fg_idx]; av_assert0(out_idx < fg->nb_outputs); - return send_to_enc(sch, &sch->enc[fg->outputs[out_idx].dst.idx], frame); + dst = fg->outputs[out_idx].dst; + + return (dst.type == SCH_NODE_TYPE_ENC) ? + send_to_enc (sch, &sch->enc[dst.idx], frame) : + send_to_filter(sch, &sch->filters[dst.idx], dst.idx_stream, frame); } static int filter_done(Scheduler *sch, unsigned fg_idx) @@ -2396,8 +2415,11 @@ static int filter_done(Scheduler *sch, unsigned fg_idx) tq_receive_finish(fg->queue, i); for (unsigned i = 0; i < fg->nb_outputs; i++) { - SchEnc *enc = &sch->enc[fg->outputs[i].dst.idx]; - int err = send_to_enc(sch, enc, NULL); + SchedulerNode dst = fg->outputs[i].dst; + int err = (dst.type == SCH_NODE_TYPE_ENC) ? + send_to_enc (sch, &sch->enc[dst.idx], NULL) : + send_to_filter(sch, &sch->filters[dst.idx], dst.idx_stream, NULL); + if (err < 0 && err != AVERROR_EOF) ret = err_merge(ret, err); } diff --git a/fftools/ffmpeg_sched.h b/fftools/ffmpeg_sched.h index e51c26cec9..7cd839016c 100644 --- a/fftools/ffmpeg_sched.h +++ b/fftools/ffmpeg_sched.h @@ -41,7 +41,8 @@ * - filtergraphs, each containing zero or more inputs (0 in case the * filtergraph contains a lavfi source filter), and one or more outputs; the * inputs and outputs need not have matching media types; - * each filtergraph input receives decoded frames from some decoder; + * each filtergraph input receives decoded frames from some decoder or another + * filtergraph output; * filtered frames from each output are sent to some encoder; * - encoders, which receive decoded frames from some decoder (subtitles) or * some filtergraph output (audio/video), encode them, and send encoded @@ -51,6 +52,9 @@ * encoder (transcoding); those packets are interleaved and written out by the * muxer. * + * The structure formed by the above components is a directed acyclic graph + * (absence of cycles is checked at startup). + * * There must be at least one muxer instance, otherwise the transcode produces * no output and is meaningless. Otherwise, in a generic transcoding scenario * there may be arbitrary number of instances of any of the above components, -- 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:15 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 ` [FFmpeg-devel] [PATCH 12/31] fftools/ffmpeg_filter: pass vsync method through OutputFilterOptions Anton Khirnov 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 ` Anton Khirnov [this message] 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-29-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