From patchwork Sat Mar 25 19:15:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 40835 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp226288pzh; Sat, 25 Mar 2023 12:18:34 -0700 (PDT) X-Google-Smtp-Source: AKy350ZzFSt39ZhDM0H2Xg5B+0/VGlXUKjOrCicXmNhJIHs88s10vlummUkUeuBCQzMdAxX8bOr0 X-Received: by 2002:a05:6402:1012:b0:4fb:7ccf:3b33 with SMTP id c18-20020a056402101200b004fb7ccf3b33mr6813814edu.31.1679771914694; Sat, 25 Mar 2023 12:18:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679771914; cv=none; d=google.com; s=arc-20160816; b=KQ/tqaahvEOMkugy9GN8JqDVsBxhf90J8/Ofl7U+9n7EFvPD/VdK5kdgZ3Co9TWLWG jg3AeIa5YqoQBJfu2Npxkm7xieH2umLSWUgHs5XigZf+uUyegp9DEFaKZ0DUs61O+ZUV CS9DOcKen0ogm5P1Cl/SfFIaFPhDgkw3ZJRhAHLCt3GbALh3OVy9/mMOYZ3zP339r4ya d49m+ct/kuMZk2aWbHdGw3THhlsbpMkARqzqfE4Csf4O3lVeJpG8CiW5kKuEFK2vkClr eH5ehMBktXI9guq+UxVhfnPGNTdSqqwXBN5z/+bXCt+yl1Qe4LTzqX1WdiN042JYqxIU fBTw== 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=796wIF7vnCnna3dlv+IYrEC+mcUzqB4mD6tBQ6how6E=; b=QOzjH7Tjg8Ac5REwc6ZpFppUQnnCVq3tkSXNuRpfJPX+0HCbsF7kkR5znkqWmJfSYx b2c+i4dSWp5oexcNFvujtcJJgoI5RYNQ3RqfKT1mJT7O5Gn9pHGSdLNQOUYwFULddJ3g wrO1D5DvTC4q2rx5j2y9yZLSeMkolmrJ0iBs8EoK+WLB3W0oGagUkDLcU8mQYPS/JSD/ S9N55FukBIDLwjMYwP2xxeDrZulH9qKUa+ST9Fc/UFoeNCvMfGund8V21PmdtBrWcPnD T5ezVVYnDkxMQFIVvU2QSbgoK3ri6EIp84u4+yC84a0CsZtLnQMvMFryBlaY1Lbrr9Wf 6q2A== 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 f9-20020a50ee89000000b004ced100b0b7si10330816edr.316.2023.03.25.12.18.34; Sat, 25 Mar 2023 12:18:34 -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 90FA468CA26; Sat, 25 Mar 2023 21:16:25 +0200 (EET) 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 B566C68C9AB for ; Sat, 25 Mar 2023 21:16:07 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E416D2405EC for ; Sat, 25 Mar 2023 20:16:03 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id b9dbTvlvVkL3 for ; Sat, 25 Mar 2023 20:16:03 +0100 (CET) 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 062202405F9 for ; Sat, 25 Mar 2023 20:16:01 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D72A03A0664 for ; Sat, 25 Mar 2023 20:15:54 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 25 Mar 2023 20:15:18 +0100 Message-Id: <20230325191529.10578-12-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230325191529.10578-1-anton@khirnov.net> References: <20230325191529.10578-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/23] fftools/ffmpeg: move encoder initialization to init_output_stream_encode 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: nSVFxSeC/EfT Encoder initialization is currently split rather arbitrarily between init_output_stream_encode() and init_output_stream(). Move all of it to init_output_stream_encode(). --- fftools/ffmpeg.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 7b7db03bde..9ae3d3891f 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3179,27 +3179,10 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) if (ost->bitexact) enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT; - ost->mux_timebase = enc_ctx->time_base; - - return 0; -} - -static int init_output_stream(OutputStream *ost, AVFrame *frame) -{ - int ret = 0; - - if (ost->enc_ctx) { - const AVCodec *codec = ost->enc_ctx->codec; - InputStream *ist = ost->ist; - - ret = init_output_stream_encode(ost, frame); - if (ret < 0) - return ret; - if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0)) av_dict_set(&ost->encoder_opts, "threads", "auto", 0); - if (codec->capabilities & AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE) { + if (enc->capabilities & AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE) { ret = av_dict_set(&ost->encoder_opts, "flags", "+copy_opaque", AV_DICT_MULTIKEY); if (ret < 0) return ret; @@ -3212,9 +3195,9 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame) return ret; } - if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) { + if ((ret = avcodec_open2(ost->enc_ctx, enc, &ost->encoder_opts)) < 0) { if (ret == AVERROR_EXPERIMENTAL) - abort_codec_experimental(codec, 1); + abort_codec_experimental(enc, 1); av_log(ost, AV_LOG_ERROR, "Error while opening encoder - maybe " "incorrect parameters such as bit_rate, rate, width or height.\n"); return ret; @@ -3282,6 +3265,20 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame) // copy estimated duration as a hint to the muxer if (ost->st->duration <= 0 && ist && ist->st->duration > 0) ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); + + ost->mux_timebase = enc_ctx->time_base; + + return 0; +} + +static int init_output_stream(OutputStream *ost, AVFrame *frame) +{ + int ret = 0; + + if (ost->enc_ctx) { + ret = init_output_stream_encode(ost, frame); + if (ret < 0) + return ret; } else if (ost->ist) { ret = init_output_stream_streamcopy(ost); if (ret < 0)