From patchwork Thu Nov 17 10:16:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39319 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp997703pzb; Thu, 17 Nov 2022 02:18:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf4gmKrrRUl10qG4wqSKAFLaEv3P7idjd9wDa+GVvvCrYirWE9hPHlNtjalSvk3NAgJ1Ghfa X-Received: by 2002:aa7:cc08:0:b0:461:8a43:e93 with SMTP id q8-20020aa7cc08000000b004618a430e93mr1440033edt.275.1668680294603; Thu, 17 Nov 2022 02:18:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668680294; cv=none; d=google.com; s=arc-20160816; b=X9qBJAyjPtqVV96YDJadlJO8H/MJVU+GJUHbrJsu+or8qdItfUTuinXCuwAFHqU136 FaxkiBtYedJPJQEO5Kl4J8olaHPcLo1toxvQ3OQJph4VrSu68YVL3KCIuE/xewe8D9a3 sKPx54g2N3zASnLfxDnzi8AWmImasT2HzXmE9TrpTEjZ5o085yUOWsnAe9CiBU2O+sEO mgWhJwjYbPWHCbT5yiFCXBZzSotd85wE4jEz0bO6JRPNg4FRNYeeNqo5NL4znaP4z+r6 5Cy70SR+T4bNfC1czeD+9DISfbz/TQuE8LwcVK2thUve1wWpVD5+QcKq/Sx1jaDN4sv/ UMDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=fPQi812QD9bSrl/2b19M0l0lIrrmxQ0sYrHwdgkGomk=; b=qnKzOLidFcn1Tq4NfpVD9lyD8TO6+oYcVu2hOdBnXXZ7B+Z5bmu/FIHjOXmU0KEs0O fYwHwkEcrrlP7sJAMAunQWs8/Y8p9KfwMnyWnnCqEiX3VPLwbCVS7qLQmtWelZ1eYMK5 lnbudJ5y52w9lf1QaoP6o1P2OOfqDW2Hossq/Sg8TT02eewT4QgKeW9sHw76bOwBL3rr efwBHeKj1QEZVtXyDxA3/2q3RLn4SeGJIQK08sZr3idpLUrE63WmWxdYAbEXzrhHl+65 QquCooT0g/4G0TO+t7h0Mcfn1vcXzTYOGMjLRGg8jOal7Q00ftWANLJz2XRcsc6HRGe7 vqRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 17-20020a170906059100b0078df19995e4si189057ejn.241.2022.11.17.02.18.14; Thu, 17 Nov 2022 02:18:14 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5223368BDFF; Thu, 17 Nov 2022 12:17:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 579B368BDA1 for ; Thu, 17 Nov 2022 12:16:50 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EC2E92406CA for ; Thu, 17 Nov 2022 11:16:48 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id gfM4JURM9T-U for ; Thu, 17 Nov 2022 11:16:47 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 6E14D2406CB for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 5FFA43A0520 for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Nov 2022 11:16:40 +0100 Message-Id: <20221117101640.6789-10-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221117101640.6789-1-anton@khirnov.net> References: <20221117101640.6789-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/10] fftools/ffmpeg_mux_init: postpone matching -disposition to streams X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: HCx2U06r+CKQ 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);