gpt4 book ai didi

objective-c - 如何设置 AVAssetImageGenerator 的大小?

转载 作者:行者123 更新时间:2023-12-03 22:24:01 24 4
gpt4 key购买 nike

我尝试从视频中读取一些帧。视频是 640 x 480 但我得到的图像只有 480 x 360。有没有办法得到原始大小的图像?

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
NSString * mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
[self readMovieFrames:[info objectForKey:UIImagePickerControllerMediaURL]];

[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)readMovieFrames:(NSURL *)url
{
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:playerItem.asset];
imageGenerator.requestedTimeToleranceAfter = kCMTimeZero;
imageGenerator.requestedTimeToleranceBefore = kCMTimeZero;
imageGenerator.appliesPreferredTrackTransform = YES;
//…
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:requestTime actualTime:&actualTime error:&error];
UIImage *img = [UIImage imageWithCGImage:imageRef];
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
CGImageRelease(imageRef);
}

最佳答案

要么使用

imageGenerator.maximumSize = CGSizeZero; 

要获取未缩放的图像或定义 640px 的边界框,纵横比保持不变

imageGenerator.maximumSize = CGSizeMake(640, 640);

希望对您有所帮助!

关于objective-c - 如何设置 AVAssetImageGenerator 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26175984/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com