iOS逐帧视频播放前进/后退

4
我想在iOS设备上以慢动作的方式播放视频。
我的视图包含一个视频(大约2秒长)和一个滑块。
用户可以移动滑块并逐帧(向前或向后)浏览电影。
MPMoviePlayerController缺乏逐帧播放的功能。
我了解到MVAssetReader,但我不知道如何具体使用它。
我没有固定的帧速率,所以应该从视频的元数据中取出这些信息。我真的需要显示每一帧。
有人能给我一个提示吗?
2个回答

3

AV播放器演示WWDC 2010样本代码可以帮助您完成任务

从视频中剪辑缩略图的方法在WWDC 2010 AV编辑中有详细解释,使用AV Foundation框架进行音频和视频编辑,还提供了许多其他示例代码。

如果您有付费的开发者账户,则可以在iTunes上观看视频。


2
AVFoundation是一个非常强大的框架,但与MPMoviePlayerController相比,需要更多的输入和理解才能使用。我强烈建议您观看WWDC视频,查看示例代码并阅读文档。文档对于获取概念上的理解非常好,但在实际视频格式的细节方面缺少一些详细信息。因此,示例代码和实验是不错的选择。如果您想逐帧播放,则AVPlayerItem stepByCount:可能是最好的选择。
// Setup a PlayerItem and a Player
NSURL* movieURL = [NSBundle URLForResource:@"movie" withExtension:@"mov" subdirectory:@"" inBundleWithURL:[NSBundle mainBundle].bundleURL];
AVURLAsset* movieAsset = [AVURLAsset assetWithURL:movieURL];
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithAsset:movieAsset];
AVPlayer* player = [AVPlayer playerWithPlayerItem:playerItem];

// setup the layer so you can see it
AVPlayerLayer* playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = self.view.bounds;
[self.view.layer addSublayer:playerLayer];

// Verify our assumptions, in production code you should do something better
NSAsset(player.currentItem.canStepForward, @"Assume this format can step forward");    
NSAsset(player.currentItem.canStepBackward, @"Assume this format can step backward");


[player.currentItem stepByCount:1];  // step forward a frame

[player.currentItem stepByCount:-1];  // step backward a frame

我知道这是一个相当旧的帖子,但我该如何创建一个包含“向前/向后帧”的新AVAsset呢?因此,当用户在帧之间滚动时,它会将帧添加到可变的avasset或其他什么东西中吗? - Ibdakine

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接