将视频同步到openGL动画

sin*_*sro 11 video opengl-es ipad ios

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

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

Tra*_*lio 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]];
Run Code Online (Sandbox Code Playgroud)

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

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

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

[self.view addSubview:playerView];
...
Run Code Online (Sandbox Code Playgroud)