From patchwork Sat Jul 23 14:09:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36901 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp1046534pzb; Sat, 23 Jul 2022 07:10:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vEueyFyC+PAg8WBN04p5a4sFwlug/+hLHDfe5uU68kESTfkQVyiK9O/GjDriQHoVcCA5YU X-Received: by 2002:aa7:ce02:0:b0:43b:c381:5e19 with SMTP id d2-20020aa7ce02000000b0043bc3815e19mr4499590edv.295.1658585440792; Sat, 23 Jul 2022 07:10:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658585440; cv=none; d=google.com; s=arc-20160816; b=E6g2dcKQtLftvBrKM2sbv1PBFcH38xm88Te8sGVxCn3eYLL6340FYjGmPqcDVeucIx IYKMsLpMdQVSuK7np1BrYbdMXpeP8W7aOtoF2Y2oEWx1fC6yOpjvZjde9hYy3YShT5ft 3KqyQEDmoWq8Qt1JaWNOLA8hU5dMjDt06ql88qOsMc3nVTdemmiipobObbHeYMp157mk /VF+bRC1O1sN3DKPSLVZIjKLvy6DCPJIAMk0c4J3IK6mthKtr2AfUUu+8G4p4R3BQgGi IX8wz9Jg29QDpmZyVGsZyraSxOmB5QAklaZF9qFOAPX40wLR1ZqK7k34s15mg7plrLfm en/w== 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=45QO3C6SA2VkFuOx7DmSHA8hkf9+t6flly8EUtJacHw=; b=O+wdtEAptGS390Hbb0ktoSr85zTnBmFU+C77tVsCEtUY2WTtCHkWrVMSw53C2Po3j7 wNFbz6FmY22uEHDkzJYjtwxN8uLwSn1ON7YQ5Egek/+Cj14utfXq1u+r1R/WOPRzBYXt iAHCC7sycH1D4DPnKl4DWo9v4kNwFi1SUb5KaUhL43KDB9cxhzSFj8isfIywSMBKVQOj 9qV97X7Xk5R3W/qfNPyLZtj0ZvcXyChF3yJx2KXeGnYrLFQg0/nknoByew/JmSls92sF GOYyANTUmkSLHkMMa2EYIfM4wth53udP2VWKDYPybXr/os3+wUOTr9sxRMjXgDC4g3vK XHsA== 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 oz9-20020a1709077d8900b0072abb95e8e4si10291718ejc.598.2022.07.23.07.10.40; Sat, 23 Jul 2022 07:10:40 -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 C125668B7DC; Sat, 23 Jul 2022 17:10:28 +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 B2D1368B704 for ; Sat, 23 Jul 2022 17:10:21 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 36F522400F5 for ; Sat, 23 Jul 2022 16:10:21 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id yPci9xQOYTce for ; Sat, 23 Jul 2022 16:10:20 +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 50011240179 for ; Sat, 23 Jul 2022 16:10:19 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 544E83A0232; Sat, 23 Jul 2022 16:10:19 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 23 Jul 2022 16:09:27 +0200 Message-Id: <20220723140952.31814-2-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 02/27] fftools/ffmpeg: stop accessing the encoder context unnecessarily 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: 6siq4tbdc33V The same information is available from AVStream.codecpar. This will allow to stop allocating an encoder unless encoding is actually performed. --- fftools/ffmpeg.c | 15 ++++++++------- fftools/ffmpeg_mux.c | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 841dd6f08a..7c340f4570 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1454,13 +1454,14 @@ static void print_final_stats(int64_t total_size) for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; - switch (ost->enc_ctx->codec_type) { + AVCodecParameters *par = ost->st->codecpar; + switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; case AVMEDIA_TYPE_SUBTITLE: subtitle_size += ost->data_size; break; default: other_size += ost->data_size; break; } - extra_size += ost->enc_ctx->extradata_size; + extra_size += par->extradata_size; data_size += ost->data_size; if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) @@ -1526,7 +1527,7 @@ static void print_final_stats(int64_t total_size) for (j = 0; j < of->nb_streams; j++) { OutputStream *ost = output_streams[of->ost_index + j]; - enum AVMediaType type = ost->enc_ctx->codec_type; + enum AVMediaType type = ost->st->codecpar->codec_type; total_size += ost->data_size; total_packets += atomic_load(&ost->packets_written); @@ -1603,12 +1604,12 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (!ost->stream_copy) q = ost->quality / (float) FF_QP2LAMBDA; - if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (vid && ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (!vid && ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { float fps; uint64_t frame_number = atomic_load(&ost->packets_written); @@ -3362,8 +3363,8 @@ static int transcode_init(void) */ for (i = 0; i < nb_output_streams; i++) { if (!output_streams[i]->stream_copy && - (output_streams[i]->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO || - output_streams[i]->enc_ctx->codec_type == AVMEDIA_TYPE_AUDIO)) + (output_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || + output_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)) continue; ret = init_output_stream_wrapper(output_streams[i], NULL, 0); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index df9cb73d0e..7f6da997a4 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -201,7 +201,7 @@ static int write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) if (debug_ts) { av_log(NULL, AV_LOG_INFO, "muxer <- type:%s " "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s size:%d\n", - av_get_media_type_string(ost->enc_ctx->codec_type), + av_get_media_type_string(st->codecpar->codec_type), av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ost->st->time_base), av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ost->st->time_base), av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ost->st->time_base),