From patchwork Mon Jun 20 18:33:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 36355 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1807348pzb; Mon, 20 Jun 2022 11:33:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tGt97XkwzcEvWvgIX5ZkOqRNpt6BiD7qntgH8AKxpD3i9g4nh4dlNqtLwNS2aSjAoI9LCw X-Received: by 2002:a05:6402:254e:b0:431:35df:5e38 with SMTP id l14-20020a056402254e00b0043135df5e38mr30760804edb.385.1655750034146; Mon, 20 Jun 2022 11:33:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655750034; cv=none; d=google.com; s=arc-20160816; b=XnvVjnW6hcabve7oksGC8alWLoTovGXAnXa78AaQ6ymbkq4XyNoHtyn7Hn5phfvuvM y52uIscQrWgJTXGhV7gOD0UiYYLKP99GhTuKTOlb0kwT94ehml52I0CpUn3c9soP0Fgz PrvDVYguoqVyH793buxfyfq68y3CuKW/QvwMOxAvm1eDePmmORO0ZUcwTMzkyEaS/cP/ wfVRIL1sQYBIdisCEGgYJXru88gi4t8AW43pML3GbUFEqHzKDsk8brI48KfhzD6zQV7P fIysjWH4+r940cAKh+65ryZvxDDHzw8p/TWV4yQBpc2iHnKOEcL/mt0fY3dAVLwJ50ke KyfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=fzgUDU34TQQgovkRpZTkkLsCujeKVjV7BqCgKxG86ug=; b=h9F4N9icpjk99+DOtmCKAH6Zuu45ZnPcQqoUExDw4fPimeMVC7tQMvRDEQDtyyQNbZ 0v3GzV3W3dNyuKbWtRJjq70lsO0SOaXSLHxKFK2/yqfqhWfRfx7MiLIKh9J7sSH/fter pX/GuW1vR0UJctJZ6iPPhidt5FNoakALHDUnNlOp5LRcqqcIlYdGZa1Jkt9wRWDtPipr FColInAX4DO//ulERBy8avJYXDMpwZODLI1N0U84g0rdCgtzj8Q2YHROq3gldLS9hGBt Tl0E5kKUKhG8lNdKQh5yzIqgISBzp/6uub40YYIdIQWseIk7UZeUCqY5jqoiZOPJzup2 gd1A== 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 cs2-20020a0564020c4200b004355e601557si10913971edb.170.2022.06.20.11.33.52; Mon, 20 Jun 2022 11:33:54 -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 6A9E768B613; Mon, 20 Jun 2022 21:33:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D4B6B68B201 for ; Mon, 20 Jun 2022 21:33:41 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 336A9E745A; Mon, 20 Jun 2022 20:33:38 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PGiAH5CV5_sb; Mon, 20 Jun 2022 20:33:36 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 50D62E6F03; Mon, 20 Jun 2022 20:33:35 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Mon, 20 Jun 2022 20:33:31 +0200 Message-Id: <20220620183331.721-1-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] fftools/ffmpeg: change frame counters to 64 bit 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 Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: JJZrmRpihdkq Frame counters can overflow relatively easily (INT_MAX number of frames is slightly more than 1 year for 60 fps content), so make sure we are always using 64 bit values for them. A live stream can easily run for more than a year and the framedup logic breaks on an overflow. Signed-off-by: Marton Balint --- fftools/ffmpeg.c | 38 +++++++++++++++++++------------------- fftools/ffmpeg.h | 6 +++--- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 09caa3e3c4..e7384f052a 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -131,9 +131,9 @@ static BenchmarkTimeStamps get_benchmark_time_stamps(void); static int64_t getmaxrss(void); static int ifilter_has_all_input_formats(FilterGraph *fg); -static int nb_frames_dup = 0; -static unsigned dup_warning = 1000; -static int nb_frames_drop = 0; +static int64_t nb_frames_dup = 0; +static uint64_t dup_warning = 1000; +static int64_t nb_frames_drop = 0; static int64_t decode_error_stat[2]; unsigned nb_output_dumped = 0; @@ -839,7 +839,7 @@ static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write const uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, NULL); AVCodecContext *enc = ost->enc_ctx; - int frame_number; + int64_t frame_number; double ti1, bitrate, avg_bitrate; ost->quality = sd ? AV_RL32(sd) : -1; @@ -866,10 +866,10 @@ static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write frame_number = ost->packets_encoded; if (vstats_version <= 1) { - fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, + fprintf(vstats_file, "frame= %5"PRId64" 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, + fprintf(vstats_file, "out= %2d st= %2d frame= %5"PRId64" q= %2.1f ", ost->file_index, ost->index, frame_number, ost->quality / (float)FF_QP2LAMBDA); } @@ -1082,7 +1082,7 @@ static void do_video_out(OutputFile *of, int ret; AVCodecContext *enc = ost->enc_ctx; AVRational frame_rate; - int nb_frames, nb0_frames, i; + int64_t nb_frames, nb0_frames, i; double delta, delta0; double duration = 0; double sync_ipts = AV_NOPTS_VALUE; @@ -1152,7 +1152,7 @@ static void do_video_out(OutputFile *of, } else if (delta < -1.1) nb_frames = 0; else if (delta > 1.1) { - nb_frames = lrintf(delta); + nb_frames = llrintf(delta); if (delta0 > 1.1) nb0_frames = llrintf(delta0 - 0.6); } @@ -1188,19 +1188,19 @@ static void do_video_out(OutputFile *of, if (nb0_frames == 0 && ost->last_dropped) { nb_frames_drop++; av_log(NULL, AV_LOG_VERBOSE, - "*** dropping frame %d from stream %d at ts %"PRId64"\n", + "*** dropping frame %"PRId64" from stream %d at ts %"PRId64"\n", ost->frame_number, ost->st->index, ost->last_frame->pts); } if (nb_frames > (nb0_frames && ost->last_dropped) + (nb_frames > nb0_frames)) { if (nb_frames > dts_error_threshold * 30) { - av_log(NULL, AV_LOG_ERROR, "%d frame duplication too large, skipping\n", nb_frames - 1); + av_log(NULL, AV_LOG_ERROR, "%"PRId64" frame duplication too large, skipping\n", nb_frames - 1); nb_frames_drop++; return; } nb_frames_dup += nb_frames - (nb0_frames && ost->last_dropped) - (nb_frames > nb0_frames); - av_log(NULL, AV_LOG_VERBOSE, "*** %d dup!\n", nb_frames - 1); + av_log(NULL, AV_LOG_VERBOSE, "*** %"PRId64" dup!\n", nb_frames - 1); if (nb_frames_dup > dup_warning) { - av_log(NULL, AV_LOG_WARNING, "More than %d frames duplicated\n", dup_warning); + av_log(NULL, AV_LOG_WARNING, "More than %"PRIu64" frames duplicated\n", dup_warning); dup_warning *= 10; } } @@ -1511,7 +1511,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti AVFormatContext *oc; int64_t total_size; AVCodecContext *enc; - int frame_number, vid, i; + int vid, i; double bitrate; double speed; int64_t pts = INT64_MIN + 1; @@ -1562,12 +1562,12 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti } if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { float fps; + int64_t frame_number = ost->frame_number; - frame_number = ost->frame_number; fps = t > 1 ? frame_number / t : 0; - av_bprintf(&buf, "frame=%5d fps=%3.*f q=%3.1f ", + av_bprintf(&buf, "frame=%5"PRId64" fps=%3.*f q=%3.1f ", frame_number, fps < 9.95, fps, q); - av_bprintf(&buf_script, "frame=%d\n", frame_number); + av_bprintf(&buf_script, "frame=%"PRId64"\n", frame_number); av_bprintf(&buf_script, "fps=%.2f\n", fps); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); @@ -1671,9 +1671,9 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti } if (nb_frames_dup || nb_frames_drop) - av_bprintf(&buf, " dup=%d drop=%d", nb_frames_dup, nb_frames_drop); - av_bprintf(&buf_script, "dup_frames=%d\n", nb_frames_dup); - av_bprintf(&buf_script, "drop_frames=%d\n", nb_frames_drop); + av_bprintf(&buf, " dup=%"PRId64" drop=%"PRId64, nb_frames_dup, nb_frames_drop); + av_bprintf(&buf_script, "dup_frames=%"PRId64"\n", nb_frames_dup); + av_bprintf(&buf_script, "drop_frames=%"PRId64"\n", nb_frames_drop); if (speed < 0) { av_bprintf(&buf, " speed=N/A"); diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 69a368b8d1..99d31c346e 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -458,7 +458,7 @@ typedef struct OutputStream { int source_index; /* InputStream index */ AVStream *st; /* stream in the output file */ int encoding_needed; /* true if encoding needed for this stream */ - int frame_number; + int64_t frame_number; /* input pts and corresponding output pts for A/V sync */ struct InputStream *sync_ist; /* input stream to sync against */ @@ -481,8 +481,8 @@ typedef struct OutputStream { AVFrame *filtered_frame; AVFrame *last_frame; AVPacket *pkt; - int last_dropped; - int last_nb0_frames[3]; + int64_t last_dropped; + int64_t last_nb0_frames[3]; void *hwaccel_ctx;