使用AVFoundation的视频的第一帧 [英] First frame of a video using AVFoundation

查看:128
本文介绍了使用AVFoundation的视频的第一帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用AVFoundation中的类获取视频的第一帧。但它似乎根本没有获得图像。

I'm trying to get the first frame of a video using the classes in AVFoundation. But it appears to not be getting an image at all.

我的代码目前看起来像这样

My code currently looks like this

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

视频路径的价值是 / var / mobile / Applications / 02F42CBF- D8BD-4155-85F2-8CF1E55B5023 / Documents / videos / 1334300431637030.mp4 这绝对是一个视频,因为我可以用 MPMoviePlayerViewController 来播放它。我不确定我做错了什么,但任何建议都会有所帮助。

The value of video path is /var/mobile/Applications/02F42CBF-D8BD-4155-85F2-8CF1E55B5023/Documents/videos/1334300431637030.mp4 which is definitely a video, since I can play it with MPMoviePlayerViewController. I'm not sure what I'm doing wrong but any suggestions would be helpful.

谢谢。

推荐答案

我解决了。显然使用 [NSURL fileURLWithPath:videoPath] 而不是 [NSURL URLWithString:videoPath] 会有所不同。

I solved it. Apparently using [NSURL fileURLWithPath:videoPath] instead of [NSURL URLWithString:videoPath] makes all the difference.

这篇关于使用AVFoundation的视频的第一帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆