From patchwork Wed May 11 08:16:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 35729 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp3781341pzb; Wed, 11 May 2022 01:18:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFPSfIpkWrocGkXLqP7nxrrGGR6HXAzvK/fJYyPK/ypLPD3536TFQtFFNkEddzvqCMKqhy X-Received: by 2002:a17:907:7205:b0:6f5:3f1:927e with SMTP id dr5-20020a170907720500b006f503f1927emr22868988ejc.739.1652257125330; Wed, 11 May 2022 01:18:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652257125; cv=none; d=google.com; s=arc-20160816; b=HaA4lB7os/xqdArG6BrOEEpImhelJp6YDGuQvE5fqpBcQQYiIxOiwjSMqFNf3e93sQ N1eOnmDi9/zb2cYutUZfDmVnzuwzFxQdWiFPtUKkYP8A0qGss0SQLQP35ffzHUSaucT1 aQlEod4ugLWCt24K/rXRHrbPYtxFP/OSz+RnF0ZNtx0ZRNwu9TrpkhNC/hkD2j9rSaRP ke1K9Dgp2lCe4T1uqkkWKW0b6JyI1VGCnjthVBTnImaifiW9qn7EoJ71MfSe/RXn6ci9 Iw0kCiaG8SVvO6S3KLd1EV+GHkEMOjNj+e0vTnvJdE0E9laNAGLwH/0SRIxxxX3jQ2ze xTZw== 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=7nJ6IXh/kkb79vXCdz38DrZsmY9pFhoCJzYDLElsGUY=; b=fOjqdZpWBjeI1I+0PnmIXNpesrhNQ16+J+9df5SdQbf8/8Zox8+++BYoKKgq8YTCIc /AkMpjXqWrz0+5mjG5Ra76bqFivRFjYA4YtsXXozIAb9jsZDT1G/j9S+sEg0SR/eu6x7 nObQIGXFNkr3nH8S3X7hWaw+BX6nMM/sQDHiy8COypUzWtykPhCWK+21ybW3vMJscSEe qEz0uK0fJzbkeSZ4GjHTmGLTq9AMP2mezPdfzXceaCW2zdniWp0h2hBeblSWBIy3owQi v1F97F/Xuk7mTXeF5nyqxI95qt6QQzczb2xbAEPZZBOtVMjeU0fnQcATuAYwYJh96LW5 459A== 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 d11-20020a170906c20b00b006e89ac43dcfsi1576436ejz.899.2022.05.11.01.18.42; Wed, 11 May 2022 01:18:45 -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 0F1C468B45F; Wed, 11 May 2022 11:17:25 +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 6796B68B419 for ; Wed, 11 May 2022 11:17:15 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5404824050B for ; Wed, 11 May 2022 10:17:12 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id lgGknqmcgeOu for ; Wed, 11 May 2022 10:17:11 +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 CBE48240511 for ; Wed, 11 May 2022 10:17:07 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id B7B913A0860; Wed, 11 May 2022 10:17:02 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 May 2022 10:16:54 +0200 Message-Id: <20220511081654.15127-9-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220511081654.15127-1-anton@khirnov.net> References: <20220511081654.15127-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 9/9] fftools/ffmpeg: 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: OVC3cpGqv1D9 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. This ensures that the values written into stats actually apply to the right packet. Rename the function to update_video_stats() to better reflect its new purpose. --- fftools/ffmpeg.c | 23 +++++++++++++++++++---- fftools/ffmpeg_mux.c | 13 ------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index fe7c37db62..2706719206 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -835,13 +835,28 @@ static double psnr(double d) return -10.0 * log10(d); } -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; ierror); 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) { @@ -941,8 +956,8 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &enc->time_base)); } - if (enc->codec_type == AVMEDIA_TYPE_VIDEO && vstats_filename) - do_video_stats(ost, pkt); + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) + update_video_stats(ost, pkt, !!vstats_filename); ost->packets_encoded++; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 3cdaa494d7..794d580635 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -101,19 +101,6 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, 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");