Commit bf097674 authored by Jean-Paul Saman's avatar Jean-Paul Saman

avcodec: correct framerate calculation

VLC frequently reports a framerate that is twice the actual framerate for interlaced content.
Correctly take the information from ffmpeg in account when determining the framerate. It now
correctly reports the actual framerate of the movie.
parent dfee5996
...@@ -98,7 +98,6 @@ struct decoder_sys_t ...@@ -98,7 +98,6 @@ struct decoder_sys_t
/* Hack to force display of still pictures */ /* Hack to force display of still pictures */
bool b_first_frame; bool b_first_frame;
/* */ /* */
#if LIBAVCODEC_VERSION_MAJOR < 54 #if LIBAVCODEC_VERSION_MAJOR < 54
AVPaletteControl palette; AVPaletteControl palette;
...@@ -198,8 +197,14 @@ static inline picture_t *ffmpeg_NewPictBuf( decoder_t *p_dec, ...@@ -198,8 +197,14 @@ static inline picture_t *ffmpeg_NewPictBuf( decoder_t *p_dec,
} }
else if( p_context->time_base.num > 0 && p_context->time_base.den > 0 ) else if( p_context->time_base.num > 0 && p_context->time_base.den > 0 )
{ {
p_dec->fmt_out.video.i_frame_rate = p_context->time_base.den; p_dec->fmt_out.video.i_frame_rate = p_context->time_base.num *
p_dec->fmt_out.video.i_frame_rate_base = p_context->time_base.num; __MAX( p_context->ticks_per_frame, 1 );
p_dec->fmt_out.video.i_frame_rate_base = p_context->time_base.den;
vlc_ureduce(&p_dec->fmt_out.video.i_frame_rate,
&p_dec->fmt_out.video.i_frame_rate_base,
p_dec->fmt_out.video.i_frame_rate,
p_dec->fmt_out.video.i_frame_rate_base, 0);
} }
return decoder_NewPicture( p_dec ); return decoder_NewPicture( p_dec );
...@@ -400,7 +405,6 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context, ...@@ -400,7 +405,6 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
p_dec->i_extra_picture_buffers = 2 * p_sys->p_context->thread_count; p_dec->i_extra_picture_buffers = 2 * p_sys->p_context->thread_count;
#endif #endif
/* ***** misc init ***** */ /* ***** misc init ***** */
p_sys->i_pts = VLC_TS_INVALID; p_sys->i_pts = VLC_TS_INVALID;
p_sys->b_has_b_frames = false; p_sys->b_has_b_frames = false;
...@@ -704,6 +708,7 @@ picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) ...@@ -704,6 +708,7 @@ picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
i_pts = i_ts; i_pts = i_ts;
} }
} }
if( i_pts <= VLC_TS_INVALID ) if( i_pts <= VLC_TS_INVALID )
i_pts = p_sys->i_pts; i_pts = p_sys->i_pts;
...@@ -713,15 +718,16 @@ picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) ...@@ -713,15 +718,16 @@ picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
if( p_sys->i_pts > VLC_TS_INVALID ) if( p_sys->i_pts > VLC_TS_INVALID )
{ {
/* interpolate the next PTS */ /* interpolate the next PTS */
if( p_dec->fmt_in.video.i_frame_rate > 0 && if( p_dec->fmt_out.video.i_frame_rate > 0 &&
p_dec->fmt_in.video.i_frame_rate_base > 0 ) p_dec->fmt_out.video.i_frame_rate_base > 0 )
{ {
p_sys->i_pts += INT64_C(1000000) * p_sys->i_pts += INT64_C(1000000) *
(2 + p_sys->p_ff_pic->repeat_pict) * (2 + p_sys->p_ff_pic->repeat_pict) *
p_dec->fmt_in.video.i_frame_rate_base / p_dec->fmt_out.video.i_frame_rate /
(2 * p_dec->fmt_in.video.i_frame_rate); (2 * p_dec->fmt_out.video.i_frame_rate_base);
} }
else if( p_context->time_base.den > 0 ) else if( p_context->time_base.num > 0 &&
p_context->time_base.den > 0 )
{ {
int i_tick = p_context->ticks_per_frame; int i_tick = p_context->ticks_per_frame;
if( i_tick <= 0 ) if( i_tick <= 0 )
...@@ -729,7 +735,7 @@ picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) ...@@ -729,7 +735,7 @@ picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
p_sys->i_pts += INT64_C(1000000) * p_sys->i_pts += INT64_C(1000000) *
(2 + p_sys->p_ff_pic->repeat_pict) * (2 + p_sys->p_ff_pic->repeat_pict) *
i_tick * p_context->time_base.num / (i_tick * p_context->time_base.num) /
(2 * p_context->time_base.den); (2 * p_context->time_base.den);
} }
} }
...@@ -833,7 +839,6 @@ picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) ...@@ -833,7 +839,6 @@ picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
break; break;
} }
} }
return p_pic; return p_pic;
} }
else else
...@@ -1266,4 +1271,3 @@ static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context, ...@@ -1266,4 +1271,3 @@ static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
return avcodec_default_get_format( p_context, pi_fmt ); return avcodec_default_get_format( p_context, pi_fmt );
} }
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment