From patchwork Tue Jan 11 09:58:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33231 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3548212iog; Tue, 11 Jan 2022 02:04:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwG5xmKV4nBDzeXZOXgCfTh2z0nJuaHjTh1VLtvoB1qOfJrXTiZl0HLlUnc5Xx/nTYZ8kqD X-Received: by 2002:a05:6402:1a38:: with SMTP id be24mr3593881edb.201.1641895448163; Tue, 11 Jan 2022 02:04:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895448; cv=none; d=google.com; s=arc-20160816; b=YCLvnsQfPGHwtyxJsyzOkETrxAxUSSQJF2O6r2FfkGfuZcc1Zhofv5zy1LbhOhrEej Zyob0URI0ZyRkbFRndG/PxuJ27L8jdLVCU/lLKjC9QFcm8VJRvCYhspB88y4VSEQK1U8 MJF0wUPKu9Bz0Kov5MHAZI23qKgqWfstnsiWLwST+2FULGD7Ps5XLxE0JG4OY2mxUAKD XlS+hyAfPi6rbwhIDahJAS8b8gpJLUuD1Man27nLzRJYVYHIqXmpJ3rPGpQJ/YI/b90c qVv6/sakJygcPhhtCVu61u2LiCm67dD/tCzJDKthSUy9fWZFO019vzGRuzh6oWXVIIYy oZ2w== 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=cxg9cJLoYpRsBzpB3yS23yDz2RdWf/oY2cXjpe1hhqQ=; b=KD9y+64ZGpXkc5rbXWRXTyK0oZHNydkT8vPAgBz4vzzoim3PFZapH6yAmKpftHQmQ3 2mPcjNmMmtyDeDWpGESI2tZLuuLAV4HBww+QiqIRsmT1ra1vL0v+IKUJlZdsFlKqXNWX ds+q4NoCYGGw/imfNwUWJlgQ8cvYN0PbIWaCQ1zeIainbKT45SWWopzyD0yGIBoqKWEg XMON9f+YJYGPzh/fKgtCXrO932UxaRUy9xaN0EliGdPHB/wk5TA/mFoJPih2s4h+3pBX 0fRpnFyU5qEURTv42sCPbpVjtAB51baJpx10t/E5qChUMyXdBmmeRLKvgCs2TTZpB+f/ BasQ== 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 f17si4792235edq.103.2022.01.11.02.04.07; Tue, 11 Jan 2022 02:04:08 -0800 (PST) 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 3F75668A320; Tue, 11 Jan 2022 11:59:37 +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 F06C568AF7E for ; Tue, 11 Jan 2022 11:59:15 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B3A4E240179 for ; Tue, 11 Jan 2022 10:59:15 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id QZXB9Fgkby5g for ; Tue, 11 Jan 2022 10:59:11 +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 ED47824068F for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 4C8003A0E05; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:30 +0100 Message-Id: <20220111095830.31542-28-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220111095830.31542-1-anton@khirnov.net> References: <20220111095830.31542-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 28/28] ffmpeg_mux: move processing AV_PKT_DATA_QUALITY_STATS to do_video_stats() 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: qxm66J/LeRZb This is a more appropriate place for this code, since the values we read from AV_PKT_DATA_QUALITY_STATS side data are primarily written into video stats. Rename the function to update_video_stats() to better reflect its new purpose. --- fftools/ffmpeg_mux.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 21771b3ae6..52986b002a 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -56,13 +56,28 @@ struct Muxer { static int want_sdp = 1; -static void do_video_stats(OutputStream *ost, const AVPacket *pkt) +static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats) { + const uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, + NULL); AVCodecContext *enc = ost->enc_ctx; int frame_number; double ti1, bitrate, avg_bitrate; - /* this is executed just the first time do_video_stats is called */ + ost->quality = sd ? AV_RL32(sd) : -1; + ost->pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE; + + for (int i = 0; i < FF_ARRAY_ELEMS(ost->error); i++) { + if (sd && i < sd[5]) + ost->error[i] = AV_RL64(sd + 8 + 8 * i); + else + ost->error[i] = -1; + } + + if (!write_vstats) + return; + + /* this is executed just the first time update_video_stats is called */ if (!vstats_file) { vstats_file = fopen(vstats_filename, "w"); if (!vstats_file) { @@ -155,19 +170,6 @@ static void write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) pkt->pts = pkt->dts = AV_NOPTS_VALUE; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { - int i; - uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, - NULL); - ost->quality = sd ? AV_RL32(sd) : -1; - ost->pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE; - - for (i = 0; ierror); i++) { - if (sd && i < sd[5]) - ost->error[i] = AV_RL64(sd + 8 + 8*i); - else - ost->error[i] = -1; - } - if (ost->frame_rate.num && ost->is_cfr) { if (pkt->duration > 0) av_log(NULL, AV_LOG_WARNING, "Overriding packet duration by frame rate, this should not happen\n"); @@ -220,9 +222,8 @@ static void write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) ost->data_size += pkt->size; ost->packets_written++; - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && - ost->encoding_needed && vstats_filename) - do_video_stats(ost, pkt); + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed) + update_video_stats(ost, pkt, !!vstats_filename); pkt->stream_index = ost->index;