From patchwork Wed Sep 25 13:29:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51853 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:9548:0:b0:48e:c0f8:d0de with SMTP id t8csp759140vqk; Wed, 25 Sep 2024 14:49:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXi3otwxacFZA1q1IQam4jFrtEVXC21xZzHvYx7y9M2v6GkGLogFwGh8CUhEEidaKDU5x8oVBEjDOmSSaDwcv3e@gmail.com X-Google-Smtp-Source: AGHT+IENGZ3y7KL1rLPppqP478qi9vH3LHc3DQTrRok298X4wDeOWEktTg8mRMCpDCGTedtwj35A X-Received: by 2002:a2e:a992:0:b0:2ef:2855:533f with SMTP id 38308e7fff4ca-2f916005447mr22019131fa.16.1727300958298; Wed, 25 Sep 2024 14:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727300958; cv=none; d=google.com; s=arc-20240605; b=bJf9rsiOUE5fsmJq0Y2pp3ZlN3AICtP9OcOu3sIALR2zMN/P5DAp/Kw9foUOIzBnHB zA0MNoyWquP0P+f+CqYMDOAEaY1C0GgvVtkc6/4+cpHozEVVznK0VBHklsEMzViLJ6w7 rWMFYiFt7cmGHjEi5la62kA8tqvMlnbJsVDDNB1QpNhUopPOXwRIiOLZMvtvsKIG3Ow1 qpyttuWlwq8C5FybWgl6GbwGhZ6zuitK/1toCpHNX98MW75MwljddcJpzdheSvx7u+AJ kwSw+e9kiT4XRjjXh8MMLrJxgH/hD+9CfWW49P8JAK86zNdDySF1G22osJlDjC2b8Wif 83rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=M0jSJDyLXY0TvFriwaOaOSNkwC+W00eyBCIJVBjshVM=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=e7cHWpVT9wP1HLtDQ/q+3fPgUebc3QXbcqEKFmLuqJbLih3ByrB3opHvRVG3X5tTJv Vc5x67eDvVQfttxaBwe2o0j1N4mKpCpPS8+aiCw5AUbnLQmvzSbAJ1J6RgSykXo3EF2M yLOdhhJeOfe6kLYswfg1GWQn4yGw4hqTzzTxGiPgLO+u5Rwasl/H9SZgsgiUr95EQuZT rtxdchMRwRzr0zp+tr5DRY1bSSaMyaY2C3N5+zULKHGpVzBIXN41R5Adyp3MqLYvdLfc AqU18kSG0OfEgnYqVKffiPZ/eoVyZPgOifViiFgOkBtkw0aLrYcBYCguBwGnZKay+9DR pPZw==; 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=nCLgLpoH; 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 38308e7fff4ca-2f8d282f73esi13827461fa.20.2024.09.25.14.49.17; Wed, 25 Sep 2024 14:49:18 -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=nCLgLpoH; 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 6C31168DBD4; Wed, 25 Sep 2024 16:29:37 +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 DA30868DA56 for ; Wed, 25 Sep 2024 16:29:26 +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=nCLgLpoH; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id C38194E1A for ; Wed, 25 Sep 2024 15:29:25 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 8ZUsdgR_JDq1 for ; Wed, 25 Sep 2024 15:29:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727270964; bh=euO8MMDzVh6a6SxJ68gHngMQXtoO6jdpziyItQZh6sc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nCLgLpoHfQ91zZj8JBY5UhKlQPem4gV/Ctep36PVZyXgecYMofopPi9kO5IXIAaqQ Koc93g2EWrC/jDWZp5MfXpKH2rOsI/vgio2HJe7KJNvk88maoZGH0lrWL4lZAnAxTC xbXt0vDe0oWPdEdy5GBPYiSSWyHom71H6tDCupBgNOW/FHZxCHo0F0xIYD7oTQCndb HRubB8lnNVj22XnKFJb5oTrYqb1Xf+AjfY5cdlMRyrIKKBJHsCbswcomaUHpzvBOWx pf4fQnoQQSsByTFztCsJWt+1GuRgE+zLvStFuDhfAUMtP8OeKHQN61zAouhs3lS4R8 JZETONYIWLpBQ== 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 CBF224E0F for ; Wed, 25 Sep 2024 15:29:24 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B5DD83A0F41 for ; Wed, 25 Sep 2024 15:29:24 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 25 Sep 2024 15:29:16 +0200 Message-ID: <20240925132921.11203-5-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240925132921.11203-1-anton@khirnov.net> References: <20240925132921.11203-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/10] doc/examples/transcode: 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: M0DRX5JSYf3d --- doc/examples/transcode.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c index 7d1e1826a3..54fb315236 100644 --- a/doc/examples/transcode.c +++ b/doc/examples/transcode.c @@ -171,23 +171,38 @@ static int open_output_file(const char *filename) * sample rate etc.). These properties can be changed for output * streams easily using filters */ if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) { + const enum AVPixelFormat *pix_fmts = NULL; + enc_ctx->height = dec_ctx->height; enc_ctx->width = dec_ctx->width; enc_ctx->sample_aspect_ratio = dec_ctx->sample_aspect_ratio; + + ret = avcodec_get_supported_config(dec_ctx, NULL, + AV_CODEC_CONFIG_PIX_FORMAT, 0, + (const void**)&pix_fmts, NULL); + /* take first format from list of supported formats */ - if (encoder->pix_fmts) - enc_ctx->pix_fmt = encoder->pix_fmts[0]; - else - enc_ctx->pix_fmt = dec_ctx->pix_fmt; + enc_ctx->pix_fmt = (ret >= 0 && pix_fmts) ? + pix_fmts[0] : dec_ctx->pix_fmt; + /* video time_base can be set to whatever is handy and supported by encoder */ enc_ctx->time_base = av_inv_q(dec_ctx->framerate); } else { + const enum AVSampleFormat *sample_fmts = NULL; + enc_ctx->sample_rate = dec_ctx->sample_rate; ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout); if (ret < 0) return ret; + + ret = avcodec_get_supported_config(dec_ctx, NULL, + AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, + (const void**)&sample_fmts, NULL); + /* take first format from list of supported formats */ - enc_ctx->sample_fmt = encoder->sample_fmts[0]; + enc_ctx->sample_fmt = (ret >= 0 && sample_fmts) ? + sample_fmts[0] : dec_ctx->sample_fmt; + enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate}; }