Skip to content

Commit

Permalink
Fix playback when framerate changes
Browse files Browse the repository at this point in the history
- When playing FFMPEG-decoded videos if the video stream
  framerate changed there was some automatic timing
  adjustment code that would set that frame's time
  to what was "expected". This code comes from
  26c79db
  (fixed the problem that some mkv file is played not
  smoothly after seeking). Since the commit doesn't
  really explain the problem and I'm seeing it cause
  a real problem in this case I'm deleting the code.
  If the problem described in that commit returns
  then the issue can be reevaluated taking this new
  issue into consideration.
- What would happen is that when the framerate changed
  libav would deliver a frame that was (in my case)
  slightly farther ahead in time than we expected the
  next frame to be. So we would force the frame's time
  to be what we actually expected the next frame's
  time to be and picked a new next frame time based
  on that time. This would cause frames to eventually
  get far enough out of sync that the timer adjustment
  code in the display path would see us way out of
  sync and force the clock current time to jump forward.
  This would make the video play as though it were
  being fast-forwarded.
  • Loading branch information
samiamwork committed Sep 1, 2013
1 parent 0312749 commit e0f00d6
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions FFVideoTrack.m
Original file line number Diff line number Diff line change
Expand Up @@ -461,22 +461,11 @@ - (double)decodePacket
else if (_frame->opaque && *(uint64_t*)_frame->opaque != AV_NOPTS_VALUE) {
pts = *(uint64_t*)_frame->opaque;
}
double time;
double timeErr = (_nextFramePts - pts) * av_q2d(_stream->time_base);
if (_needPtsAdjust &&
_frame->pict_type != FF_I_TYPE && packet->duration &&
-1. < timeErr && timeErr < 1.) {
time = (double)(_nextFramePts) * av_q2d(_stream->time_base);
_nextFramePts += _frameInterval / av_q2d(_stream->time_base);
}
else {
time = (double)(pts) * av_q2d(_stream->time_base);
_nextFramePts = pts + _frameInterval / av_q2d(_stream->time_base);
}
//TRACE(@"[%s] frame flag %d pts %lld dts %lld pos %lld time %f timeErr %f", __PRETTY_FUNCTION__,
double time = (double)(pts) * av_q2d(_stream->time_base);
//TRACE(@"[%s] frame flag %d pts %lld dts %lld pos %lld time %f", __PRETTY_FUNCTION__,
// _frame->pict_type,
// packet.pts, packet.dts,
// packet.pos, time, timeErr);
// packet.pos, time);
return time;
}

Expand Down

0 comments on commit e0f00d6

Please sign in to comment.