1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

avcodec/mpegvideo_enc: do not use AVFrame.*_picture_number for encoding

Move these fields to MPEGPicture instead and use that.

Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
Marton Balint 2023-01-27 23:13:05 +01:00
parent 817141c562
commit 8e2c124904
6 changed files with 23 additions and 14 deletions

View File

@ -419,10 +419,10 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
/* time code: we must convert from the real frame rate to a
* fake MPEG frame rate in case of low frame rate */
fps = (framerate.num + framerate.den / 2) / framerate.den;
time_code = s->current_picture_ptr->f->coded_picture_number +
time_code = s->current_picture_ptr->coded_picture_number +
mpeg12->timecode_frame_start;
mpeg12->gop_picture_number = s->current_picture_ptr->f->coded_picture_number;
mpeg12->gop_picture_number = s->current_picture_ptr->coded_picture_number;
av_assert0(mpeg12->drop_frame_timecode == !!(mpeg12->tc.flags & AV_TIMECODE_FLAG_DROPFRAME));
if (mpeg12->drop_frame_timecode)

View File

@ -332,6 +332,8 @@ void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic)
pic->needs_realloc = 0;
pic->reference = 0;
pic->shared = 0;
pic->display_picture_number = 0;
pic->coded_picture_number = 0;
}
int ff_update_picture_tables(Picture *dst, const Picture *src)
@ -397,6 +399,8 @@ int ff_mpeg_ref_picture(AVCodecContext *avctx, Picture *dst, Picture *src)
dst->needs_realloc = src->needs_realloc;
dst->reference = src->reference;
dst->shared = src->shared;
dst->display_picture_number = src->display_picture_number;
dst->coded_picture_number = src->coded_picture_number;
return 0;
fail:

View File

@ -76,6 +76,9 @@ typedef struct Picture {
int reference;
int shared;
int display_picture_number;
int coded_picture_number;
} Picture;
/**

View File

@ -1219,7 +1219,7 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg)
if (ret < 0)
return ret;
pic->f->display_picture_number = display_picture_number;
pic->display_picture_number = display_picture_number;
pic->f->pts = pts; // we set this here to avoid modifying pic_arg
} else {
/* Flushing: When we have not received enough input frames,
@ -1477,14 +1477,14 @@ static int select_input_picture(MpegEncContext *s)
!s->next_picture_ptr || s->intra_only) {
s->reordered_input_picture[0] = s->input_picture[0];
s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I;
s->reordered_input_picture[0]->f->coded_picture_number =
s->reordered_input_picture[0]->coded_picture_number =
s->coded_picture_number++;
} else {
int b_frames = 0;
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;
int pict_num = s->input_picture[0]->display_picture_number + i;
if (pict_num >= s->rc_context.num_entries)
break;
@ -1563,13 +1563,13 @@ static int select_input_picture(MpegEncContext *s)
s->reordered_input_picture[0] = s->input_picture[b_frames];
if (s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I)
s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P;
s->reordered_input_picture[0]->f->coded_picture_number =
s->reordered_input_picture[0]->coded_picture_number =
s->coded_picture_number++;
for (i = 0; i < b_frames; i++) {
s->reordered_input_picture[i + 1] = s->input_picture[i];
s->reordered_input_picture[i + 1]->f->pict_type =
AV_PICTURE_TYPE_B;
s->reordered_input_picture[i + 1]->f->coded_picture_number =
s->reordered_input_picture[i + 1]->coded_picture_number =
s->coded_picture_number++;
}
}
@ -1604,6 +1604,8 @@ no_output_pic:
ret = av_frame_copy_props(pic->f, s->reordered_input_picture[0]->f);
if (ret < 0)
return ret;
pic->coded_picture_number = s->reordered_input_picture[0]->coded_picture_number;
pic->display_picture_number = s->reordered_input_picture[0]->display_picture_number;
/* mark us unused / free shared pic */
av_frame_unref(s->reordered_input_picture[0]->f);
@ -1618,7 +1620,8 @@ no_output_pic:
s->new_picture->data[i] += INPLACE_OFFSET;
}
}
s->picture_number = s->new_picture->display_picture_number;
s->picture_number = s->current_picture_ptr->display_picture_number;
}
return 0;
}
@ -1954,7 +1957,7 @@ vbv_retry:
pkt->pts = s->current_picture.f->pts;
pkt->duration = s->current_picture.f->duration;
if (!s->low_delay && s->pict_type != AV_PICTURE_TYPE_B) {
if (!s->current_picture.f->coded_picture_number)
if (!s->current_picture.coded_picture_number)
pkt->dts = pkt->pts - s->dts_delta;
else
pkt->dts = s->reordered_pts;

View File

@ -39,8 +39,8 @@ 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 "
"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,
s->current_picture_ptr->display_picture_number,
s->current_picture_ptr->coded_picture_number,
s->pict_type,
s->current_picture.f->quality,
s->i_tex_bits,

View File

@ -1856,13 +1856,12 @@ redo_frame:
ff_snow_release_buffer(avctx);
s->current_picture->coded_picture_number = avctx->frame_num;
s->current_picture->pict_type = pic->pict_type;
s->current_picture->quality = pic->quality;
s->m.frame_bits = 8*(s->c.bytestream - s->c.bytestream_start);
s->m.p_tex_bits = s->m.frame_bits - s->m.misc_bits - s->m.mv_bits;
s->m.current_picture.f->display_picture_number =
s->m.current_picture.f->coded_picture_number = avctx->frame_num;
s->m.current_picture.display_picture_number =
s->m.current_picture.coded_picture_number = avctx->frame_num;
s->m.current_picture.f->quality = pic->quality;
s->m.total_bits += 8*(s->c.bytestream - s->c.bytestream_start);
if(s->pass1_rc)