From patchwork Fri Apr 5 16:12:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 47840 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp1069949pzd; Fri, 5 Apr 2024 09:15:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVR4IrlgAwq57RpewAnfd6cnz8krzIOhWQo1bjAgkMYDX5R9WJd71fMOUt3yqGF/lA+wzDZkOCu8Il/jDuQ6tWudIAULzHPtXs9Aw== X-Google-Smtp-Source: AGHT+IEKNd6Klq9DJ8sR9u6j61+h0GHbQy43kqXB3w3r4YmM4+/iUQsI83XFMVwwHXTdf4dNGmNA X-Received: by 2002:a50:d69e:0:b0:56b:ff5d:8bdc with SMTP id r30-20020a50d69e000000b0056bff5d8bdcmr1130358edi.32.1712333700951; Fri, 05 Apr 2024 09:15:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712333700; cv=none; d=google.com; s=arc-20160816; b=eyPF3M6i3l+m2/OIku6BBeqGGm7AgmdTfuBy7zLLaWwd1BkzgkjTghYXId+G448R0w LdQ0z2qLiMnfa8a9hGTE0G6sILmTzz8YHzcPwU3WAYfqMs1wMrJ6f7+7ubWz+0FtV9mN t+C+6vF2sGIRNAikqHTDuXByJO3XvWCwiCuBpF3epnEbOha35dd/iCQ+k+ygG4OGGzrK Snm3n4Q2Xki88e0GNoPda2g8c/E9nZGjd7c1s5rzYxof+zaD+Sr4WhcWYMWCVoB6Q/1u 7RFqWNvvRBVu3mv1mxu5/ruphnoCE5n9z+kWAVX6ZzBATnQzeFsotWiH7LUrtXFkDTuY TmZA== 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=rjezfMw/UBFxqibrdz1ggG9MrODI7RHv5Fdh/zM5GqM=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=uhvLuFkyy0bCmcyNrCtzLmc+HwoevJEroqb1f0IIOfI+LtoHKuSfxSc4gTcPEgs5Wc xl5UhJRTdkuQQdJJCgO2LGuxzIA0KPLMaqxNtr/DAdxMx74gwup1GYAaazrVxq1s+zMn DclFEwqjFAnTg11iWqDNqA0Z+/gIU7ETHeDUF1vKZNM09MtYJ606GftVqUJvAqBLYvBt 3uXtbAmQH2B3TaH9UDZTjrJfvhpahUAZ6OfncPjCFISNNbOPJHkWulj7687ukp7NJOhF /puy/crd0W01JoCslPdGS+v9ZovlKxcStnuYxk7N5WQOSKyHlO28XFd6HMrm9J3SF11k Nw9w==; 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=sAWCcBG4; 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 15-20020a508e4f000000b0056e332f32casi573994edx.540.2024.04.05.09.15.00; Fri, 05 Apr 2024 09:15:00 -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=sAWCcBG4; 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 F3E9568D244; Fri, 5 Apr 2024 19:13:21 +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 449E868D180 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=sAWCcBG4; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 91D984D7E for ; Fri, 5 Apr 2024 18:13:06 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id MEtQqlbE8LZ9 for ; Fri, 5 Apr 2024 18:13:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1712333582; bh=NEFyaZ7QXM3Wh3WLYsD/jGgvrCsPNFwsTdxpiWrXtJ4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sAWCcBG4hk7jan5OFdezAG7SLj+wb2tA0eF22toV4LfO/fF66px0dV4yi4aEpQL4r OW01acTPXPitFFnhakwkMk23otdPdugwQrJ0xmfyS1XV5oFPflazy5Btq2ulnxDKic 3Bsf33seuds9HFj/0wEh5fX0ELcguUmCjRl1GrHZR6Dftlz3obrHnnDGcgL8oLOSIT ghcO/2CV9oXheDV1j/92etrrhy+bY0z+zYOVC600vPWjbmArFirZg8t/W/xGoui6ZF YZTFPyXLGKiPrXBoBOvVWbFJrtm5yByvvWQkRcRbVL2Qdu9TJiVysNdStv0CDVEqen CIPp96yRYzUsg== 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 C95524D91 for ; Fri, 5 Apr 2024 18:13:02 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 52B953A159F 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:00 +0200 Message-ID: <20240405161212.26167-19-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 19/31] fftools/ffmpeg_filter: pass sws/swr opts through OutputFilterOptions 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: 4ZPK5a1W5sry Do not read them from OutputStream directly. Will allow decoupling filtering from encoding in future commits. --- fftools/ffmpeg.h | 7 +++++-- fftools/ffmpeg_filter.c | 27 ++++++++++++++++++++++----- fftools/ffmpeg_mux.c | 3 --- fftools/ffmpeg_mux_init.c | 11 ++++------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 786f925bc6..c61a670103 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -265,6 +265,8 @@ typedef struct InputFilterOptions { enum OFilterFlags { OFILTER_FLAG_DISABLE_CONVERT = (1 << 0), + // produce 24-bit audio + OFILTER_FLAG_AUDIO_24BIT = (1 << 1), }; typedef struct OutputFilterOptions { @@ -283,6 +285,9 @@ typedef struct OutputFilterOptions { */ AVRational output_tb; + AVDictionary *sws_opts; + AVDictionary *swr_opts; + // A combination of OFilterFlags. unsigned flags; @@ -574,8 +579,6 @@ typedef struct OutputStream { OutputFilter *filter; AVDictionary *encoder_opts; - AVDictionary *sws_dict; - AVDictionary *swr_opts; char *apad; char *attachment_filename; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index d2fd26af7e..8aa4053716 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -210,6 +210,9 @@ typedef struct OutputFilterPriv { AVRational sample_aspect_ratio; + AVDictionary *sws_opts; + AVDictionary *swr_opts; + // those are only set if no format is specified and the encoder gives us multiple options // They point directly to the relevant lists of the encoder. const int *formats; @@ -813,6 +816,17 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, if (!ofp->name) return AVERROR(EINVAL); + ret = av_dict_copy(&ofp->sws_opts, opts->sws_opts, 0); + if (ret < 0) + return ret; + + ret = av_dict_copy(&ofp->swr_opts, opts->swr_opts, 0); + if (ret < 0) + return ret; + + if (opts->flags & OFILTER_FLAG_AUDIO_24BIT) + av_dict_set(&ofp->swr_opts, "output_sample_bits", "24", 0); + if (fgp->is_simple) { // for simple filtergraph there is just one output, // so use only graph-level information for logging @@ -945,6 +959,8 @@ void fg_free(FilterGraph **pfg) OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); av_frame_free(&ofp->fps.last_frame); + av_dict_free(&ofp->sws_opts); + av_dict_free(&ofp->swr_opts); av_freep(&ofilter->linklabel); av_freep(&ofilter->name); @@ -1358,7 +1374,7 @@ static int configure_output_video_filter(FilterGraph *fg, AVFilterGraph *graph, snprintf(args, sizeof(args), "%d:%d", ofp->width, ofp->height); - while ((e = av_dict_iterate(ost->sws_dict, e))) { + while ((e = av_dict_iterate(ofp->sws_opts, e))) { av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value); } @@ -1725,6 +1741,7 @@ static int configure_filtergraph(FilterGraph *fg, FilterGraphThread *fgt) return AVERROR(ENOMEM); if (simple) { + OutputFilterPriv *ofp = ofp_from_ofilter(fg->outputs[0]); OutputStream *ost = fg->outputs[0]->ost; if (filter_nbthreads) { @@ -1738,17 +1755,17 @@ static int configure_filtergraph(FilterGraph *fg, FilterGraphThread *fgt) av_opt_set(fgt->graph, "threads", e->value, 0); } - if (av_dict_count(ost->sws_dict)) { - ret = av_dict_get_string(ost->sws_dict, + if (av_dict_count(ofp->sws_opts)) { + ret = av_dict_get_string(ofp->sws_opts, &fgt->graph->scale_sws_opts, '=', ':'); if (ret < 0) goto fail; } - if (av_dict_count(ost->swr_opts)) { + if (av_dict_count(ofp->swr_opts)) { char *args; - ret = av_dict_get_string(ost->swr_opts, &args, '=', ':'); + ret = av_dict_get_string(ofp->swr_opts, &args, '=', ':'); if (ret < 0) goto fail; av_opt_set(fgt->graph, "aresample_swr_opts", args, 0); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 253c2e58d4..557f08b3a5 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -819,9 +819,6 @@ static void ost_free(OutputStream **post) av_freep(&ost->attachment_filename); - av_dict_free(&ost->sws_dict); - av_dict_free(&ost->swr_opts); - if (ost->enc_ctx) av_freep(&ost->enc_ctx->stats_in); avcodec_free_context(&ost->enc_ctx); diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 219be5f965..8f4b73f8a7 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1356,12 +1356,6 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx) ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0); - - av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0); - if (ost->enc_ctx && av_get_exact_bits_per_sample(ost->enc_ctx->codec_id) == 24) - av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0); - MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ms->copy_initial_nonkeyframes, oc, st); @@ -1392,10 +1386,13 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, .vsync_method = vsync_method, .sample_rate = ost->enc_ctx->sample_rate, .ch_layout = ost->enc_ctx->ch_layout, + .sws_opts = o->g->sws_dict, + .swr_opts = o->g->swr_opts, .output_tb = enc_tb, .ts_offset = mux->of.start_time == AV_NOPTS_VALUE ? 0 : mux->of.start_time, - .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt, + .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt | + OFILTER_FLAG_AUDIO_24BIT * !!(av_get_exact_bits_per_sample(ost->enc_ctx->codec_id) == 24), }; snprintf(name, sizeof(name), "#%d:%d", mux->of.index, ost->index);