gpt4 book ai didi

objective-c - 为什么 AVAssetExportSession 会产生一个空文件?

转载 作者:可可西里 更新时间:2023-11-01 05:10:07 28 4
gpt4 key购买 nike

我正在尝试从 UIImagePickerController 创建的源视频中导出 .mov 文件。问题是 AVAssetExportSession 创建的输出文件只有 668 字节。为什么会失败?我的代码:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *imagePickerVideoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSString *filename = @"vid1.mov";

AVAsset *video = [AVAsset assetWithURL:imagePickerVideoURL];
AVAssetExportSession *exportSession
= [AVAssetExportSession exportSessionWithAsset:video presetName:AVAssetExportPresetMediumQuality];
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
exportSession.outputURL = [pathToSavedVideosDirectory URLByAppendingPathComponent:filename];
NSLog(@"processing video...: %@", exportSession);
[exportSession exportAsynchronouslyWithCompletionHandler:^{
NSLog(@"done processing video!");
}];
}

最佳答案

我猜这是因为 exportSession 没有保留在内存中,因此在 didFinishPickingMediaWithInfo 完成后(在导出 session 完成处理程序运行之前)被杀死。

exportSession 存储到 @property 或更改完成处理程序以复制对 exportSession 的引用,如下所示:

[exportSession exportAsynchronouslyWithCompletionHandler:^{
if (AVAssetExportSessionStatusCompleted == exportSession.status)
{
NSLog(@"done processing video!");
}
}];

关于objective-c - 为什么 AVAssetExportSession 会产生一个空文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11754304/

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