Set rate at which AVSampleBufferDisplayLayer renders sample buffers

前端 未结 3 1014
天涯浪人
天涯浪人 2021-01-06 20:58

I am using an AVSampleBufferDisplayLayer to display CMSampleBuffers which are coming over a network connection in the h.264 format. Video playback is smooth and working corr

3条回答
  •  余生分开走
    2021-01-06 21:41

    Set output presentation timestamp on sample buffer before enqueuing it to AVSampleBufferDisplayLayer. For FPS = 30:

    CMSampleBufferSetOutputPresentationTimeStamp(sampleBuffer,    CMTimeAdd(kCMTimeZero, CMTimeMake(1 * _frameCount, 30)));
    

    Set the timestamp on first buffer to 0 (kCMTimeZero) and increment the timestamp on subsequent buffers by 1/30th of a second.

    Also, need to set timebase on AVSampleBufferDisplayLayer instance so that buffer with presentation timestamp set to 0 is displayed first.

    CMTimebaseRef controlTimebase;
    CMTimebaseCreateWithMasterClock(CFAllocatorGetDefault(),    CMClockGetHostTimeClock(), &controlTimebase);
    
    _videoLayer.controlTimebase = controlTimebase;
    CMTimebaseSetTime(_videoLayer.controlTimebase, kCMTimeZero);
    CMTimebaseSetRate(_videoLayer.controlTimebase, 1.0);
    

提交回复
热议问题