Fix up AVI timing
This commit is contained in:
@@ -340,10 +340,11 @@ void MovieTexture_FFMpeg::CreateTexture()
|
|||||||
void MovieTexture_FFMpeg::DecoderThread()
|
void MovieTexture_FFMpeg::DecoderThread()
|
||||||
{
|
{
|
||||||
bool GetNextTimestamp = true;
|
bool GetNextTimestamp = true;
|
||||||
float CurrentTimestamp = 0, LastGoodTimestamp = 0, Last_IP_Timestamp=0;
|
float CurrentTimestamp = 0, Last_IP_Timestamp = 0;
|
||||||
|
|
||||||
bool FrameSkipMode = false;
|
bool FrameSkipMode = false;
|
||||||
unsigned Frame = 0;
|
unsigned Frame = 0;
|
||||||
|
float LastFrameDelay = 0;
|
||||||
|
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
while( m_State != DECODER_QUIT )
|
while( m_State != DECODER_QUIT )
|
||||||
@@ -394,12 +395,15 @@ void MovieTexture_FFMpeg::DecoderThread()
|
|||||||
{
|
{
|
||||||
if ( GetNextTimestamp )
|
if ( GetNextTimestamp )
|
||||||
{
|
{
|
||||||
if (pkt.pts == AV_NOPTS_VALUE)
|
if (pkt.pts != AV_NOPTS_VALUE)
|
||||||
CurrentTimestamp = 0;
|
|
||||||
else
|
|
||||||
CurrentTimestamp = (float)pkt.pts * m_fctx->pts_num / m_fctx->pts_den;
|
CurrentTimestamp = (float)pkt.pts * m_fctx->pts_num / m_fctx->pts_den;
|
||||||
if( CurrentTimestamp != 0 )
|
else
|
||||||
LastGoodTimestamp = CurrentTimestamp;
|
{
|
||||||
|
/* 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;
|
GetNextTimestamp = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,6 +428,10 @@ void MovieTexture_FFMpeg::DecoderThread()
|
|||||||
|
|
||||||
++Frame;
|
++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. */
|
/* We got a frame. Convert it. */
|
||||||
avcodec::AVPicture pict;
|
avcodec::AVPicture pict;
|
||||||
pict.data[0] = (unsigned char *)m_img->pixels;
|
pict.data[0] = (unsigned char *)m_img->pixels;
|
||||||
@@ -433,19 +441,6 @@ void MovieTexture_FFMpeg::DecoderThread()
|
|||||||
frame.pict_type != FF_B_TYPE )
|
frame.pict_type != FF_B_TYPE )
|
||||||
swap( CurrentTimestamp, Last_IP_Timestamp );
|
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;
|
m_Position = CurrentTimestamp;
|
||||||
|
|
||||||
const float Offset = CurrentTimestamp - m_Timer;
|
const float Offset = CurrentTimestamp - m_Timer;
|
||||||
|
|||||||
Reference in New Issue
Block a user