From f269a2a73a2b37d3729c4d143ed11fcd01b6d876 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 2 Sep 2003 05:31:47 +0000 Subject: [PATCH] Fix up AVI timing --- .../arch/MovieTexture/MovieTexture_FFMpeg.cpp | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp b/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp index cbb132a918..c38a6777ac 100644 --- a/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp +++ b/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp @@ -340,11 +340,12 @@ void MovieTexture_FFMpeg::CreateTexture() void MovieTexture_FFMpeg::DecoderThread() { bool GetNextTimestamp = true; - float CurrentTimestamp = 0, LastGoodTimestamp = 0, Last_IP_Timestamp=0; + float CurrentTimestamp = 0, Last_IP_Timestamp = 0; bool FrameSkipMode = false; unsigned Frame = 0; - + float LastFrameDelay = 0; + CHECKPOINT; while( m_State != DECODER_QUIT ) { @@ -394,12 +395,15 @@ void MovieTexture_FFMpeg::DecoderThread() { if ( GetNextTimestamp ) { - if (pkt.pts == AV_NOPTS_VALUE) - CurrentTimestamp = 0; - else + if (pkt.pts != AV_NOPTS_VALUE) CurrentTimestamp = (float)pkt.pts * m_fctx->pts_num / m_fctx->pts_den; - if( CurrentTimestamp != 0 ) - LastGoodTimestamp = CurrentTimestamp; + else + { + /* If the timestamp is zero, this frame is to be played at the + * time of the last frame plus the length of the last frame. */ + CurrentTimestamp += LastFrameDelay; + } + GetNextTimestamp = false; } @@ -424,6 +428,10 @@ void MovieTexture_FFMpeg::DecoderThread() ++Frame; + /* Length of this frame: */ + LastFrameDelay = (float)m_stream->codec.frame_rate_base / m_stream->codec.frame_rate; + LastFrameDelay += frame.repeat_pict * (LastFrameDelay * 0.5f); + /* We got a frame. Convert it. */ avcodec::AVPicture pict; pict.data[0] = (unsigned char *)m_img->pixels; @@ -433,19 +441,6 @@ void MovieTexture_FFMpeg::DecoderThread() frame.pict_type != FF_B_TYPE ) swap( CurrentTimestamp, Last_IP_Timestamp ); - if( CurrentTimestamp != 0 ) - LastGoodTimestamp = CurrentTimestamp; - else { - /* If the timestamp is zero, guess what the timestamp - * would be. */ - CurrentTimestamp = LastGoodTimestamp; - const float frame_delay = (float)m_stream->codec.frame_rate_base / - (float)m_stream->codec.frame_rate; - - CurrentTimestamp += frame_delay; - CurrentTimestamp += frame.repeat_pict * (frame_delay * 0.5f); - } - m_Position = CurrentTimestamp; const float Offset = CurrentTimestamp - m_Timer;