Frame Sync with AVPlayer

I have a problem with synchronizing external content in CALayer with AVPlayer with high accuracy.

My first thought was to lay out an array of frames (equal to the number of frames in the video) within the CAKeyframeAnimation and synchronize with AVSynchronizedLayer . However, when moving around the frame, it is shown that AVPlayer and Core Animation redraw on different cycles, since there is a slight (but noticeable) delay before synchronizing them.

There is not enough processing and display through Core Video, is there a way to accurately synchronize with AVPlayer at the frame level?

Update: February 5, 2012

So far, the best way I've found for this is to pre-render through AVAssetExportSession in combination with AVVideoCompositionCoreAnimationTool and CAKeyframeAnimation .

I am still very interested in learning about any ways to do this in real time.

+6
source share
2 answers

What do you mean by "high precision"?

Although the documents claim that AVAssetReader not intended for use in real time, in practice I had no problems reading real-time video using it (cf fooobar.com/questions/123654 / ... ). The returned frames have a โ€œpresentation timestamp,โ€ which you can get with CMSampleBufferGetPresentationTimeStamp .

You want one part of the project to be the master of the timekeeper here. Assuming your CALayer animation CALayer quickly computed and does not include potentially blocking things like disk access, I would use this as the main source of time. When you need to draw content (for example, in the draw selector in a subclass of UIView ), you should read currentTime from the CALayer animation, if necessary, continue using AVAssetReader video frames using copyNextSampleBuffer , until CMSampleBufferGetPresentationTimeStamp returns> = currentTime , draw a frame, and then draw the content CALayer animations on top.

+3
source

If your player uses AVURLAsset, did you download it with the exact duration flag set? That is, something like:

 NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey]; AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:aUrl options:options]; 
+1
source

Source: https://habr.com/ru/post/907651/


All Articles