From patchwork Mon Apr 8 12:57:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 47918 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp2455903pzd; Mon, 8 Apr 2024 06:01:11 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXdD2eHapxopd7j7Fb9Nsrg7yNQoTgb2AKrGt2cW9zd5JZ60qAHuhzZOKZ9J84+ntcXvHbtvTb0Pky08viMWXC6+iSv+SSxBFogsA== X-Google-Smtp-Source: AGHT+IG66P/TfG6EaNItsu9PvDrRrdkSZ7U1eYuvUZd4l8J4prKKHBb0qqaUxUu1izmZdajh6VJy X-Received: by 2002:a19:5e51:0:b0:516:cec0:1fb8 with SMTP id z17-20020a195e51000000b00516cec01fb8mr7379433lfi.65.1712581270702; Mon, 08 Apr 2024 06:01:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712581270; cv=none; d=google.com; s=arc-20160816; b=iTs0hXuw85aespt3CMB1fmEADQ/kptUIH/NfgUit+y0/3hbnKD68dslRkiwKwnpTHy DCm6Rg5B8o9RAp9ucCdxCSQo03cc3tOhOiY2jvEvtoDsTVJk0ub9Rt4wGh7wXjF5Wnqe 53Z0X1kLtsufiU33qcjx2xCLaeNz6Ku0UkzxM3k1mXEgTPGzQXsxqRJwf61+7JOrwA6c Luob16KoXTY8NbpC8dYE7/1noZwFhn8+a56YGJ3P4Fb5Po5ES+QWobh2cHfsgQdoUShs PzfT7vWszPbEijB7kg0E60QVXNNM4rue7h0SyvZa7eqlbaxPEfV5qo1XKf+RxFrMF/a+ VXvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=f4Lw46rb3hPOjtnWx0diSshxBRf6ghXqGsIb49oo4Ug=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=jA65g199RxFabkK5uErYG8LhZe9qBkIhHEBgTPxaVeFdp9/zq1mB1OewymutV+fu/O T6tdvaiSPts07+ah09dYxnYIoHnI4IeYQLTRnp94Lb4bxanWSzdR3wbS1Wm3DDzMsJ8y NsZRHxEmOUeEflek4hAbBxB0fLnnLZ2aWK5/RfmY7oKfxwZKbtl7BrIPgkHddpgYgsAw ZOOlBXm8oPFmJr1gqWRL3glZerFZ/JqPDCMHrkD5cZsXomggPZz+YbbR3lt8WOo+OV6f wwYdQxeyh7Y9SrZDImxTvwyqpFvRrqIxz5e+/niAs3YsNW3A343M9k3JQhO7DI2BRY3g s6cw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=PEGLE4ZA; 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 rn21-20020a170906d93500b00a519e255f44si3634471ejb.57.2024.04.08.06.01.10; Mon, 08 Apr 2024 06:01:10 -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=@haasn.xyz header.s=mail header.b=PEGLE4ZA; 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 7BAE068D25F; Mon, 8 Apr 2024 16:00:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BDC1F68D1D2 for ; Mon, 8 Apr 2024 15:59:58 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1712581195; bh=ujFQFTZsF2BuepQbF17BRrK0c+8Y15OieQ7w0mp8T1A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PEGLE4ZAve4dwts7Oyl0wSDdyNc1fsZRecHB0ekrI/48+7ypPDJ0zqjjDP2mwJsHz LX7UeZulOxmnpLe03D29siJypdBoAMzDG9+kuyTz97ehb254gKF3XW9IUbC9xXf29h qOc1u/UyZo0Gxdj17Zo1FQhicWWuM7+VG4KNeAkI= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id A9823479E4; Mon, 8 Apr 2024 14:59:55 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 Apr 2024 14:57:19 +0200 Message-ID: <20240408125950.53472-16-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240408125950.53472-1-ffmpeg@haasn.xyz> References: <20240408125950.53472-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 15/17] fftools/ffmpeg_filter: switch to avcodec_get_supported_config() 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: /vgG3z6Ywcb7 From: Niklas Haas I preserved the no-op condition on `!ch_layouts`, even though I suspect it's not actually needed. --- fftools/ffmpeg_filter.c | 59 ++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 945147d6ca1..83259416a68 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -694,7 +694,7 @@ static int ifilter_bind_dec(InputFilterPriv *ifp, Decoder *dec) static int set_channel_layout(OutputFilterPriv *f, OutputStream *ost) { - const AVCodec *c = ost->enc_ctx->codec; + const AVChannelLayout *ch_layouts; int i, err; if (ost->enc_ctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) { @@ -705,8 +705,14 @@ static int set_channel_layout(OutputFilterPriv *f, OutputStream *ost) return 0; } + err = avcodec_get_supported_config(ost->enc_ctx, NULL, + AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0, + (const void **) &ch_layouts); + if (err < 0) + return err; + /* Requested layout is of order UNSPEC */ - if (!c->ch_layouts) { + if (!ch_layouts) { /* Use the default native layout for the requested amount of channels when the encoder doesn't have a list of supported layouts */ av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels); @@ -714,13 +720,13 @@ static int set_channel_layout(OutputFilterPriv *f, OutputStream *ost) } /* Encoder has a list of supported layouts. Pick the first layout in it with the same amount of channels as the requested layout */ - for (i = 0; c->ch_layouts[i].nb_channels; i++) { - if (c->ch_layouts[i].nb_channels == ost->enc_ctx->ch_layout.nb_channels) + for (i = 0; ch_layouts[i].nb_channels; i++) { + if (ch_layouts[i].nb_channels == ost->enc_ctx->ch_layout.nb_channels) break; } - if (c->ch_layouts[i].nb_channels) { + if (ch_layouts[i].nb_channels) { /* Use it if one is found */ - err = av_channel_layout_copy(&f->ch_layout, &c->ch_layouts[i]); + err = av_channel_layout_copy(&f->ch_layout, &ch_layouts[i]); if (err < 0) return err; return 0; @@ -762,7 +768,11 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) { ofp->format = ost->enc_ctx->pix_fmt; } else if (!ost->keep_pix_fmt) { - ofp->formats = c->pix_fmts; + ret = avcodec_get_supported_config(ost->enc_ctx, NULL, + AV_CODEC_CONFIG_PIX_FORMAT, 0, + (const void **) &ofp->formats); + if (ret < 0) + return ret; // MJPEG encoder exports a full list of supported pixel formats, // but the full-range ones are experimental-only. @@ -788,8 +798,16 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, ofp->fps.framerate = ost->frame_rate; ofp->fps.framerate_max = ost->max_frame_rate; - ofp->fps.framerate_supported = ost->force_fps ? - NULL : c->supported_framerates; + + if (ost->force_fps) { + ofp->fps.framerate_supported = NULL; + } else { + ret = avcodec_get_supported_config(ost->enc_ctx, NULL, + AV_CODEC_CONFIG_FRAME_RATE, 0, + (const void **) &ofp->fps.framerate_supported); + if (ret < 0) + return ret; + } // reduce frame rate for mpeg4 to be within the spec limits if (c->id == AV_CODEC_ID_MPEG4) @@ -802,19 +820,34 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) { ofp->format = ost->enc_ctx->sample_fmt; } else { - ofp->formats = c->sample_fmts; + ret = avcodec_get_supported_config(ost->enc_ctx, NULL, + AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, + (const void **) &ofp->formats); + if (ret < 0) + return ret; } if (ost->enc_ctx->sample_rate) { ofp->sample_rate = ost->enc_ctx->sample_rate; } else { - ofp->sample_rates = c->supported_samplerates; + ret = avcodec_get_supported_config(ost->enc_ctx, NULL, + AV_CODEC_CONFIG_SAMPLE_RATE, 0, + (const void **) &ofp->sample_rates); + if (ret < 0) + return ret; } if (ost->enc_ctx->ch_layout.nb_channels) { int ret = set_channel_layout(ofp, ost); if (ret < 0) return ret; - } else if (c->ch_layouts) { - ofp->ch_layouts = c->ch_layouts; + } else { + const AVChannelLayout *ch_layouts; + ret = avcodec_get_supported_config(ost->enc_ctx, NULL, + AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0, + (const void **) &ch_layouts); + if (ret < 0) + return ret; + if (ch_layouts) + ofp->ch_layouts = ch_layouts; } break; }