使用AVFoundation的video的第一帧
我正在尝试使用AVFoundation中的类获取video的第一帧。 但它似乎没有得到一个形象。
我的代码目前看起来像这样
AVURLAsset* asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:videoPath] options:nil]; AVAssetImageGenerator* imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset]; UIImage* image = [UIImage imageWithCGImage:[imageGenerator copyCGImageAtTime:CMTimeMake(0, 1) actualTime:nil error:nil]]; [videoFrame setImage:image];
videopath的值是/var/mobile/Applications/02F42CBF-D8BD-4155-85F2-8CF1E55B5023/Documents/videos/1334300431637030.mp4
这绝对是一个video,因为我可以用MPMoviePlayerViewController
播放它。 我不知道我做错了什么,但任何build议将是有益的。
谢谢。
我解决了它。 显然使用[NSURL fileURLWithPath:videoPath]
而不是[NSURL URLWithString:videoPath]
使所有不同。
我用null0pointer的解决scheme,但在一些video中,我收到了第一帧旋转。 为了解决这个问题,我将AVAssetImageGenerator的appliedPreferredTrackTransform属性设置为TRUE。 这个代码看起来像这样:
AVURLAsset* asset = [AVURLAsset URLAssetWithURL:fileURL options:nil]; AVAssetImageGenerator* imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset]; [imageGenerator setAppliesPreferredTrackTransform:TRUE]; UIImage* image = [UIImage imageWithCGImage:[imageGenerator copyCGImageAtTime:CMTimeMake(0, 1) actualTime:nil error:nil]]; [self.imageView setImage:image];
- iOS 10.0 – 10.1:使用AVVideoCompositionCoreAnimationTool后,AVPlayerLayer不显示video,只有audio
- 如何正确释放AVCaptureSession
- AVAssetWriter输出(UIImage写入video)失真
- 当另一个应用程序开始/停止播放audio时,可以通知我的应用程序?
- 如何使用AVFoundation结合不同方向的video剪辑
- AVAssetWriter可以使用透明度编写文件吗?
- iOS检测系统音量水平变化。 私人API或不? AVSystemController_SystemVolumeDidChangeNotification
- CALayer – 放置在storyboard UIButton下面的子图层?
- CMSampleBufferSetDataBufferFromAudioBufferList返回错误12731