[FFmpeg-devel] [BUMP PATCH 2/2] avutil/frame: change AVFrame.*_picture_number to int64_t
Marton Balint
cus at passwd.hu
Fri Jan 27 00:46:49 EET 2023
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 use 64 bit
values for them.
We also change MpegEncContext picture number members to 64 bit in this change,
because mpeg(ish) decoding/encoding usually use and set AVFrame attributes
based on the MpegEncContext picture number members, so it makes sense to use
the same type. Same is true for H264Context.coded_picture_number.
There are also a couple of printf() format string updates, which is the
necessary evil of this change, because API users need to do this as well. The
alternative would be to introduce separate 64-bit counters for the int64 type,
and keep the two values in sync, but that would be also quite ugly.
So let's do what we already did for AVFormatContext.bit_rate some years ago and
simply change the type.
Signed-off-by: Marton Balint <cus at passwd.hu>
---
doc/APIchanges | 4 ++++
doc/examples/demuxing_decoding.c | 2 +-
libavcodec/flvdec.c | 2 +-
libavcodec/h264dec.h | 2 +-
libavcodec/mpeg12enc.c | 2 +-
libavcodec/mpegvideo.h | 6 +++---
libavcodec/mpegvideo_enc.c | 6 +++---
libavcodec/ratecontrol.c | 6 +++---
libavutil/frame.h | 4 ++--
9 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index cdd407799a..b8dd6fc6ec 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,10 @@ libavutil: 2021-04-27
API changes, most recent first:
+2023-xx-xx - xxxxxxxxxx - lavu 58.0.100 - frame.h
+ AVFrame.coded_picture_number and AVFrame.display_picture_number was changed
+ to 64bit, make sure you update any printf() or other type sensitive code
+
2023-xx-xx - xxxxxxxxxx - lavc 60.0.100 - avcodec.h
AVCodecContext.frame_number was changed to 64bit, make sure you update any
printf() or other type sensitive code
diff --git a/doc/examples/demuxing_decoding.c b/doc/examples/demuxing_decoding.c
index 999a78db0d..b16436b55b 100644
--- a/doc/examples/demuxing_decoding.c
+++ b/doc/examples/demuxing_decoding.c
@@ -73,7 +73,7 @@ static int output_video_frame(AVFrame *frame)
return -1;
}
- printf("video_frame n:%d coded_n:%d\n",
+ printf("video_frame n:%d coded_n:%"PRId64"\n",
video_frame_count++, frame->coded_picture_number);
/* copy decoded frame to destination buffer:
diff --git a/libavcodec/flvdec.c b/libavcodec/flvdec.c
index 09fefd3d1c..19fb23563d 100644
--- a/libavcodec/flvdec.c
+++ b/libavcodec/flvdec.c
@@ -103,7 +103,7 @@ int ff_flv_decode_picture_header(MpegEncContext *s)
s->avctx->sample_aspect_ratio= (AVRational){1,2};
if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
- av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
+ av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%"PRId64"\n",
s->droppable ? 'D' : av_get_picture_type_char(s->pict_type),
s->h263_flv - 1, s->qscale, s->picture_number);
}
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 9a1ec1bace..dd3f06a03b 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -354,7 +354,7 @@ typedef struct H264Context {
int chroma_x_shift, chroma_y_shift;
int droppable;
- int coded_picture_number;
+ int64_t coded_picture_number;
int context_initialized;
int flags;
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index a6663a158b..690c401432 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -76,7 +76,7 @@ typedef struct MPEG12EncContext {
AVRational frame_rate_ext;
unsigned frame_rate_index;
- int gop_picture_number; ///< index of the first picture of a GOP based on fake_pic_num
+ int64_t gop_picture_number; ///< index of the first picture of a GOP based on fake_pic_num
int64_t timecode_frame_start; ///< GOP timecode frame start number, in non drop frame format
AVTimecode tc; ///< timecode context
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 42275953b9..3e932d3ab5 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -114,9 +114,9 @@ typedef struct MpegEncContext {
/* sequence parameters */
int context_initialized;
- int input_picture_number; ///< used to set pic->display_picture_number, should not be used for/by anything else
- int coded_picture_number; ///< used to set pic->coded_picture_number, should not be used for/by anything else
- int picture_number; //FIXME remove, unclear definition
+ int64_t input_picture_number; ///< used to set pic->display_picture_number, should not be used for/by anything else
+ int64_t coded_picture_number; ///< used to set pic->coded_picture_number, should not be used for/by anything else
+ int64_t picture_number; //FIXME remove, unclear definition
int extradata_parsed;
int picture_in_gop_number; ///< 0-> first pic in gop, ...
int mb_width, mb_height; ///< number of MBs horizontally & vertically
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index bb101612e5..d2becc7003 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1095,8 +1095,8 @@ static int alloc_picture(MpegEncContext *s, Picture *pic, int shared)
static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg)
{
Picture *pic = NULL;
- int64_t pts;
- int i, display_picture_number = 0, ret;
+ int64_t pts, display_picture_number = 0;
+ int i, ret;
int encoding_delay = s->max_b_frames ? s->max_b_frames
: (s->low_delay ? 0 : 1);
int flush_offset = 1;
@@ -1484,7 +1484,7 @@ static int select_input_picture(MpegEncContext *s)
if (s->avctx->flags & AV_CODEC_FLAG_PASS2) {
for (i = 0; i < s->max_b_frames + 1; i++) {
- int pict_num = s->input_picture[0]->f->display_picture_number + i;
+ int64_t pict_num = s->input_picture[0]->f->display_picture_number + i;
if (pict_num >= s->rc_context.num_entries)
break;
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 4829172c2c..299d82223c 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -37,7 +37,7 @@
void ff_write_pass1_stats(MpegEncContext *s)
{
snprintf(s->avctx->stats_out, 256,
- "in:%d out:%d type:%d q:%d itex:%d ptex:%d mv:%d misc:%d "
+ "in:%"PRId64" out:%"PRId64" type:%d q:%d itex:%d ptex:%d mv:%d misc:%d "
"fcode:%d bcode:%d mc-var:%"PRId64" var:%"PRId64" icount:%d skipcount:%d hbits:%d;\n",
s->current_picture_ptr->f->display_picture_number,
s->current_picture_ptr->f->coded_picture_number,
@@ -571,7 +571,7 @@ av_cold int ff_rate_control_init(MpegEncContext *s)
p = s->avctx->stats_in;
for (i = 0; i < rcc->num_entries - s->max_b_frames; i++) {
RateControlEntry *rce;
- int picture_number;
+ int64_t picture_number;
int e;
char *next;
@@ -580,7 +580,7 @@ av_cold int ff_rate_control_init(MpegEncContext *s)
(*next) = 0; // sscanf is unbelievably slow on looong strings // FIXME copy / do not write
next++;
}
- e = sscanf(p, " in:%d ", &picture_number);
+ e = sscanf(p, " in:%"PRId64" ", &picture_number);
av_assert0(picture_number >= 0);
av_assert0(picture_number < rcc->num_entries);
diff --git a/libavutil/frame.h b/libavutil/frame.h
index bbe909ee2d..da06a2f868 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -454,11 +454,11 @@ typedef struct AVFrame {
/**
* picture number in bitstream order
*/
- int coded_picture_number;
+ int64_t coded_picture_number;
/**
* picture number in display order
*/
- int display_picture_number;
+ int64_t display_picture_number;
/**
* quality (between 1 (good) and FF_LAMBDA_MAX (bad))
--
2.35.3
More information about the ffmpeg-devel
mailing list