From patchwork Wed May 11 08:16:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 35724 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp3781049pzb; Wed, 11 May 2022 01:17:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgXrA2pYfA7LEltMljTAImyEJKRfrl9E9bb+0jhAJwIR6HbQ2+Dsc2RzgRe0nGXY57lKxn X-Received: by 2002:a17:906:6a1b:b0:6f4:a9b8:e027 with SMTP id qw27-20020a1709066a1b00b006f4a9b8e027mr23295542ejc.222.1652257070895; Wed, 11 May 2022 01:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652257070; cv=none; d=google.com; s=arc-20160816; b=vUm1TYV+MHALzcGCU41eAMrLc+VfX2X9Dvd+4Un1QJ5QW/5kkcnI5EdP9wkZysGhgI bPEM203pshC51iLRXjTrSEL9ZvRAhhSka9Oc2gZ8/J6SW0URn5oSyVHcoKKQ8qlr9Nsc kZ+v6MXnAOz/RS0XTj7sN4hs8acEwjYK3/VA/MTiV0jO1QgscghWwcHT2IaYu+wF2IBN mLVOaSqnCeLDjn3uBhVN9tcXG/Am7SsUBV1K/cDjSlPAjuDu3484wx5J4vKiJKzvSGI9 sp7aAIv6YcI4q0SqufTB6+NvG9DevAfZi3Z5Q8UlKBUcxEB4UDgkLDlY3sKG9Z08XFOf tZBg== 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:message-id:date:to:from :delivered-to; bh=O2wSuQUBjHolZGjwDup3U7leKYK2BKkzPgCbq5RA7fg=; b=zksi383JpxKE6fOvZvvapg/zfcDXiYjmzT9pxYojDH3iwZZDeN52uEPoraTUKSFiEx mfqxAkeMlgRe1nBN7D25pS2u5ZP4OEW3/nhbTDwDAnrc5gitqXzo5UxxjWRmgiX8l0rC sx4q4BJzDvDL1zl+AxExGifQQOW+7LNJNP8lGyZ9R2C4mInbocfPqldnq9jjZEcC8MIy a1jJLBw9mTlbm+sQ9DnCm9CFvr98fYakmcU1nholgkKKndZ5mTErqN9m835ZTuof5Jju dLGJXrKNHqZQMePr4XwlV3oUDCX/C9f+wigYMeIgBKcriDJrUoZtNXbCsnHQsxIZ+X6P 04ig== 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 u18-20020aa7d992000000b004281818148bsi1453744eds.240.2022.05.11.01.17.49; Wed, 11 May 2022 01:17:50 -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 BAC0768B379; Wed, 11 May 2022 11:17:19 +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 E60DF68B379 for ; Wed, 11 May 2022 11:17:10 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 54870240179 for ; Wed, 11 May 2022 10:17:10 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id won-SIXXHe8I for ; Wed, 11 May 2022 10:17:09 +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 92E2224017E for ; Wed, 11 May 2022 10:17:07 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id A51F83A0406; Wed, 11 May 2022 10:17:02 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 May 2022 10:16:46 +0200 Message-Id: <20220511081654.15127-1-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/9] fftools/ffmpeg: share the code encoding a single frame between video and audio 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: yjy00KK08rj9 Call do_video_stats() for every video packets produced by the encoder, rather than for every frame sent to the encoder. --- fftools/ffmpeg.c | 145 ++++++++++++++++++++--------------------------- 1 file changed, 60 insertions(+), 85 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index a85ed18b08..0e62c39522 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -831,63 +831,96 @@ static int init_output_stream_wrapper(OutputStream *ost, AVFrame *frame, return ret; } -static void do_audio_out(OutputFile *of, OutputStream *ost, - AVFrame *frame) +static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) { - AVCodecContext *enc = ost->enc_ctx; - AVPacket *pkt = ost->pkt; + AVCodecContext *enc = ost->enc_ctx; + AVPacket *pkt = ost->pkt; + const char *type_desc = av_get_media_type_string(enc->codec_type); int ret; - adjust_frame_pts_to_encoder_tb(of, ost, frame); - - if (!check_recording_time(ost)) - return; - - if (frame->pts == AV_NOPTS_VALUE || audio_sync_method < 0) - frame->pts = ost->sync_opts; - ost->sync_opts = frame->pts + frame->nb_samples; - ost->samples_encoded += frame->nb_samples; ost->frames_encoded++; update_benchmark(NULL); + if (debug_ts) { - av_log(NULL, AV_LOG_INFO, "encoder <- type:audio " + av_log(NULL, AV_LOG_INFO, "encoder <- type:%s " "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n", + type_desc, av_ts2str(frame->pts), av_ts2timestr(frame->pts, &enc->time_base), enc->time_base.num, enc->time_base.den); } ret = avcodec_send_frame(enc, frame); - if (ret < 0) - goto error; + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error submitting %s frame to the encoder\n", + type_desc); + return ret; + } while (1) { ret = avcodec_receive_packet(enc, pkt); + update_benchmark("encode_%s %d.%d", type_desc, + ost->file_index, ost->index); if (ret == AVERROR(EAGAIN)) - break; - if (ret < 0) - goto error; + return 0; + else if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "%s encoding failed\n", type_desc); + return ret; + } - update_benchmark("encode_audio %d.%d", ost->file_index, ost->index); + if (debug_ts) { + av_log(NULL, AV_LOG_INFO, "encoder -> type:%s " + "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s " + "duration:%s duration_time:%s\n", + type_desc, + av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &enc->time_base), + av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &enc->time_base), + av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &enc->time_base)); + } av_packet_rescale_ts(pkt, enc->time_base, ost->mux_timebase); if (debug_ts) { - av_log(NULL, AV_LOG_INFO, "encoder -> type:audio " + av_log(NULL, AV_LOG_INFO, "encoder -> type:%s " "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s " "duration:%s duration_time:%s\n", + type_desc, av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &enc->time_base), av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &enc->time_base), 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->size); + output_packet(of, pkt, ost, 0); + + /* if two pass, output log */ + if (ost->logfile && enc->stats_out) + fprintf(ost->logfile, "%s", enc->stats_out); } - return; -error: - av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n"); - exit_program(1); + av_assert0(0); +} + +static void do_audio_out(OutputFile *of, OutputStream *ost, + AVFrame *frame) +{ + int ret; + + adjust_frame_pts_to_encoder_tb(of, ost, frame); + + if (!check_recording_time(ost)) + return; + + if (frame->pts == AV_NOPTS_VALUE || audio_sync_method < 0) + frame->pts = ost->sync_opts; + ost->sync_opts = frame->pts + frame->nb_samples; + ost->samples_encoded += frame->nb_samples; + + ret = encode_frame(of, ost, frame); + if (ret < 0) + exit_program(1); } static void do_subtitle_out(OutputFile *of, @@ -979,14 +1012,12 @@ static void do_video_out(OutputFile *of, AVFrame *next_picture) { int ret; - AVPacket *pkt = ost->pkt; AVCodecContext *enc = ost->enc_ctx; AVRational frame_rate; int nb_frames, nb0_frames, i; double delta, delta0; double duration = 0; double sync_ipts = AV_NOPTS_VALUE; - int frame_size = 0; InputStream *ist = NULL; AVFilterContext *filter = ost->filter->filter; @@ -1179,73 +1210,17 @@ static void do_video_out(OutputFile *of, av_log(NULL, AV_LOG_DEBUG, "Forced keyframe at time %f\n", pts_time); } - update_benchmark(NULL); - if (debug_ts) { - av_log(NULL, AV_LOG_INFO, "encoder <- type:video " - "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n", - av_ts2str(in_picture->pts), av_ts2timestr(in_picture->pts, &enc->time_base), - enc->time_base.num, enc->time_base.den); - } - - ost->frames_encoded++; - - ret = avcodec_send_frame(enc, in_picture); + ret = encode_frame(of, ost, in_picture); if (ret < 0) - goto error; - // Make sure Closed Captions will not be duplicated - av_frame_remove_side_data(in_picture, AV_FRAME_DATA_A53_CC); - - while (1) { - ret = avcodec_receive_packet(enc, pkt); - update_benchmark("encode_video %d.%d", ost->file_index, ost->index); - if (ret == AVERROR(EAGAIN)) - break; - if (ret < 0) - goto error; - - if (debug_ts) { - av_log(NULL, AV_LOG_INFO, "encoder -> type:video " - "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s " - "duration:%s duration_time:%s\n", - av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &enc->time_base), - av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &enc->time_base), - av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &enc->time_base)); - } - - av_packet_rescale_ts(pkt, enc->time_base, ost->mux_timebase); - - if (debug_ts) { - av_log(NULL, AV_LOG_INFO, "encoder -> type:video " - "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s " - "duration:%s duration_time:%s\n", - av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ost->mux_timebase), - av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ost->mux_timebase), - av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ost->mux_timebase)); - } - - frame_size = pkt->size; - output_packet(of, pkt, ost, 0); + exit_program(1); - /* if two pass, output log */ - if (ost->logfile && enc->stats_out) { - fprintf(ost->logfile, "%s", enc->stats_out); - } - } ost->sync_opts++; ost->frame_number++; - - if (vstats_filename && frame_size) - do_video_stats(ost, frame_size); } av_frame_unref(ost->last_frame); if (next_picture) av_frame_move_ref(ost->last_frame, next_picture); - - return; -error: - av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n"); - exit_program(1); } static double psnr(double d) From patchwork Wed May 11 08:16:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 35722 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp3780968pzb; Wed, 11 May 2022 01:17:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxvbohItEoqUOMV/zMMresrZFWxiwOu15ebpEuwYePUj3GpVkDNSua6j4lIinh+hMPO7za X-Received: by 2002:a05:6402:4304:b0:427:cb08:b085 with SMTP id m4-20020a056402430400b00427cb08b085mr27667238edc.194.1652257050581; Wed, 11 May 2022 01:17:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652257050; cv=none; d=google.com; s=arc-20160816; b=XtVI/KustKeUZtO5XrTPwjv8ZVW9MLzexcRIvvNJEDlwpV8P/EL+226xiJRmF5mzHt 0LEHNotPsG02tV4Cqs6GJFgtxfMNLa9M8J/HL79oZqlYdr9W1zf8AZW/WVrXRgdx9rT8 v7V5sgOkItTNEOHx9L/K90xrz6s4ChKSHxi4R/k/ST9GNOhukF5pXeYyxxR3mxuacR1H 8Kr0bcZczUIkZc0nX/ajJ9b9rW2dSJ+A2avTLsYkoDco7ykrC13RLTRnc62blxYoMHkn /GVutb34KRzyRFwBipHjg/fuZIyLhI6Igbxber4rhte047GwaUQnpFoLTPHtfntRR8qm zzOw== 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=cEtih5MNkE8E+Ee7VS3ZHdWXKAj9NMPysyahMYRha1Y=; b=k1VBq5Wo74wDE/73G/vvt0epwJ1Xp9AD7gr6AS6MEaclNFWuWHD/xA9XjVrV88aTVf LMBQoPe0lXLdOadk9Dk/cY86PbXpeIH6p660o9pZXEjIz6kYWZQKm2KESeYyVoTPb3vc WTgm3bDKoUd8XDAKhBd17++XO8H5DqibLZ3cQ7OFmz5j4BJ4PZ6BwBJMHjgSAx0Ea6b6 ZaIpQTgPEPfjz3UARXa0aRmSmWNJbFEFMISNI1au8J7pHS9nt7Rx6yo/kWeCRzslWqZB 6miXHqvxSvwaxEUsDWL9Stq7HNLhCKCYfj8rlYJZumFvsclDZYNSPQh9r1KxB46CJFxF g94Q== 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 hc39-20020a17090716a700b006e89f35bd27si1651303ejc.874.2022.05.11.01.17.30; Wed, 11 May 2022 01:17:30 -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 C094B68A61E; Wed, 11 May 2022 11:17:17 +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 2A18668B236 for ; Wed, 11 May 2022 11:17:10 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9363324017C for ; Wed, 11 May 2022 10:17:09 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id vyAuo2GRcnbd for ; Wed, 11 May 2022 10:17:09 +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 85BCA2400F5 for ; Wed, 11 May 2022 10:17:07 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id A6F003A0315; Wed, 11 May 2022 10:17:02 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 May 2022 10:16:47 +0200 Message-Id: <20220511081654.15127-2-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 2/9] fftools/ffmpeg: reuse the encoding code for flushing encoders 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: z7tInM7Q0Nqm --- fftools/ffmpeg.c | 75 +++++++++++------------------------------------- 1 file changed, 16 insertions(+), 59 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0e62c39522..9fa0719cf6 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -836,12 +836,12 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) AVCodecContext *enc = ost->enc_ctx; AVPacket *pkt = ost->pkt; const char *type_desc = av_get_media_type_string(enc->codec_type); + const char *action = frame ? "encode" : "flush"; int ret; + if (frame) { ost->frames_encoded++; - update_benchmark(NULL); - if (debug_ts) { av_log(NULL, AV_LOG_INFO, "encoder <- type:%s " "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n", @@ -849,9 +849,12 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) av_ts2str(frame->pts), av_ts2timestr(frame->pts, &enc->time_base), enc->time_base.num, enc->time_base.den); } + } + + update_benchmark(NULL); ret = avcodec_send_frame(enc, frame); - if (ret < 0) { + if (ret < 0 && !(ret == AVERROR_EOF && !frame)) { av_log(NULL, AV_LOG_ERROR, "Error submitting %s frame to the encoder\n", type_desc); return ret; @@ -859,11 +862,15 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) while (1) { ret = avcodec_receive_packet(enc, pkt); - update_benchmark("encode_%s %d.%d", type_desc, + update_benchmark("%s_%s %d.%d", action, type_desc, ost->file_index, ost->index); - if (ret == AVERROR(EAGAIN)) + if (ret == AVERROR(EAGAIN)) { + av_assert0(frame); // should never happen during flushing return 0; - else if (ret < 0) { + } else if (ret == AVERROR_EOF) { + output_packet(of, pkt, ost, 1); + return ret; + } else if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "%s encoding failed\n", type_desc); return ret; } @@ -1762,59 +1769,9 @@ static void flush_encoders(void) if (enc->codec_type != AVMEDIA_TYPE_VIDEO && enc->codec_type != AVMEDIA_TYPE_AUDIO) continue; - for (;;) { - const char *desc = NULL; - AVPacket *pkt = ost->pkt; - int pkt_size; - - switch (enc->codec_type) { - case AVMEDIA_TYPE_AUDIO: - desc = "audio"; - break; - case AVMEDIA_TYPE_VIDEO: - desc = "video"; - break; - default: - av_assert0(0); - } - - update_benchmark(NULL); - - while ((ret = avcodec_receive_packet(enc, pkt)) == AVERROR(EAGAIN)) { - ret = avcodec_send_frame(enc, NULL); - if (ret < 0) { - av_log(NULL, AV_LOG_FATAL, "%s encoding failed: %s\n", - desc, - av_err2str(ret)); - exit_program(1); - } - } - - update_benchmark("flush_%s %d.%d", desc, ost->file_index, ost->index); - if (ret < 0 && ret != AVERROR_EOF) { - av_log(NULL, AV_LOG_FATAL, "%s encoding failed: %s\n", - desc, - av_err2str(ret)); - exit_program(1); - } - if (ost->logfile && enc->stats_out) { - fprintf(ost->logfile, "%s", enc->stats_out); - } - if (ret == AVERROR_EOF) { - output_packet(of, pkt, ost, 1); - break; - } - if (ost->finished & MUXER_FINISHED) { - av_packet_unref(pkt); - continue; - } - av_packet_rescale_ts(pkt, enc->time_base, ost->mux_timebase); - pkt_size = pkt->size; - output_packet(of, pkt, ost, 0); - if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO && vstats_filename) { - do_video_stats(ost, pkt_size); - } - } + ret = encode_frame(of, ost, NULL); + if (ret != AVERROR_EOF) + exit_program(1); } } From patchwork Wed May 11 08:16:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 35721 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp3780899pzb; Wed, 11 May 2022 01:17:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKPOT39aW5caBLgc8UgJ5jcyU88S5BC+mgq61m8RXPxJCpf1YedR2R6En7m/tpAUHU145e X-Received: by 2002:a17:906:974e:b0:6f5:2d44:7e3c with SMTP id o14-20020a170906974e00b006f52d447e3cmr21028175ejy.167.1652257040501; Wed, 11 May 2022 01:17:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652257040; cv=none; d=google.com; s=arc-20160816; b=o5OjARJYdFPd+TQingc7491sLpsr0xsjPgvGbYTWLAuB2rDWwM2AUjV9E47vzg9ieH WlqbfXbUONedp3qcCfu7WlhxLgYDDFd3m4c026GMVPqR99ydSIcT6sWPSUE15phJZHRl KA4O1Cgf3Je/0F7BnSJ0cgFTXl+5mmCL67uYcsvaHjp+Dsr6jQtTGJlAtEnL9iO5Fl3d 8RVKyvP+VEvyGTN1Qj4ZEq5k0YzsaA6bd4clpk4JUpLOuVp1kSWKRqkvoFUXEywmzEke XMpusEkW4WOcsqW8c5FJQnQPumKnzwfECTzraYqlfIcFtUTTXFMdWZTedWCU8jXqo2fo ECwA== 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=Q642AAvfhrUtBOTq4TFlYOKIGE9jy1FHf3jcvbaQ3fU=; b=Kqeb3+wUFy69WiUggvacTPfN4dVg8snjX9ebcqEyWijuHRCG7BjIOv3gsbynyxeLmg VUh6ZsEqZI8ENWxDlgFonuRNzasAGZv+zevRRsmXdGfacu89JCPy3JyoF1eGIb7q3Nuj C+HDgCUxTjvtzaiFhaOIMLOxl3+Dx0MzeoJDP7/vCkCGNLCezKhI3IIjFsz1QZdWWjyD Y0KrZidzIqSvOixbXo4FPV10l+W8n3Ok8MzHigzVhwn0zig3OtON2RwRCW1x2Wbyui/p sjgVTGi/XaFGqIh37fGzYrvT8F2Bi5uZbdyvicGPQ35LiF2jDgUFU6H/ddNhbvqxYSry evCg== 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 oz16-20020a1709077d9000b006f379f93701si1664854ejc.843.2022.05.11.01.17.19; Wed, 11 May 2022 01:17:20 -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 B6A6068B3BB; Wed, 11 May 2022 11:17:16 +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 0662668AEF0 for ; Wed, 11 May 2022 11:17:10 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D622A240512 for ; Wed, 11 May 2022 10:17:08 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id cBwVn7uwUobw for ; Wed, 11 May 2022 10:17:07 +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 9129D24017C for ; Wed, 11 May 2022 10:17:07 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id A95683A0631; Wed, 11 May 2022 10:17:02 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 May 2022 10:16:48 +0200 Message-Id: <20220511081654.15127-3-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 3/9] fftools/ffmpeg: reindent after previous commit 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: yAIdc4Rbs1o+ --- fftools/ffmpeg.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 9fa0719cf6..69b9c42822 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -840,15 +840,15 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) int ret; if (frame) { - ost->frames_encoded++; + ost->frames_encoded++; - if (debug_ts) { - av_log(NULL, AV_LOG_INFO, "encoder <- type:%s " - "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n", - type_desc, - av_ts2str(frame->pts), av_ts2timestr(frame->pts, &enc->time_base), - enc->time_base.num, enc->time_base.den); - } + if (debug_ts) { + av_log(NULL, AV_LOG_INFO, "encoder <- type:%s " + "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n", + type_desc, + av_ts2str(frame->pts), av_ts2timestr(frame->pts, &enc->time_base), + enc->time_base.num, enc->time_base.den); + } } update_benchmark(NULL); From patchwork Wed May 11 08:16:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 35723 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp3780997pzb; Wed, 11 May 2022 01:17:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ6I1RDuGq98mUbdqBAkFNrdId+gtLukUgM1oyMW2K6JYlaoYd/yJiHGNJ9iqDfTjnxZDx X-Received: by 2002:a17:907:3e93:b0:6f4:e215:e293 with SMTP id hs19-20020a1709073e9300b006f4e215e293mr22716767ejc.629.1652257059965; Wed, 11 May 2022 01:17:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652257059; cv=none; d=google.com; s=arc-20160816; b=svcWjdhxKDmFlWCP0MK4+VUBMHdUi9m6nnX0u/f0Um+n6rpcL+J0ZPTomTQoJ3JGCT zlmkB0TeWZetsmtPMROmFnekEw71wovMrfO6HJ2MAhcLPrMghsnwLI1rjV+jUVyf/hEX T2YPyD+97WRt3vpaSET6fITwoqEY3/ozrKZaVI1OBjsMyjaotJDqBrBtqod1H6G8UwM+ GkYF1UXbsGo7BD2SekZQtYzlCKLilawijTo5UNy5UhRrJsGQ59/myNJmOeT64bAHV4CH sc5+sidqIL1+dbt7/3vwlgHFwtuoW1lcIkzvivyjuo4IM6BX+6OqncRwHohyIFDWKlir lrvA== 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=SXU0/0i84gkG0P6Kn+Tt9nZSf0a4xqeCgaIJSf7St6I=; b=LX2mW7WZTRaJD8X/c7jpuIiQ0/925inAuAYFO4JcP3REtUwGmWs3vPqzbNO/LuhGR3 wZOhkVw9ZOnT2FmDEI6PxOd/fGGavE569EorMcxn0ii9zXgF4QdOJ5lXcoyUeewifenL YyefVMi0Njpzgc+ET9QG1qSwRHOAlGA25cpkAbNpj6OZ/LGO2UeamuwEonSHyvilt/ca XOMxxqDcNHpoQ3A+7VLzv7g3dAiG4GzGz59GAsN56D5AQh7VUDTtXeqdSDXfbCweQurg 8Y0HwsUZjrZd5rtGVsug2VTfWm/ol4PCVQ/RjRkX4ogwTi40Yh4XUo97Xtu59ecJ08kQ ON5Q== 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 hr40-20020a1709073fa800b006fa8f581b90si1632764ejc.771.2022.05.11.01.17.39; Wed, 11 May 2022 01:17:39 -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 BF07F68B388; Wed, 11 May 2022 11:17:18 +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 5C91B68B236 for ; Wed, 11 May 2022 11:17:10 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BE5632400F5 for ; Wed, 11 May 2022 10:17:09 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 1WJw3r90FPB6 for ; Wed, 11 May 2022 10:17:07 +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 8F27D240179 for ; Wed, 11 May 2022 10:17:07 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id ABB0B3A0663; Wed, 11 May 2022 10:17:02 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 May 2022 10:16:49 +0200 Message-Id: <20220511081654.15127-4-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 4/9] fftools/ffmpeg: drop a useless check and reduce indentation 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: x3QHTw/OVnSW do_video_stats() is only ever called for video. --- fftools/ffmpeg.c | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 69b9c42822..2bc612f448 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1251,31 +1251,29 @@ static void do_video_stats(OutputStream *ost, int frame_size) } enc = ost->enc_ctx; - if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { - frame_number = ost->st->nb_frames; - if (vstats_version <= 1) { - fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, - ost->quality / (float)FF_QP2LAMBDA); - } else { - fprintf(vstats_file, "out= %2d st= %2d frame= %5d q= %2.1f ", ost->file_index, ost->index, frame_number, - ost->quality / (float)FF_QP2LAMBDA); - } - - if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR)) - fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0))); - - fprintf(vstats_file,"f_size= %6d ", frame_size); - /* compute pts value */ - ti1 = av_stream_get_end_pts(ost->st) * av_q2d(ost->st->time_base); - if (ti1 < 0.01) - ti1 = 0.01; - - bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0; - avg_bitrate = (double)(ost->data_size * 8) / ti1 / 1000.0; - fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", - (double)ost->data_size / 1024, ti1, bitrate, avg_bitrate); - fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(ost->pict_type)); - } + frame_number = ost->st->nb_frames; + if (vstats_version <= 1) { + fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, + ost->quality / (float)FF_QP2LAMBDA); + } else { + fprintf(vstats_file, "out= %2d st= %2d frame= %5d q= %2.1f ", ost->file_index, ost->index, frame_number, + ost->quality / (float)FF_QP2LAMBDA); + } + + if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR)) + fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0))); + + fprintf(vstats_file,"f_size= %6d ", frame_size); + /* compute pts value */ + ti1 = av_stream_get_end_pts(ost->st) * av_q2d(ost->st->time_base); + if (ti1 < 0.01) + ti1 = 0.01; + + bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0; + avg_bitrate = (double)(ost->data_size * 8) / ti1 / 1000.0; + fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", + (double)ost->data_size / 1024, ti1, bitrate, avg_bitrate); + fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(ost->pict_type)); } static void finish_output_stream(OutputStream *ost) From patchwork Wed May 11 08:16:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 35726 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp3781170pzb; Wed, 11 May 2022 01:18:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEFrWGJklY3LliUa7xV7y6ZNg27iHrFLvL8DNjtla8iQxf6mP1t3bmkWbTRG2h2GtZYzve X-Received: by 2002:a17:906:d550:b0:6f8:60a4:c2cf with SMTP id cr16-20020a170906d55000b006f860a4c2cfmr17403541ejc.477.1652257092335; Wed, 11 May 2022 01:18:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652257092; cv=none; d=google.com; s=arc-20160816; b=YrzF6crIQH3TctRzaezFRWfThDlq+EvNP/mjVGiHTZagk9s+7coudGyio0sFwQF5Uz 7bkDhhAHc1/1aX8O2EdQaOlDW9GfxSXasIQ7pdNQRNkzqdzWfG51MzHNNW4wDaTc3sty bA+UCprrL1IOc8J/TjXXtC9hqeT27FyeqHa8HT9Qc6hybPQsQu9ONDTrc51G0r4nYaTR X59vM3WQtfeWiYnbZoqhQ/9ezdKaiXWyyexCqFii0ivQXntwbSl9nxMPnZUg7JwmmWuB UiO6gC5p9dZvhNKL6c2OElRsJ6DJ6TpejVsyvMRWbTQrIfYWtugig3WHCrdb67tZ9KKb DcnA== 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=9bV+dN5WNT4eES4dW7fufhpry9tVLaMBz0iA9IwSCbw=; b=uiYFwutCxR1f5J6suczqmj0Mo/YoQlHKmzn1sjvpbvb783iEstc04Xdz5rFH1Mjf1k wLoHzlT3CV7IbQ9aSvFLOiogGwtv5z3WQBRHgGgAGCJUrMiWMQx4pJnWMvp01mxU5s47 eUVbm4ehDY8nUcbXVgc8f2u56+sQ45zeYXs8Yd5ADNzSJDMfDs/7antM9IbqzDLxRtFN x+2jcw795CzmAHNcD0VpTtCTYcdYxEN0iP0kOQs59uErTyqH/bIZJ2Wkw7KlYuCDHKdl 1geuA7+uIynhESYpKQ8rh7aws1wFeU/SnLp0/nWN82i9Fg4lWnlk2BF26wulIiI4HGmU awMg== 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 dt19-20020a170907729300b006f3c1c439f3si1561483ejc.595.2022.05.11.01.18.11; Wed, 11 May 2022 01:18:12 -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 CAA9768B445; Wed, 11 May 2022 11:17:21 +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 3A6BB68B409 for ; Wed, 11 May 2022 11:17:15 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 4357D240506 for ; Wed, 11 May 2022 10:17:11 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 8R7buNDVeiva for ; Wed, 11 May 2022 10:17:09 +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 941372404FE for ; Wed, 11 May 2022 10:17:07 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id AE1293A0763; Wed, 11 May 2022 10:17:02 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 May 2022 10:16:50 +0200 Message-Id: <20220511081654.15127-5-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 5/9] fftools/ffmpeg: move do_video_stats() to avoid a forward declaration 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: tU74jTYOY46R --- fftools/ffmpeg.c | 93 ++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 47 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2bc612f448..ae3cc57bef 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -127,7 +127,6 @@ typedef struct BenchmarkTimeStamps { int64_t sys_usec; } BenchmarkTimeStamps; -static void do_video_stats(OutputStream *ost, int frame_size); static BenchmarkTimeStamps get_benchmark_time_stamps(void); static int64_t getmaxrss(void); static int ifilter_has_all_input_formats(FilterGraph *fg); @@ -831,6 +830,52 @@ static int init_output_stream_wrapper(OutputStream *ost, AVFrame *frame, return ret; } +static double psnr(double d) +{ + return -10.0 * log10(d); +} + +static void do_video_stats(OutputStream *ost, int frame_size) +{ + AVCodecContext *enc; + int frame_number; + double ti1, bitrate, avg_bitrate; + + /* this is executed just the first time do_video_stats is called */ + if (!vstats_file) { + vstats_file = fopen(vstats_filename, "w"); + if (!vstats_file) { + perror("fopen"); + exit_program(1); + } + } + + enc = ost->enc_ctx; + frame_number = ost->st->nb_frames; + if (vstats_version <= 1) { + fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, + ost->quality / (float)FF_QP2LAMBDA); + } else { + fprintf(vstats_file, "out= %2d st= %2d frame= %5d q= %2.1f ", ost->file_index, ost->index, frame_number, + ost->quality / (float)FF_QP2LAMBDA); + } + + if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR)) + fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0))); + + fprintf(vstats_file,"f_size= %6d ", frame_size); + /* compute pts value */ + ti1 = av_stream_get_end_pts(ost->st) * av_q2d(ost->st->time_base); + if (ti1 < 0.01) + ti1 = 0.01; + + bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0; + avg_bitrate = (double)(ost->data_size * 8) / ti1 / 1000.0; + fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", + (double)ost->data_size / 1024, ti1, bitrate, avg_bitrate); + fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(ost->pict_type)); +} + static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) { AVCodecContext *enc = ost->enc_ctx; @@ -1230,52 +1275,6 @@ static void do_video_out(OutputFile *of, av_frame_move_ref(ost->last_frame, next_picture); } -static double psnr(double d) -{ - return -10.0 * log10(d); -} - -static void do_video_stats(OutputStream *ost, int frame_size) -{ - AVCodecContext *enc; - int frame_number; - double ti1, bitrate, avg_bitrate; - - /* this is executed just the first time do_video_stats is called */ - if (!vstats_file) { - vstats_file = fopen(vstats_filename, "w"); - if (!vstats_file) { - perror("fopen"); - exit_program(1); - } - } - - enc = ost->enc_ctx; - frame_number = ost->st->nb_frames; - if (vstats_version <= 1) { - fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, - ost->quality / (float)FF_QP2LAMBDA); - } else { - fprintf(vstats_file, "out= %2d st= %2d frame= %5d q= %2.1f ", ost->file_index, ost->index, frame_number, - ost->quality / (float)FF_QP2LAMBDA); - } - - if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR)) - fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0))); - - fprintf(vstats_file,"f_size= %6d ", frame_size); - /* compute pts value */ - ti1 = av_stream_get_end_pts(ost->st) * av_q2d(ost->st->time_base); - if (ti1 < 0.01) - ti1 = 0.01; - - bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0; - avg_bitrate = (double)(ost->data_size * 8) / ti1 / 1000.0; - fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", - (double)ost->data_size / 1024, ti1, bitrate, avg_bitrate); - fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(ost->pict_type)); -} - static void finish_output_stream(OutputStream *ost) { OutputFile *of = output_files[ost->file_index]; From patchwork Wed May 11 08:16:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 35728 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp3781292pzb; Wed, 11 May 2022 01:18:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNmmWXldXkck7qSU3Wq5otmmLw6xzqtx8ln03w5/iMARwYePSCOR/NvHtukzNZZHNjcDQX X-Received: by 2002:a17:907:6d24:b0:6f4:bc43:e7d1 with SMTP id sa36-20020a1709076d2400b006f4bc43e7d1mr22740741ejc.581.1652257112985; Wed, 11 May 2022 01:18:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652257112; cv=none; d=google.com; s=arc-20160816; b=ZQCWhR+cgGLv4gqXjlX9lr70jIGXxWyScPplGoUnR99SxGXCuwI3MQdfyWF+rcDNhb 55ALgOs3mpb3/hCemzZOZF4wHgZmTMJzP09Y0YTy/nsDKmxSL7v/Uvh241hZe5BBUU9c CQLAV63ScEemAMbZXw3TB9hLAvivhAfUVoGdkeTaCqaDyuAB8Y53X8HtFUPrhs3poDQi sFsdrmwcD22Q4h+eqdwBys1l8gcCm1+xZx4x+nN8Z/xoDrh7V3sKe1a/eMWIALwxZErf pF4S+Qgyo8Wo8kqZzTYFLEap6D16TZjD3zfPi4GABMR0PltsWdC1L65T3UY6TQXFjyCf rwFQ== 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=Gl60HweIdEGH1zD3payprv2Wwpiy1KzmzyZP1EMZvoU=; b=EHEJI86qcYinUc8Sn26Adeas1fdn37qxzbSIAkIl2AQNDj7+OZcitzsQ0mhhDzvOSO nlxkhtgvN8kcZIQcvF+wST7Zh9mWY4POo3T8X8LOBbJfidVfgr3kFr7npwX13fdu+QLp jslweWUlhxLKXchdxes+chiRxK/v2l8VEQiDgQBGPp0pX+A+RfyUxNDbpTiN25+JaC1x veO0cC+BPZ5tTTNGgKcry/j6nlswvruzVw/yI8+niL6cMffjk3E4N1M4LNonQmPTV3sl 7oHb8usri0RcrtwXhCy+D9Ky5z6/fyBafLQQXk3OxcsXMsCIcanrZwPb7abXKxCUPFDW UJqA== 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 g17-20020a1709065d1100b006e86c3056c2si1852210ejt.33.2022.05.11.01.18.32; Wed, 11 May 2022 01:18:32 -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 4083B68B457; Wed, 11 May 2022 11:17:24 +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 5F67668B423 for ; Wed, 11 May 2022 11:17:15 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B7F65240507 for ; Wed, 11 May 2022 10:17:11 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id WRVg16njpYAj 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 C961224050B for ; Wed, 11 May 2022 10:17:07 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id B07863A07AE; Wed, 11 May 2022 10:17:02 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 May 2022 10:16:51 +0200 Message-Id: <20220511081654.15127-6-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 6/9] fftools/ffmpeg: stop using AVStream.nb_frames in 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: eVnW8wWCsey8 Its use for muxing is not documented, in practice it is incremented per each packet successfully passed to the muxer's write_packet(). Since there is a lot of indirection between ffmpeg receiving a packet from the encoder and it actually being written (e.g. bitstream filters, the interleaving queue), using nb_frames here is incorrect. Add a new counter for packets received from encoder instead. --- fftools/ffmpeg.c | 4 +++- fftools/ffmpeg.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index ae3cc57bef..c15d1486dd 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -851,7 +851,7 @@ static void do_video_stats(OutputStream *ost, int frame_size) } enc = ost->enc_ctx; - frame_number = ost->st->nb_frames; + frame_number = ost->packets_encoded; if (vstats_version <= 1) { fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, ost->quality / (float)FF_QP2LAMBDA); @@ -945,6 +945,8 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) if (enc->codec_type == AVMEDIA_TYPE_VIDEO && vstats_filename) do_video_stats(ost, pkt->size); + ost->packets_encoded++; + output_packet(of, pkt, ost, 0); /* if two pass, output log */ diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 9f0c093e34..7326193caf 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -551,6 +551,8 @@ typedef struct OutputStream { // number of frames/samples sent to the encoder uint64_t frames_encoded; uint64_t samples_encoded; + // number of packets received from the encoder + uint64_t packets_encoded; /* packet quality factor */ int quality; From patchwork Wed May 11 08:16:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 35725 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp3781104pzb; Wed, 11 May 2022 01:18:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXHPXIkIIk1eWX57WnJVYX8+c2RHesBdmH6iRCpxS4wILG6cglHo1dxIGC/D0AY5ft650y X-Received: by 2002:a17:907:7e8f:b0:6f5:fc1:e8af with SMTP id qb15-20020a1709077e8f00b006f50fc1e8afmr22708761ejc.20.1652257081405; Wed, 11 May 2022 01:18:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652257081; cv=none; d=google.com; s=arc-20160816; b=zdoBZfpjXbRej5myG5JUB2c1HpTJvnn8ruLGYbWyVwsSbBC94XYcaK8Yk3Wa+i5nMw 9x1uZkKqtx0Ty9bVVpyQZlc0ebVZq9ycXgzymNhkaif62p/J6SlmBipjlmj80YtFOjcI AlB9yK3opEhbLZuYXIpYEdDTy/c4ZLhdYSo9Oy60APUSpcbe5YBqn+eD+a8ng1Gn0VCx G9vxry57nEoAsqtiZLePAjjzvAZQb1a3l9GrFeNKZLaUlOg1iBbpVV4ycWd7IjRSIekV i+6LM3SPPi3T2eGuYeAHmnWdImNF8DekzLoLN2KIICMG76l3T/otJrJFMtzL/yizYWqs 6ArQ== 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=8XxP3fqvoQ6gwTrUkArqXIiL+UQyBT0x0wKxjhmy+Uo=; b=p+XTdqeH8qBitYJ52nZ4jNDsCLiQFDJp0MmzeInZNoHE517J23bUo4eA1XmIQhDN90 X/IEK4ynv+PoPDYbk7VuN0ZhLEFYNLKsTwv/zxQM664YWHpmjSbxaV48mt4+hOJlgjkF YlsbGUN8q1K0bIfvVZiFQFQx3CUVFZMkjOuudtYqLdruGfrjZ78sXU20JmAXP90wE46h 81iqYeeWqXZJUNsFJz/EvcCSyr/jRfZjTfsu9HWuOH4sIalenG7jI8TppG0lqHxfYdRK q0PdLHlMHlsSHNhvaaLpY86yK8A3sD+LEjXc/h6F8lO4w+P7SdidtS2tELF3pkdoUtdl RSQw== 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 c69-20020a509fcb000000b0041d81347011si1479564edf.382.2022.05.11.01.18.00; Wed, 11 May 2022 01:18:01 -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 D033F68B38D; Wed, 11 May 2022 11:17:20 +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 7935068B3BB for ; Wed, 11 May 2022 11:17:11 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id DC57D24017E for ; Wed, 11 May 2022 10:17:10 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id A5WsNwki04jK for ; Wed, 11 May 2022 10:17:10 +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 B1330240506 for ; Wed, 11 May 2022 10:17:07 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id B2E0C3A0836; Wed, 11 May 2022 10:17:02 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 May 2022 10:16:52 +0200 Message-Id: <20220511081654.15127-7-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 7/9] fftools/ffmpeg: stop using av_stream_get_end_pts() in 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: mYbZB86NRh/K It retrieves libavformat's internal dts value (contrary to the function's name), which is not only incorrect in general, but also unnecessary because we can access the packet directly. --- fftools/ffmpeg.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index c15d1486dd..5983c57410 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -835,7 +835,7 @@ static double psnr(double d) return -10.0 * log10(d); } -static void do_video_stats(OutputStream *ost, int frame_size) +static void do_video_stats(OutputStream *ost, const AVPacket *pkt) { AVCodecContext *enc; int frame_number; @@ -863,13 +863,13 @@ static void do_video_stats(OutputStream *ost, int frame_size) if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR)) fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0))); - fprintf(vstats_file,"f_size= %6d ", frame_size); + fprintf(vstats_file,"f_size= %6d ", pkt->size); /* compute pts value */ - ti1 = av_stream_get_end_pts(ost->st) * av_q2d(ost->st->time_base); + ti1 = pkt->dts * av_q2d(ost->mux_timebase); if (ti1 < 0.01) ti1 = 0.01; - bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0; + bitrate = (pkt->size * 8) / av_q2d(enc->time_base) / 1000.0; avg_bitrate = (double)(ost->data_size * 8) / ti1 / 1000.0; fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", (double)ost->data_size / 1024, ti1, bitrate, avg_bitrate); @@ -943,7 +943,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) } if (enc->codec_type == AVMEDIA_TYPE_VIDEO && vstats_filename) - do_video_stats(ost, pkt->size); + do_video_stats(ost, pkt); ost->packets_encoded++; From patchwork Wed May 11 08:16:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 35727 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp3781230pzb; Wed, 11 May 2022 01:18:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkVCzrEg0is8mQ2x+vfJ0rF8PlYb0x+ZSZUlptxwXNV5sKy+w9XRdQw2HvmuO1/y5im5bn X-Received: by 2002:a17:907:94c4:b0:6f9:f69f:2fd5 with SMTP id dn4-20020a17090794c400b006f9f69f2fd5mr14598680ejc.347.1652257103183; Wed, 11 May 2022 01:18:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652257103; cv=none; d=google.com; s=arc-20160816; b=ECNEFKKIferXvu+RUH4HDHt8lOWNHdGri/ONNcJnXU0Qe4gbCU8+xN+xG04yy0y64a kKoCAhu8L5Vnf7vKAcnefmZRdKUQFXGohSY6vrL53NhQqcFzjWmfCBQWXWmwPT7ZW8CN gXpAK+NPRoV7+NzPR1Yb1TP8W42a7sDOlZ9qiGyyzbR4JHUm7hHlNCrKkrl/sUlKMZUw QhNECni6iCDL6yeUozz0oG5YP36+HdGIPK1x9W78HZIfZup0K9MX41mhP5VEuV+0cwRV 5nV/j83R5TrKsV7iKyMG50ksFU3nmB7idXC/td7IgdRy8KHLQZApGCQWnxrI/n5IgODf Ay2A== 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=OcLMTptq8OEBnMJ635L0GbloWKeWyFQL+BOljKqChAY=; b=iVYS4271EJVcQyodqvwkAwL3sPQEMXqW/sT3zJd2K8XuTuMSD2kKWJB1QlPf+zxlYM 5G4R+A50qrgyg1ZOJ9Htf6hDirhEpY+6/BZdWoZRDjZCl5o2MC7sgjbLKPaSKpRNqn6V Fe2sIWYFC4n4eWEr5PzJvoqTkABGuJrfi1Rg9ancIeoI5tC7By8gqP6ljA1tMC5IRRIY TaAAnf15pL2vc8UVc2P5xY1ZSCBeJmgiDM1qwXGYQSXa+ScnCJFkzCbe3aZHbv8ctBZv 9To8ZKkLt1BVhpKfnYHhoxiN84Txr0NWUwt5ruGToaA1A4nXzmJwt7e89csKzXTzK8e5 cveA== 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 m11-20020a056402050b00b0041d9b15148asi1514131edv.531.2022.05.11.01.18.22; Wed, 11 May 2022 01:18:23 -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 1F0E368B3C0; Wed, 11 May 2022 11:17:23 +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 4346868B419 for ; Wed, 11 May 2022 11:17:15 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 638142404FE for ; Wed, 11 May 2022 10:17:11 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 0Ifuvsclon1X for ; Wed, 11 May 2022 10:17:10 +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 C56B3240507 for ; Wed, 11 May 2022 10:17:07 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id B54813A0837; Wed, 11 May 2022 10:17:02 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 May 2022 10:16:53 +0200 Message-Id: <20220511081654.15127-8-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 8/9] fftools/ffmpeg: merge variable declaration and initialization 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: Jn5MWWpqsaTT --- fftools/ffmpeg.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 5983c57410..fe7c37db62 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -837,7 +837,7 @@ static double psnr(double d) static void do_video_stats(OutputStream *ost, const AVPacket *pkt) { - AVCodecContext *enc; + AVCodecContext *enc = ost->enc_ctx; int frame_number; double ti1, bitrate, avg_bitrate; @@ -850,7 +850,6 @@ static void do_video_stats(OutputStream *ost, const AVPacket *pkt) } } - enc = ost->enc_ctx; frame_number = ost->packets_encoded; if (vstats_version <= 1) { fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, 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");