开发者

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:

  1. Find the currently playing video frame.
  2. 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];
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜