Seeking to start of stream that is being recorded shows a frame of the live stream position

In our app the user could start a stream from beginning while it's being recorded.


Currently we are waiting for AVPlayerItemStatusReadyToPlay from the AVPlayer.status to seek to the beginning.

However this will show a frame of the live position before seeking to the beginning of the stream. Is there a better way to accomblish this? We are using AVPlayer and could reproduce this on both out iOS and tvOS apps.

Replies

I've had a similar problem in playback of H.264 movies on Mac OS X.

AVPlayerItemVideoOutput reports YES that it hasNewPixelBufferForItemTime,

but then it delivers the wrong frame anyway.


I have yet to discover a good solution, because many workarounds break scrubbing of the playhead.



AVPlayerItemVideoOutput *video_output;









if(video_output && ([video_output hasNewPixelBufferForItemTime:tph]))

{

CMTime it, ht; /

CVPixelBufferRef pix = [video_output copyPixelBufferForItemTime:tph itemTimeForDisplay:&it];


// kpk 02/01/2018 prevent wrong inFrame from being displayed.

// dang... unfortunately this breaks scrubbing for highly compressed movies (that have less key frames?)


double receivedTime = (((double)it.value) / tph.timescale);

double actualDiff = fabs(receivedTime - phTime );

if ( seeking && (actualDiff > 0.2 || (actualDiff > 0.1 && it.value == 0.0)))

{

if ( seekToInFrame )

{

if(verbose) printf( "discarding mismatched frame time %0.2f vs %0.2f, %s\n", phTime, receivedTime, threadName );

seekToInFrame = NO; /

return;

}

if(verbose) printf( "mismatched frame time %0.2f vs %0.2f, %s\n", phTime, receivedTime, threadName );

}