0

I am looping 1 second mp4/h264 videos with no audio on an M1 Mac Mini. AVPlayer was causing hitches with scrolling.

Now I read videos using AVAssetReader and feed those CMSampleBuffers into a AVSampleBufferDisplayLayer.

To get it to seamlessly loop without having to create a new AVAssetReader, I just cache all of those samples in an array and create copies with new timing via CMSampleBufferCreateCopyWithNewTiming. These are short videos so it's not a lot of data.

It all works pretty great now with no hitches. However the VTDecoderXPCService is going nuts on the CPU. I was expecting the GPU to be doing most of the work for decoding.

Is copying those samples from memory via CMSampleBufferCreateCopyWithNewTiming causing it? Is there a better way?

jnorris
  • 51
  • 1
  • 6
  • How about using `AVPlayerLooper`? https://stackoverflow.com/a/47120425/22147 – Rhythmic Fistman Jul 16 '22 at 10:35
  • @RhythmicFistman that is what I replaced when it was not performing well (too much happening on the main thread) – jnorris Jul 16 '22 at 11:18
  • Oh. 1s of video can fit in memory. Just decode it once and keep all the frames around for instant display, no ongoing xpc or high cpu usage needed. – Rhythmic Fistman Jul 16 '22 at 12:56
  • @RhythmicFistman thanks for the reply...I thought the AVAssetReader would have already decoded it? So I need to feed the sample buffer to a VTDecompressionSession or something? Thank you – jnorris Jul 17 '22 at 05:19
  • @RhythmicFistman I am converting the pixel format to get a CVImageBuffer from the buffer via CMSampleBufferGetImageBuffer. There is no more xpc. Thanks very much, I am not a Swift dev – jnorris Jul 17 '22 at 06:52
  • Can you show how you’re configuring your AVAssetReader? – Rhythmic Fistman Jul 17 '22 at 07:29
  • @RhythmicFistman the xpc cpu usage seems to be solved. Now I'm converting the pixel format to something to get the CVImageBuffer to be populated `let videoOutput = AVAssetReaderTrackOutput(track: track, outputSettings: [kCVPixelBufferPixelFormatTypeKey as String : NSNumber(value: kCVPixelFormatType_422YpCbCr8 )])` – jnorris Jul 17 '22 at 08:14

0 Answers0