From patchwork Fri Apr 5 18:57:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 47870 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp1158134pzd; Fri, 5 Apr 2024 11:59:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUKGzKwYv1O0mKaN0UU9qIX7ZNXU0V5NvegIVIsBjYNcrzw18V4NppsDC5nHe261W6A/xgoun/MAAu9/QRWJuUx+Jl6rIlVId6ENg== X-Google-Smtp-Source: AGHT+IENBJDVtiR7kp78YKXYoYkTikZofkHtn6oDjqlANmYtRluZt/pSjxRzqlWN/zd3bIIHhM0o X-Received: by 2002:a17:906:3941:b0:a51:99ec:7062 with SMTP id g1-20020a170906394100b00a5199ec7062mr1595315eje.66.1712343543757; Fri, 05 Apr 2024 11:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712343543; cv=none; d=google.com; s=arc-20160816; b=kTNYRQvEq8WTKLODovk2hzlLTQyW6GHXVg4wifaMgC0PZqfw/nBVXDwOnzGpmk0boF tIXQhbsG2A29UT5Z+P1w9nTo2AdUeCa/JDB9hPZ7RivCYi8YGQ1NTpUD4Cwtl3xQIsn9 T1LeMkM5SrjZCMczUTVntCm2srICL4HBlguvCKqsJxMeM5OjXIQF4fPr6T4wr9DcF3hv h/5YH39T6+eDainPBh9zLJhNZjJNiFHOBaTaO+237tTu3/f9eD0XdFKQr98atMHh+075 maO46JRCpuXXMRbiJufudKfhdIWrNlc+IJGJzA0AnnvBlBRwbkNRcfxW1fQpyoH0qVXI iZFA== 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=mvSXo3Ys566MteFqoio2tNpzSOelN1HMpt1GLiP1WYI=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=Tqw9AVQxpiToorss0kX5e4AGaLHo9Cr74RwAhgaxlnfA6zX+nGNjfbE2yYKkfNIfll hFGULBk8H5X17Qy0WL4afdPHW21hdVx/b2qT1eQu++RKzHqv8t8Sj9qPrs9lQNizG0oX 1qLdzVKavNEG+O5nXXj/FxX6My9dkVBG09UNMJoPEFd5Q7Q8Cevr0DbNparYnps/CLVO HgRV+VQ3vUGCV+pUPHCjA4YoHkackWfrT/sw9kkn1HQ7VdjqqTrrVaETmB6G1MkT/JSg kJZlc8canPAN0UJruBsjNMldNK80SKXOjOLyw2Gn4+KSA/NdERGtArsUmaokPQ3AuNZ+ aUSQ==; 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=IMP7TZkv; 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 x25-20020a170906135900b00a5198910903si939059ejb.70.2024.04.05.11.59.03; Fri, 05 Apr 2024 11:59:03 -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=IMP7TZkv; 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 B138568D21C; Fri, 5 Apr 2024 21:57:43 +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 C24FF68D1BE for ; Fri, 5 Apr 2024 21:57:31 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1712343448; bh=dgJQEa04pg2CvYhLE0BQRCInKpO4jyjM4IV61Tcck84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IMP7TZkvcoicYbzjehMy79jOIGfDFPPglRQGMZAspAT4VaLBWO3C9edp0tAEiJgJF 3ghe2Ta9eA4I/SeMOB09ZAbrF2IkZW7pqPO3VmbK17859XSBrG88UziSjb54JFFO2f dcrtXWjubNQuJhrcvwXwIW5PRxYh/eCecvuiDvKs= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 159F7444D6; Fri, 5 Apr 2024 20:57:28 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Apr 2024 20:57:21 +0200 Message-ID: <20240405185721.111072-11-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405185721.111072-1-ffmpeg@haasn.xyz> References: <20240405185721.111072-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/11] 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: 2Wn5hUq4tUUm 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 ac04841a16c..e617b9da289 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -724,7 +724,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) { @@ -735,8 +735,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); @@ -744,13 +750,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; @@ -787,7 +793,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 { - 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. @@ -822,8 +832,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) @@ -836,19 +854,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; }