From patchwork Sat Jul 23 14:09:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36919 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp1047943pzb; Sat, 23 Jul 2022 07:13:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t4l6VYH4iYwWBW5UH0yvzPQOZGw3ri8sT+AldsDOV+tsnYOQ6Xo2vW1tbwgH98WxAJn/sA X-Received: by 2002:a05:6402:4507:b0:43b:b8df:571d with SMTP id ez7-20020a056402450700b0043bb8df571dmr4585553edb.230.1658585601486; Sat, 23 Jul 2022 07:13:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658585601; cv=none; d=google.com; s=arc-20160816; b=EtfrpZ1ZW1/kdlDfIAbsfwrsPJcpM9JIPJdxKHqVHZdai8VGYw6jNL5oU/ocVXmYrn AIURMXQ9l6FNz7ScrhP9PDdYqN73jRG0etzIcNsjxzfdGgkFW179RcfHsZppXuxp5EMy PaQXb8wSdSdlddPmwY0PjhWNsb3bVfgrY4+sUBXob570ZOMJMVruy5iAWx5x/EsGXKRd 4p2f5C14oCyww2USZpn8EDlJz0Z+qe03ka1B1k9bhtX5LrW7DGZQm5whhT8fLWsqZvsv ZapT8m1ImzqkQ47+wjeTZRJa5paUENYjr94shTB0l+w3IiVTmiRDWdqMhXf4xZZJSsHq f8Sg== 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:delivered-to; bh=q8Ns7lh2ML8m4m2mcZNcEmHTbOn2085rKpYlgNbEu+Y=; b=Wd9f5RgNNg3vPIkf9RA/7LMr4vqrbIdHmAtLibOK3JU2hGGqesFToEQ+ewtSKGBMR/ 62Z+PtdrmPBpXcJueQFQYDGIFZHAFjjl8pqdPSNfuUpDyieZlSP8HhJE3TOw0b51zLjx Pp97LDW1ViFwTpmd4cl0cIHb8Ilask+9CtvuyhlLi6za5nQqD9eIUbp0dwAbjydWIyoB lZV0iGmzc8ENWRABfTJM/wYwoesAKnpujP+GX90ZT/SwevLEae2MD35V68zmaaY0ziWX 80N3GCaPxMubBHFIQGP6emqwKX02vLNDEE4UsOCg4Hxb7rNUE0ZmBA3kPPO0BxVnoj2P wr9w== ARC-Authentication-Results: i=1; mx.google.com; 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 g6-20020a1709065d0600b00704dc5420adsi10121631ejt.38.2022.07.23.07.13.21; Sat, 23 Jul 2022 07:13:21 -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; 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 D836F68B8D6; Sat, 23 Jul 2022 17:10:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 60C4968B777 for ; Sat, 23 Jul 2022 17:10:26 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 405A9240506 for ; Sat, 23 Jul 2022 16:10:22 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id NoTGCU8Ex65A for ; Sat, 23 Jul 2022 16:10:21 +0200 (CEST) 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 mail0.khirnov.net (Postfix) with ESMTPS id 73805240507 for ; Sat, 23 Jul 2022 16:10:19 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 7157C3A0449; Sat, 23 Jul 2022 16:10:19 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 23 Jul 2022 16:09:33 +0200 Message-Id: <20220723140952.31814-8-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220723140952.31814-1-anton@khirnov.net> References: <20220723140952.31814-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/27] fftools/ffmpeg: do not use the encoder context for streamcopy 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: nZ9ejLc2/gJf The streamcopy initialization code briefly needs an AVCodecContext to apply AVOptions to. Allocate a temporary codec context, do not use the encoding one. --- fftools/ffmpeg.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index cad9f1e885..0e30f8ce01 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2757,22 +2757,29 @@ static int init_output_stream_streamcopy(OutputStream *ost) OutputFile *of = output_files[ost->file_index]; InputStream *ist = get_input_stream(ost); AVCodecParameters *par = ost->st->codecpar; + AVCodecContext *codec_ctx; AVRational sar; int i, ret; uint32_t codec_tag = par->codec_tag; av_assert0(ist && !ost->filter); - ret = avcodec_parameters_to_context(ost->enc_ctx, ist->st->codecpar); + codec_ctx = avcodec_alloc_context3(NULL); + if (!codec_ctx) + return AVERROR(ENOMEM); + + ret = avcodec_parameters_to_context(codec_ctx, ist->st->codecpar); if (ret >= 0) - ret = av_opt_set_dict(ost->enc_ctx, &ost->encoder_opts); + ret = av_opt_set_dict(codec_ctx, &ost->encoder_opts); if (ret < 0) { av_log(NULL, AV_LOG_FATAL, "Error setting up codec context options.\n"); + avcodec_free_context(&codec_ctx); return ret; } - ret = avcodec_parameters_from_context(par, ost->enc_ctx); + ret = avcodec_parameters_from_context(par, codec_ctx); + avcodec_free_context(&codec_ctx); if (ret < 0) { av_log(NULL, AV_LOG_FATAL, "Error getting reference codec parameters.\n");