avcodec/mpeg12dec: Recalculate SAR unconditionally

Fixes Ticket4161

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2015-01-02 02:33:34 +01:00
parent aeb36fd207
commit 1010b36d86
1 changed files with 44 additions and 40 deletions

View File

@ -1273,55 +1273,10 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
uint8_t old_permutation[64]; uint8_t old_permutation[64];
int ret; int ret;
if ((s1->mpeg_enc_ctx_allocated == 0) ||
avctx->coded_width != s->width ||
avctx->coded_height != s->height ||
s1->save_width != s->width ||
s1->save_height != s->height ||
s1->save_aspect_info != s->aspect_ratio_info ||
(s1->save_progressive_seq != s->progressive_sequence && FFALIGN(s->height, 16) != FFALIGN(s->height, 32)) ||
0) {
if (s1->mpeg_enc_ctx_allocated) {
ParseContext pc = s->parse_context;
s->parse_context.buffer = 0;
ff_mpv_common_end(s);
s->parse_context = pc;
s1->mpeg_enc_ctx_allocated = 0;
}
ret = ff_set_dimensions(avctx, s->width, s->height);
if (ret < 0)
return ret;
if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->bit_rate) {
avctx->rc_max_rate = s->bit_rate;
} else if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO && s->bit_rate &&
(s->bit_rate != 0x3FFFF*400 || s->vbv_delay != 0xFFFF)) {
avctx->bit_rate = s->bit_rate;
}
s1->save_aspect_info = s->aspect_ratio_info;
s1->save_width = s->width;
s1->save_height = s->height;
s1->save_progressive_seq = s->progressive_sequence;
/* low_delay may be forced, in this case we will have B-frames
* that behave like P-frames. */
avctx->has_b_frames = !s->low_delay;
if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) { if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
// MPEG-1 fps
avctx->framerate = ff_mpeg12_frame_rate_tab[s->frame_rate_index];
// MPEG-1 aspect // MPEG-1 aspect
avctx->sample_aspect_ratio = av_d2q(1.0 / ff_mpeg1_aspect[s->aspect_ratio_info], 255); avctx->sample_aspect_ratio = av_d2q(1.0 / ff_mpeg1_aspect[s->aspect_ratio_info], 255);
avctx->ticks_per_frame = 1;
} else { // MPEG-2 } else { // MPEG-2
// MPEG-2 fps
av_reduce(&s->avctx->framerate.num,
&s->avctx->framerate.den,
ff_mpeg12_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num,
ff_mpeg12_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den,
1 << 30);
avctx->ticks_per_frame = 2;
// MPEG-2 aspect // MPEG-2 aspect
if (s->aspect_ratio_info > 1) { if (s->aspect_ratio_info > 1) {
AVRational dar = AVRational dar =
@ -1362,6 +1317,55 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
ff_set_sar(s->avctx, s->avctx->sample_aspect_ratio); ff_set_sar(s->avctx, s->avctx->sample_aspect_ratio);
if ((s1->mpeg_enc_ctx_allocated == 0) ||
avctx->coded_width != s->width ||
avctx->coded_height != s->height ||
s1->save_width != s->width ||
s1->save_height != s->height ||
s1->save_aspect_info != s->aspect_ratio_info ||
(s1->save_progressive_seq != s->progressive_sequence && FFALIGN(s->height, 16) != FFALIGN(s->height, 32)) ||
0) {
if (s1->mpeg_enc_ctx_allocated) {
ParseContext pc = s->parse_context;
s->parse_context.buffer = 0;
ff_mpv_common_end(s);
s->parse_context = pc;
s1->mpeg_enc_ctx_allocated = 0;
}
ret = ff_set_dimensions(avctx, s->width, s->height);
if (ret < 0)
return ret;
if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->bit_rate) {
avctx->rc_max_rate = s->bit_rate;
} else if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO && s->bit_rate &&
(s->bit_rate != 0x3FFFF*400 || s->vbv_delay != 0xFFFF)) {
avctx->bit_rate = s->bit_rate;
}
s1->save_aspect_info = s->aspect_ratio_info;
s1->save_width = s->width;
s1->save_height = s->height;
s1->save_progressive_seq = s->progressive_sequence;
/* low_delay may be forced, in this case we will have B-frames
* that behave like P-frames. */
avctx->has_b_frames = !s->low_delay;
if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
// MPEG-1 fps
avctx->framerate = ff_mpeg12_frame_rate_tab[s->frame_rate_index];
avctx->ticks_per_frame = 1;
} else { // MPEG-2
// MPEG-2 fps
av_reduce(&s->avctx->framerate.num,
&s->avctx->framerate.den,
ff_mpeg12_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num,
ff_mpeg12_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den,
1 << 30);
avctx->ticks_per_frame = 2;
} // MPEG-2
avctx->pix_fmt = mpeg_get_pixelformat(avctx); avctx->pix_fmt = mpeg_get_pixelformat(avctx);
setup_hwaccel_for_pixfmt(avctx); setup_hwaccel_for_pixfmt(avctx);