From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 7DBFD432DC for ; Mon, 27 Jun 2022 18:46:32 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 912DD68B8CD; Mon, 27 Jun 2022 21:46:30 +0300 (EEST) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 54E2168B85A for ; Mon, 27 Jun 2022 21:46:23 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 2BF6DE744B for ; Mon, 27 Jun 2022 20:46:23 +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 UmjlNreGB1Zj for ; Mon, 27 Jun 2022 20:45:54 +0200 (CEST) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id 25A8CE7448 for ; Mon, 27 Jun 2022 20:45:54 +0200 (CEST) Date: Mon, 27 Jun 2022 20:45:54 +0200 (CEST) From: Marton Balint To: FFmpeg development discussions and patches In-Reply-To: <20220620183331.721-1-cus@passwd.hu> Message-ID: References: <20220620183331.721-1-cus@passwd.hu> MIME-Version: 1.0 Subject: Re: [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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Mon, 20 Jun 2022, Marton Balint wrote: > 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. Applied. Regards, Marton > > 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; > > -- > 2.35.3 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".