Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 cause visual artifacts.
like image 926
sinsro Avatar asked Oct 03 '11 06:10

sinsro


1 Answers

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];
...
like image 200
Trasplazio Garzuglio Avatar answered Oct 16 '22 06:10

Trasplazio Garzuglio