Synchronize video to openGL animation
I am trying to sync a video to an animation drawn using openGL on iPad, and there are two things I am not sure how to do:
- Find the currently playing video frame.
- Make sure the update of the video and update of the openGL drawing occurs at the exact same time, as even a slight sync issue may ca开发者_JAVA技巧use visual artifacts.
Not sure it will work but instead of using MPMoviePlayerController
you could use an AVPlayer and use and AVSynchronizedLayer to synchronize your OpenGL layer timing with the AVPlayerLayer
's one.
You could create the video player like this:
NSURL *videoURL = [NSURL fileURLWithPath:@"your_url"];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
UIView *playerView = [[UIView alloc] initWithFrame:frame];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
[playerLayer setFrame:[[playerView layer] bounds]];
Then create a AVSynchronizedLayer
layer and sync it with the playerLayer
:
AVSynchronizedLayer *syncLayer = [AVSynchronizedLayer synchronizedLayerWithPlayerItem:playerItem];
[syncLayer addSublayer:yourGlView.layer];
[playerView.layer addSublayer:playerLayer];
[playerView.layer addSublayer:syncLayer];
[self.view addSubview:playerView];
...
精彩评论