Search code examples
iosvideoavplayeravplayeritem

iOS: AVPlayerItem seekToTime not seeking to exact time requested


I'm working on an app which streams a video over HTTP. AVPlayer is used to play the video. I am using AVPlayerItem and the selectMediaOption method to switch between specific video streams (there are three streams in the source).

My problem is when I switch between the media options I call seekToTime: toleranceBefore: toleranceAfter: to skip the new video to the same point in time as the video I am switching from. The trouble is, this doesn't work reliably. The video normally skips to a point several seconds before the requested time, even though the AVPlayerItem currentTime property reports the time I requested. I am passing kCMTimeZero for both toleranceBefore and toleranceAfter.

Something else that is worth mentioning is that this only happens with one specific media stream. I have another media stream which does not exhibit the issue.

Can any one suggest what might be the problem here?


Solution

  • It turns out this issue didn't have anything to do with the APIs or how they were being used. It looks like the encoder used to create the video segments were creating errors in the resulting files.

    The errors reported by ffprobe are like:

    [h264 @ 00000249a4348980] decode_slice_header error
    [h264 @ 00000249a4348980] no frame!
    [h264 @ 00000249a4348980] non-existing PPS 0 referenced
    

    I'm not sure what the original tool was that was used to create the video segments I was using, but I've verified that Apple's mediafilesegmenter also causes errors.

    I solved the error by encoding the segments using ffmpeg.