From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 10/10] fftools/ffmpeg_mux_init: postpone matching -disposition to streams Date: Thu, 17 Nov 2022 11:16:40 +0100 Message-ID: <20221117101640.6789-10-anton@khirnov.net> (raw) In-Reply-To: <20221117101640.6789-1-anton@khirnov.net> Do it in set_dispositions() rather than during stream creation. Since at this point all other stream information is known, this allows setting disposition based on metadata, which implements #10015. This also avoids an extra allocated string in OutputStream that was unused after of_open(). --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_mux.c | 1 - fftools/ffmpeg_mux_init.c | 36 ++++++++++++++++++++++++------------ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 5cae266600..4b76b1d0d7 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -585,7 +585,6 @@ typedef struct OutputStream { int streamcopy_started; int copy_initial_nonkeyframes; int copy_prior_start; - char *disposition; int keep_pix_fmt; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index ad04f5049d..2b885f7ab0 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -673,7 +673,6 @@ static void ost_free(OutputStream **post) av_freep(&ost->logfile_prefix); av_freep(&ost->forced_kf_pts); av_freep(&ost->apad); - av_freep(&ost->disposition); #if FFMPEG_OPT_MAP_CHANNEL av_freep(&ost->audio_channels_map); diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index b6782b49aa..7aa2e030d8 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -333,9 +333,6 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale; } - MATCH_PER_STREAM_OPT(disposition, str, ost->disposition, oc, st); - ost->disposition = av_strdup(ost->disposition); - ms->max_muxing_queue_size = 128; MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ms->max_muxing_queue_size, oc, st); @@ -1667,11 +1664,21 @@ static void copy_meta(Muxer *mux, const OptionsContext *o) } } -static int set_dispositions(OutputFile *of, AVFormatContext *ctx) +static int set_dispositions(Muxer *mux, const OptionsContext *o) { + OutputFile *of = &mux->of; + AVFormatContext *ctx = mux->fc; + int nb_streams[AVMEDIA_TYPE_NB] = { 0 }; int have_default[AVMEDIA_TYPE_NB] = { 0 }; int have_manual = 0; + int ret = 0; + + const char **dispositions; + + dispositions = av_calloc(ctx->nb_streams, sizeof(*dispositions)); + if (!dispositions) + return AVERROR(ENOMEM); // first, copy the input dispositions for (int i = 0; i < ctx->nb_streams; i++) { @@ -1679,7 +1686,9 @@ static int set_dispositions(OutputFile *of, AVFormatContext *ctx) nb_streams[ost->st->codecpar->codec_type]++; - have_manual |= !!ost->disposition; + MATCH_PER_STREAM_OPT(disposition, str, dispositions[i], ctx, ost->st); + + have_manual |= !!dispositions[i]; if (ost->ist) { ost->st->disposition = ost->ist->st->disposition; @@ -1693,25 +1702,25 @@ static int set_dispositions(OutputFile *of, AVFormatContext *ctx) // process manually set dispositions - they override the above copy for (int i = 0; i < ctx->nb_streams; i++) { OutputStream *ost = of->streams[i]; - int ret; + const char *disp = dispositions[i]; - if (!ost->disposition) + if (!disp) continue; #if LIBAVFORMAT_VERSION_MAJOR >= 60 - ret = av_opt_set(ost->st, "disposition", ost->disposition, 0); + ret = av_opt_set(ost->st, "disposition", disp, 0); #else { const AVClass *class = av_stream_get_class(); const AVOption *o = av_opt_find(&class, "disposition", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ); av_assert0(o); - ret = av_opt_eval_flags(&class, o, ost->disposition, &ost->st->disposition); + ret = av_opt_eval_flags(&class, o, disp, &ost->st->disposition); } #endif if (ret < 0) - return ret; + goto finish; } } else { // For each media type with more than one stream, find a suitable stream to @@ -1730,7 +1739,10 @@ static int set_dispositions(OutputFile *of, AVFormatContext *ctx) } } - return 0; +finish: + av_freep(&dispositions); + + return ret; } static void validate_enc_avopt(const Muxer *mux, const AVDictionary *codec_avopt) @@ -1943,7 +1955,7 @@ int of_open(const OptionsContext *o, const char *filename) of_add_programs(oc, o); of_add_metadata(of, oc, o); - err = set_dispositions(of, oc); + err = set_dispositions(mux, o); if (err < 0) { av_log(NULL, AV_LOG_FATAL, "Error setting output stream dispositions\n"); exit_program(1); -- 2.35.1 _______________________________________________ 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".
prev parent reply other threads:[~2022-11-17 10:18 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-11-17 10:16 [FFmpeg-devel] [PATCH 01/10] fftools/ffmpeg: move freeing an input stream into a separate function Anton Khirnov 2022-11-17 10:16 ` [FFmpeg-devel] [PATCH 02/10] fftools/ffmpeg: drop an arbitrary condition Anton Khirnov 2022-11-17 10:16 ` [FFmpeg-devel] [PATCH 03/10] fftools/ffmpeg: stop inventing fake source information Anton Khirnov 2022-11-17 10:16 ` [FFmpeg-devel] [PATCH 04/10] fftools/ffmpeg: replace OutputStream.source_index with a pointer to InputStream Anton Khirnov 2022-11-17 10:16 ` [FFmpeg-devel] [PATCH 05/10] fftools/ffmpeg_mux_init: simplify inner loop in map_auto_{video, audio} Anton Khirnov 2022-11-17 10:16 ` [FFmpeg-devel] [PATCH 06/10] fftools/ffmpeg: remove the input_streams global Anton Khirnov 2022-11-17 10:16 ` [FFmpeg-devel] [PATCH 07/10] fftools/ffmpeg: do not assume input streams exist Anton Khirnov 2022-11-17 10:16 ` [FFmpeg-devel] [PATCH 08/10] fftools/ffmpeg: declare loop variables inside loops in transcode_init() Anton Khirnov 2022-11-17 10:16 ` [FFmpeg-devel] [PATCH 09/10] fftools/ffmpeg: _-prefix variables in MATCH_PER_STREAM_OPT() Anton Khirnov 2022-11-17 10:16 ` Anton Khirnov [this message]
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=20221117101640.6789-10-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