将视频同步到openGL动画

时间:2011-10-03 06:20:12

标签: ios ipad video opengl-es

我正在尝试将视频同步到在iPad上使用openGL绘制的动画,有两件事我不知道该怎么办:

  1. 查找当前播放的视频帧。
  2. 确保视频的更新和openGL绘图的更新在同一时间发生,因为即使轻微的同步问题也可能导致视觉瑕疵。

1 个答案:

答案 0 :(得分:3)

不确定它是否有效但不使用MPMoviePlayerController您可以使用AVPlayer并使用和AVSynchronizedLayer将您的OpenGL图层时序与AVPlayerLayer同步

您可以像这样创建视频播放器:

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]];

然后创建AVSynchronizedLayer图层并将其与playerLayer

同步
AVSynchronizedLayer *syncLayer = [AVSynchronizedLayer synchronizedLayerWithPlayerItem:playerItem];
[syncLayer addSublayer:yourGlView.layer];

[playerView.layer addSublayer:playerLayer];
[playerView.layer addSublayer:syncLayer];

[self.view addSubview:playerView];
...