From patchwork Sun May 28 09:13:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41854 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp987291pzb; Sun, 28 May 2023 02:15:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6YrEiRFj85OMMmDZKjmFdol57rqJvV8D/n1icH+24iWTkhrsMz8J7BNblQkpsX8EonTjO9 X-Received: by 2002:a17:907:7f0c:b0:96f:44b0:b3b7 with SMTP id qf12-20020a1709077f0c00b0096f44b0b3b7mr9374326ejc.7.1685265344648; Sun, 28 May 2023 02:15:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265344; cv=none; d=google.com; s=arc-20160816; b=Uoi1plTaaMIwQZUZi8L//FArCw87xVQd4nDjvUVRluNeHJq4rBFF/tjxCGw1IfpY72 sS7ZDUqcdUCm2p4NR9w/0d1Dhjot8qnwbshbjjW0hbas4Mf1edn2P8w2jOCx6YSAJADL n9sf4DcA4ROMseEjKKUE2w/Sq8p8c39fVi9udtIy15A203kGrYTwTkehZP2z03FrsX8J iUGyrzuLsQnY1o8O3tFbt97LVBR7YfTo2szfLrIePYiPcK4pzlsIEahUC0mEMkC0a67o bjCgjqRHZpNXJlqiISlcbnNntoZEhdare2KPICw9LW+qyYsPCAKEd9nW5BLUzZUW0cNB REnQ== 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:message-id:date:to:from :delivered-to; bh=1xWBu8g0QoLWrt30F0rYvqr8XFkBDKkXew525IF3q9Y=; b=PA8TlNqhbr5CsbrTnj5AE9JrSU4VHq6fdeORDiwz5oN8ri2I/BmtrnvMeLSEZ1MvfR vaTeVUVRYHfmsBYFx5rPYd3DCTld5HvMeiK+zxRK2zKZMnc/rgUEwEJv9ScAONs8zY8s begtnVrKIj529MBoswCef66dJJbqepmWecX9QEa6JF1m8npjbEHOnZeRtgJ0hs5hJ+4u loUuLB5NegffgUF9jivMax9o9DrPugfqQ1/lmEctbleQYaDk+kglwNfLbtrJMkoJjetW N+N2PdUGxyS6FBi2T0owc79GLcuFQiuhwof/fpI59uC4en+MgaPjgk61jg3KbVDmGGv4 mEPg== 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 ku5-20020a170907788500b0094ed5083927si1274140ejc.426.2023.05.28.02.15.44; Sun, 28 May 2023 02:15:44 -0700 (PDT) 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 8F6DF68C230; Sun, 28 May 2023 12:15:00 +0300 (EEST) 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 7970E68C1E6 for ; Sun, 28 May 2023 12:14:50 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3F53F2404EC for ; Sun, 28 May 2023 11:14:50 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id zhNb0JchKMRf for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) 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 71E03240177 for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 112BE3A01C0 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:13:53 +0200 Message-Id: <20230528091416.17927-1-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/24] fftools/ffmpeg_mux_init: merge ost_add_from_filter() to ost_add() 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: j5opB//vDxfx This way ost_add() knows about the complex filtergraph it is fed from, which will become useful in future commits. --- fftools/ffmpeg_mux_init.c | 71 ++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 7878789bb4..de39b360af 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -985,7 +985,8 @@ fail: } static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, - enum AVMediaType type, InputStream *ist) + enum AVMediaType type, InputStream *ist, + OutputFilter *ofilter) { AVFormatContext *oc = mux->fc; MuxStream *ms; @@ -1040,6 +1041,14 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, av_strlcat(ms->log_name, "/", sizeof(ms->log_name)); av_strlcat(ms->log_name, enc->name, sizeof(ms->log_name)); } else { + if (ofilter) { + av_log(ost, AV_LOG_ERROR, + "Streamcopy requested for output stream fed " + "from a complex filtergraph. Filtering and streamcopy " + "cannot be used together.\n"); + exit_program(1); + } + av_strlcat(ms->log_name, "/copy", sizeof(ms->log_name)); } @@ -1233,22 +1242,26 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, exit_program(1); } - if (ost->ist) { - if (ost->enc && - (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { + if (ost->enc && + (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { + if (ofilter) { + ost->filter = ofilter; + ofilter->ost = ost; + avfilter_inout_free(&ofilter->out_tmp); + } else { ret = init_simple_filtergraph(ost->ist, ost); if (ret < 0) { av_log(ost, AV_LOG_ERROR, "Error initializing a simple filtergraph\n"); exit_program(1); } - } else { - ret = ist_output_add(ost->ist, ost); - if (ret < 0) { - av_log(ost, AV_LOG_ERROR, - "Error binding an input stream\n"); - exit_program(1); - } + } + } else if (ost->ist) { + ret = ist_output_add(ost->ist, ost); + if (ret < 0) { + av_log(ost, AV_LOG_ERROR, + "Error binding an input stream\n"); + exit_program(1); } } @@ -1261,26 +1274,6 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, return ost; } -// add a new output stream fed by the provided filtergraph output -static void ost_add_from_filter(OutputFilter *ofilter, const OptionsContext *o, - Muxer *mux) -{ - OutputStream *ost = ost_add(mux, o, ofilter->type, NULL); - - ost->filter = ofilter; - - ofilter->ost = ost; - - if (!ost->enc_ctx) { - av_log(ost, AV_LOG_ERROR, "Streamcopy requested for output stream fed " - "from a complex filtergraph. Filtering and streamcopy " - "cannot be used together.\n"); - exit_program(1); - } - - avfilter_inout_free(&ofilter->out_tmp); -} - static void map_auto_video(Muxer *mux, const OptionsContext *o) { AVFormatContext *oc = mux->fc; @@ -1329,7 +1322,7 @@ static void map_auto_video(Muxer *mux, const OptionsContext *o) } } if (best_ist) - ost_add(mux, o, AVMEDIA_TYPE_VIDEO, best_ist); + ost_add(mux, o, AVMEDIA_TYPE_VIDEO, best_ist, NULL); } static void map_auto_audio(Muxer *mux, const OptionsContext *o) @@ -1371,7 +1364,7 @@ static void map_auto_audio(Muxer *mux, const OptionsContext *o) } } if (best_ist) - ost_add(mux, o, AVMEDIA_TYPE_AUDIO, best_ist); + ost_add(mux, o, AVMEDIA_TYPE_AUDIO, best_ist, NULL); } static void map_auto_subtitle(Muxer *mux, const OptionsContext *o) @@ -1406,7 +1399,7 @@ static void map_auto_subtitle(Muxer *mux, const OptionsContext *o) input_descriptor && output_descriptor && (!input_descriptor->props || !output_descriptor->props)) { - ost_add(mux, o, AVMEDIA_TYPE_SUBTITLE, ist); + ost_add(mux, o, AVMEDIA_TYPE_SUBTITLE, ist, NULL); break; } } @@ -1426,7 +1419,7 @@ static void map_auto_data(Muxer *mux, const OptionsContext *o) continue; if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA && ist->st->codecpar->codec_id == codec_id ) - ost_add(mux, o, AVMEDIA_TYPE_DATA, ist); + ost_add(mux, o, AVMEDIA_TYPE_DATA, ist, NULL); } } @@ -1458,7 +1451,7 @@ loop_end: "in any defined filter graph, or was already used elsewhere.\n", map->linklabel); exit_program(1); } - ost_add_from_filter(ofilter, o, mux); + ost_add(mux, o, ofilter->type, NULL, ofilter); } else { ist = input_files[map->file_index]->streams[map->stream_index]; if (ist->user_set_discard == AVDISCARD_ALL) { @@ -1490,7 +1483,7 @@ loop_end: return; } - ost_add(mux, o, ist->st->codecpar->codec_type, ist); + ost_add(mux, o, ist->st->codecpar->codec_type, ist, NULL); } } @@ -1524,7 +1517,7 @@ static void of_add_attachments(Muxer *mux, const OptionsContext *o) avio_read(pb, attachment, len); memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE); - ost = ost_add(mux, o, AVMEDIA_TYPE_ATTACHMENT, NULL); + ost = ost_add(mux, o, AVMEDIA_TYPE_ATTACHMENT, NULL, NULL); ost->attachment_filename = o->attachments[i]; ost->par_in->extradata = attachment; ost->par_in->extradata_size = len; @@ -1557,7 +1550,7 @@ static void create_streams(Muxer *mux, const OptionsContext *o) case AVMEDIA_TYPE_AUDIO: auto_disable_a = 1; break; case AVMEDIA_TYPE_SUBTITLE: auto_disable_s = 1; break; } - ost_add_from_filter(ofilter, o, mux); + ost_add(mux, o, ofilter->type, NULL, ofilter); } }