From patchwork Sat Jul 23 14:09:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36932 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a9d:f07:0:b0:61c:acf1:bf6b with SMTP id 7csp644810ott; Sat, 23 Jul 2022 07:14:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1srfTpIBbgmd5DeVBCfNsYEiQwc+0OdtBCGrUUVfUtvK+si4h4v0kYPO/uOL2413VlV1ma1 X-Received: by 2002:a05:6402:3282:b0:43b:e650:4352 with SMTP id f2-20020a056402328200b0043be6504352mr159880eda.376.1658585653372; Sat, 23 Jul 2022 07:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658585653; cv=none; d=google.com; s=arc-20160816; b=feiK/hCgGX4SfxogGA8fPvn89FT8s8G3ged+wHHnw3m0DJiK9DGVrWgAiTt92HuIBW jgveZYA3JkPS7hkDRhCXfpzotk/LDhPKrIsR++ZD8qI3UJQb+FqfWASHonj0yqYWBfKj SoK+UK7aZYg0CXr67fZ419gkj2BXp87rtpEQdi4yiZUf75T5hcqhFe3W0LWRh74eq6yO OXRr1Uj+Y3FU+T10pRyrQrCgcKCRzPTkNu3qWdagGXwdBD+d41JBXhjV8C71FO4wRbvo D+70ACwZGlYQIthVptFIuNXbzFUu+aQNsigD3IMA2DLUJ3XRRX/guPHP9IBOXvC1MC4o HiJA== 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=UDZiskUzNUnLR6nvW77zkb7KQCVn33F/KmPuCCL7oIc=; b=mtei2K8m4SujEVmEf/p6RuCrO16gGbcmVS7bmlwe0igEsHPw6cIPF4smRqgO5GhJHS vsSIPvcwVwiBaO5q1mSoYq8rbBMFIyvMEn4dxQc2FyujqHyK3w2v3YWzOf5P7Lv2Ae+T FXisn8gGv8snthJuW95CdPUn0qeVBY117ET9CK9FTVwubQIEV1OMDek16yjrPF8vRuLN ev5qxSPNcO5lsv8X/UjnvYopZ8KQgl8LLUVWYLize/mvHKO1QX0ddwnslpV7zeQBE0oG aOnYDPftB0yGzGLG2t+YjjF1CXZ5XNiQVTfbpwERNppMwHZjAX4WnK0UZrYMneItA0Fy Coiw== 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 e18-20020a17090658d200b0072f1dffedcfsi11216971ejs.588.2022.07.23.07.14.10; Sat, 23 Jul 2022 07:14:13 -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 49ED468B900; Sat, 23 Jul 2022 17:10:51 +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 8EC8168B7C9 for ; Sat, 23 Jul 2022 17:10:27 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 08C51240512 for ; Sat, 23 Jul 2022 16:10:24 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ok0-NzkEl_g0 for ; Sat, 23 Jul 2022 16:10:23 +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 9A39024055A for ; Sat, 23 Jul 2022 16:10:19 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 6CC1C3A0404; Sat, 23 Jul 2022 16:10:19 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 23 Jul 2022 16:09:32 +0200 Message-Id: <20220723140952.31814-7-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 07/27] fftools/ffmpeg: drop OutputStream.ref_par 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: Qyi23h2ygXrF Content-Length: 5525 It serves no purpose, codec parameters can be written directly to AVStream.codecpar with the same effect. --- fftools/ffmpeg.c | 37 ++++++++++++++++--------------------- fftools/ffmpeg.h | 1 - fftools/ffmpeg_opt.c | 6 ------ 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 1780e535ae..cad9f1e885 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -587,7 +587,6 @@ static void ffmpeg_cleanup(int ret) if (ost->enc_ctx) av_freep(&ost->enc_ctx->stats_in); avcodec_free_context(&ost->enc_ctx); - avcodec_parameters_free(&ost->ref_par); av_freep(&output_streams[i]); } @@ -2757,11 +2756,10 @@ static int init_output_stream_streamcopy(OutputStream *ost) { OutputFile *of = output_files[ost->file_index]; InputStream *ist = get_input_stream(ost); - AVCodecParameters *par_dst = ost->st->codecpar; - AVCodecParameters *par_src = ost->ref_par; + AVCodecParameters *par = ost->st->codecpar; AVRational sar; int i, ret; - uint32_t codec_tag = par_dst->codec_tag; + uint32_t codec_tag = par->codec_tag; av_assert0(ist && !ost->filter); @@ -2774,7 +2772,7 @@ static int init_output_stream_streamcopy(OutputStream *ost) return ret; } - ret = avcodec_parameters_from_context(par_src, ost->enc_ctx); + ret = avcodec_parameters_from_context(par, ost->enc_ctx); if (ret < 0) { av_log(NULL, AV_LOG_FATAL, "Error getting reference codec parameters.\n"); @@ -2784,16 +2782,12 @@ static int init_output_stream_streamcopy(OutputStream *ost) if (!codec_tag) { unsigned int codec_tag_tmp; if (!of->format->codec_tag || - av_codec_get_id (of->format->codec_tag, par_src->codec_tag) == par_src->codec_id || - !av_codec_get_tag2(of->format->codec_tag, par_src->codec_id, &codec_tag_tmp)) - codec_tag = par_src->codec_tag; + av_codec_get_id (of->format->codec_tag, par->codec_tag) == par->codec_id || + !av_codec_get_tag2(of->format->codec_tag, par->codec_id, &codec_tag_tmp)) + codec_tag = par->codec_tag; } - ret = avcodec_parameters_copy(par_dst, par_src); - if (ret < 0) - return ret; - - par_dst->codec_tag = codec_tag; + par->codec_tag = codec_tag; if (!ost->frame_rate.num) ost->frame_rate = ist->framerate; @@ -2838,26 +2832,27 @@ static int init_output_stream_streamcopy(OutputStream *ost) av_display_rotation_set((int32_t *)sd, -ost->rotate_override_value); } - switch (par_dst->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: - if((par_dst->block_align == 1 || par_dst->block_align == 1152 || par_dst->block_align == 576) && par_dst->codec_id == AV_CODEC_ID_MP3) - par_dst->block_align= 0; - if(par_dst->codec_id == AV_CODEC_ID_AC3) - par_dst->block_align= 0; + if ((par->block_align == 1 || par->block_align == 1152 || par->block_align == 576) && + par->codec_id == AV_CODEC_ID_MP3) + par->block_align = 0; + if (par->codec_id == AV_CODEC_ID_AC3) + par->block_align = 0; break; case AVMEDIA_TYPE_VIDEO: if (ost->frame_aspect_ratio.num) { // overridden by the -aspect cli option sar = av_mul_q(ost->frame_aspect_ratio, - (AVRational){ par_dst->height, par_dst->width }); + (AVRational){ par->height, par->width }); av_log(NULL, AV_LOG_WARNING, "Overriding aspect ratio " "with stream copy may produce invalid files\n"); } else if (ist->st->sample_aspect_ratio.num) sar = ist->st->sample_aspect_ratio; else - sar = par_src->sample_aspect_ratio; - ost->st->sample_aspect_ratio = par_dst->sample_aspect_ratio = sar; + sar = par->sample_aspect_ratio; + ost->st->sample_aspect_ratio = par->sample_aspect_ratio = sar; ost->st->avg_frame_rate = ist->st->avg_frame_rate; ost->st->r_frame_rate = ist->st->r_frame_rate; break; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 0c9498c23e..59c2f47a66 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -481,7 +481,6 @@ typedef struct OutputStream { AVBSFContext *bsf_ctx; AVCodecContext *enc_ctx; - AVCodecParameters *ref_par; /* associated input codec parameters with encoders options applied */ const AVCodec *enc; int64_t max_frames; AVFrame *filtered_frame; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 81754f7d91..32e0d9a7ff 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1573,12 +1573,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e } ost->enc_ctx->codec_type = type; - ost->ref_par = avcodec_parameters_alloc(); - if (!ost->ref_par) { - av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding parameters.\n"); - exit_program(1); - } - ost->filtered_frame = av_frame_alloc(); if (!ost->filtered_frame) exit_program(1);