获取缩略图的视频快照

获取缩略图的视频快照

本文介绍了获取缩略图的视频快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apple提供的AVCam代码从iPhone相机录制视频。

I am recording a video from the iPhone camera by using the AVCam code provided from apple.

录制视频后,会将其保存到照片库。

After the video is recorded it is saved to the photos library.

然后加载一个新视图,这里我需要有一个视频的图像缩略图。

A new view is then loaded, here I need to have an image thumbnail of the video.

我有一条视频路径:

file://localhost/private/var/mobile/Applications/ED45DEFC-ABF9-4A5E-9102-21680CC1448E/tmp/output.mov

我似乎无法想象如何将视频的第一帧用作缩略图。

I can't seem to figure how to get the first frame of the video to use as a thumbnail.

非常感谢任何帮助,感谢您的时间。

Any help would be very appreciated and thank you for your time.

编辑

I结果使用了这个,我不知道为什么它会将图像侧向返回?

I ended up using this, I'm not sure why it returns the image sideways?

- (UIImage*)loadImage {

    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:vidURL options:nil];
    AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    NSError *err = NULL;
    CMTime time = CMTimeMake(1, 60);
    CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];
    NSLog(@"err==%@, imageRef==%@", err, imgRef);

    return [[UIImage alloc] initWithCGImage:imgRef];

}


推荐答案

To 修复 AVAssetImageGenerator中的缩略图方向集 applyPreferredTrackTransform YES / code>实例。如果您添加自己的视频合成,则需要包含正确的转换以根据需要旋转视频。

To fix the thumbnail orientation set appliesPreferredTrackTransform to YES in the AVAssetImageGenerator instance. If you add your own video composition, you'll need to include the right transform to rotate the video as wanted.

generate.appliesPreferredTrackTransform = YES;

请记住用 CGImageRelease 。

要请求多个缩略图,最好与 generateCGImagesAsynchronouslyForTimes异步执行:completionHandler:

To request multiple thumbnails it's better to do asynchronously with generateCGImagesAsynchronouslyForTimes:completionHandler:.

这篇关于获取缩略图的视频快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 19:12