From patchwork Fri Apr 5 16:12:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 47845 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp1070625pzd; Fri, 5 Apr 2024 09:15:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWSFPmNlXyxX2DMPwznSqF/LuqjDBj/CNcpAsWb2C+l595NaPy06VbaSDUYT8eJ8deH1hI+ZW3BI1d4YPzpTQyPFk51W/kaszQngw== X-Google-Smtp-Source: AGHT+IGNX+/5pxACRY6/PTtj/IvZg9oFrTDjjZIg7Fbr4T+VW3+PT2YZyVCqhuv1O+VZWdzrSCHw X-Received: by 2002:a50:d714:0:b0:56e:2e0:79d1 with SMTP id t20-20020a50d714000000b0056e02e079d1mr1425306edi.4.1712333752076; Fri, 05 Apr 2024 09:15:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712333752; cv=none; d=google.com; s=arc-20160816; b=SFKh/hIniAJL3FiyHfwm+jRImp6dgNkE2AwlN94F/Ru7gY95+dUMXb4Sz8S89wnaZd QcE3mokcoM9lcjHXjwGh6lHVoTtn7rjj+5K0WsrmVet2p+uQyBYIMTIMU1UKHuvopDF9 Q4Zl1W1EMg3ZOSAQ0d3nqyFMHBYSETnPec2H34HK4qLEtFUU9GzwwVIo5ERmegXUHqvk s5i6euXgvZJcS3zikoqHeXiI8uEk8gtoUNY4RR+WOCHsMVJ7NgmLO76UsOoeVba7CepO L7oewJ7TH0/yOX5wdkRs5CNMTGdqBIATNmohOx2GLdFORxZlykvs60iEsMZPTZwUWa6W mi/g== 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:dkim-signature:delivered-to; bh=PE3B7K4rnHI3o396CsUYtEs1R7bFpIY3inUpl6lriTg=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=BkJLjCqaCGLshyCitwB9MjSiHwXGaXffTYYz5mmyxbNU7/bzg37sUMZhOD6M6m2DeN vdP5QWsYIBG/pzZSREIHvP+L2bLKPtKfnkYsrjKnzMVCmllhxXzfmmaQtZtXEdb65LyD hAnzNmTclXcqyF/emXAWUmUxa9QQcjSlyAIqDkyt7dH2tjvJV0PcbLlLVmdU0UrZ9YKh pHigrHJGNmiifWJva5CZYS3ghLPfxhfTGmDj8a2Dhl9gC9RUmnEb7Vxc/mdaUb8+mnjd um4lRuImEzKzi5khZkS3o7VumyuLBhuZ318CiodzKYK+Ov6XOlIUTKk3SY3cO6zY/IxR NzrA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=KUVh02gS; 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 c22-20020a50f616000000b0056e2acef875si880414edn.669.2024.04.05.09.15.51; Fri, 05 Apr 2024 09:15:52 -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; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=KUVh02gS; 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 EE4D368D28A; Fri, 5 Apr 2024 19:13:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5EB5668D1A6 for ; Fri, 5 Apr 2024 19:13:10 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=KUVh02gS; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id E89E04D8D for ; Fri, 5 Apr 2024 18:13:07 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 09HeCaIn9FfG for ; Fri, 5 Apr 2024 18:13:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1712333583; bh=GQEBp8yNwDFjYJ8uYNyAPQDX0WY2bCGeYzKqPYpF24Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KUVh02gSAcrL2opXkKi0mHYPEt91SgbN7G+q3mwoVfyui4R+sWnkCfUSKSxCeMlnp 9Z5VPG7NQNkTdWkd13+GhrJDDSTG6gEAF21xlMYPVDAbzVn0mZu0wqzmgeHL4GUn+X TuFP82UipbnAppAoqBRaz8vxIuuo5P5zwf7wSg6uOOStTiHptdFWtqvZd6kESM0Pji 2TAdTdimWaqgazShXDLYL71hx1LfRYm67tqbg+GfvcTb/Rlnp05CgjRmkSfPpq77Pw wGnRH88hcybcLEwhXH0mor1EsJAfnM9VHhh1FuQqGU9iu7I++aCYQIpAaD/qO5y1bn DcEwj0kdIhj2Q== 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 mail1.khirnov.net (Postfix) with ESMTPS id 753B94D76 for ; Fri, 5 Apr 2024 18:13:03 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 75E143A1752 for ; Fri, 5 Apr 2024 18:12:56 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Apr 2024 18:12:03 +0200 Message-ID: <20240405161212.26167-22-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240405161212.26167-1-anton@khirnov.net> References: <20240405161212.26167-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/31] fftools/ffmpeg_filter: move most of -apad logic to the muxer 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: a4uBBrtSwQTn The decision whether -apad actually does anything is made based on muxer properties, and so more properly belongs there. Filtering code only receives the result. --- fftools/ffmpeg.h | 3 ++- fftools/ffmpeg_filter.c | 16 +++------------- fftools/ffmpeg_mux.c | 1 - fftools/ffmpeg_mux.h | 2 ++ fftools/ffmpeg_mux_init.c | 36 +++++++++++++++++++++++++++++------- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 8e773165da..26b42a3fcd 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -320,6 +320,8 @@ typedef struct OutputFilter { * this stores the output linklabel, if any */ uint8_t *linklabel; + char *apad; + enum AVMediaType type; atomic_uint_least64_t nb_frames_dup; @@ -581,7 +583,6 @@ typedef struct OutputStream { OutputFilter *filter; AVDictionary *encoder_opts; - char *apad; char *attachment_filename; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 225fa4bda2..ec17e99494 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -969,6 +969,7 @@ void fg_free(FilterGraph **pfg) av_freep(&ofilter->linklabel); av_freep(&ofilter->name); + av_freep(&ofilter->apad); av_freep(&ofp->name); av_channel_layout_uninit(&ofp->ch_layout); av_freep(&fg->outputs[j]); @@ -1430,8 +1431,6 @@ static int configure_output_audio_filter(FilterGraph *fg, AVFilterGraph *graph, OutputFilter *ofilter, AVFilterInOut *out) { OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); - OutputStream *ost = ofilter->ost; - OutputFile *of = ost->file; AVFilterContext *last_filter = out->filter_ctx; int pad_idx = out->pad_idx; AVBPrint args; @@ -1493,17 +1492,8 @@ static int configure_output_audio_filter(FilterGraph *fg, AVFilterGraph *graph, pad_idx = 0; } - if (ost->apad && of->shortest) { - int i; - - for (i = 0; i < of->nb_streams; i++) - if (of->streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) - break; - - if (i < of->nb_streams) { - AUTO_INSERT_FILTER("-apad", "apad", ost->apad); - } - } + if (ofilter->apad) + AUTO_INSERT_FILTER("-apad", "apad", ofilter->apad); snprintf(name, sizeof(name), "trim for output %s", ofp->name); ret = insert_trim(ofp->trim_start_us, ofp->trim_duration_us, diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 557f08b3a5..6a64cba72d 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -815,7 +815,6 @@ static void ost_free(OutputStream **post) av_expr_free(ost->kf.pexpr); av_freep(&ost->logfile_prefix); - av_freep(&ost->apad); av_freep(&ost->attachment_filename); diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h index f8b6f7a790..1e9ea35412 100644 --- a/fftools/ffmpeg_mux.h +++ b/fftools/ffmpeg_mux.h @@ -78,6 +78,8 @@ typedef struct MuxStream { #if FFMPEG_OPT_VSYNC_DROP int ts_drop; #endif + + char *apad; } MuxStream; typedef struct Muxer { diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 6e19b98abd..a483fffa6e 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -828,6 +828,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, static int new_stream_audio(Muxer *mux, const OptionsContext *o, OutputStream *ost) { + MuxStream *ms = ms_from_ost(ost); AVFormatContext *oc = mux->fc; AVStream *st = ost->st; @@ -836,7 +837,6 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o, int channels = 0; char *layout = NULL; char *sample_fmt = NULL; - const char *apad = NULL; MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st); if (channels) { @@ -859,12 +859,7 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o, MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st); - MATCH_PER_STREAM_OPT(apad, str, apad, oc, st); - if (apad) { - ost->apad = av_strdup(apad); - if (!ost->apad) - return AVERROR(ENOMEM); - } + MATCH_PER_STREAM_OPT(apad, str, ms->apad, oc, st); } return 0; @@ -1890,6 +1885,33 @@ static int create_streams(Muxer *mux, const OptionsContext *o) } } + // handle -apad + if (mux->of.shortest) { + int have_video = 0; + + for (unsigned i = 0; i < mux->of.nb_streams; i++) + if (mux->of.streams[i]->type == AVMEDIA_TYPE_VIDEO) { + have_video = 1; + break; + } + + for (unsigned i = 0; have_video && i < mux->of.nb_streams; i++) { + MuxStream *ms = ms_from_ost(mux->of.streams[i]); + OutputFilter *ofilter = ms->ost.filter; + + if (ms->ost.type != AVMEDIA_TYPE_AUDIO || !ms->apad || !ofilter) + continue; + + ofilter->apad = av_strdup(ms->apad); + if (!ofilter->apad) + return AVERROR(ENOMEM); + } + } + for (unsigned i = 0; i < mux->of.nb_streams; i++) { + MuxStream *ms = ms_from_ost(mux->of.streams[i]); + ms->apad = NULL; + } + if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) { av_dump_format(oc, nb_output_files - 1, oc->url, 1); av_log(mux, AV_LOG_ERROR, "Output file does not contain any stream\n");