ios - AVAssetExportSession fileLengthLimit 被忽略并且 estimatedOutputFileLength 返回 0

标签 ios avfoundation avassetexportsession

我正在使用 AVAssetExportSession 重新编码视频,我想尝试将生成的文件大小保持在限制以下。我的最终调用如下所示:

        NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
        if ([compatiblePresets containsObject:AVAssetExportPresetMediumQuality])
        {
            AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:mixComposition presetName:AVAssetExportPresetMediumQuality];
            exportSession.outputURL = outputURL;
            exportSession.fileLengthLimit = 600000;
            exportSession.outputFileType = AVFileTypeMPEG4;
            exportSession.shouldOptimizeForNetworkUse = YES;
            exportSession.videoComposition = mainCompositionInst;
            NSLog(@"bytes = %lli", exportSession.estimatedOutputFileLength);
            [exportSession exportAsynchronouslyWithCompletionHandler:^{
            switch ([exportSession status])
            {
                case AVAssetExportSessionStatusFailed:
                    NSLog(@"Export failed: %@ : %@", [[exportSession error] localizedDescription], [exportSession error]);
                    handler(nil);

                    break;
                case AVAssetExportSessionStatusCancelled:

                    NSLog(@"Export canceled");
                    handler(nil);

                    break;
                default:

                    handler(outputURL);

                    break;

            }
            }];
         }

然而 estimatedOutputFileLength 总是返回 0 而 fileLengthLimit 似乎被完全忽略了。我想使用 estimatedOutputFileLength 来确定是使用中等还是低质量编码。

这可能是 iOS 错误吗?有没有人让这 2 个属性起作用?

最佳答案

为后代添加一个注释,关于 exstimatedOutputFileLength 总是返回 0,我必须向导出 session 添加一个 timeRange。

exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, [asset duration]);

关于ios - AVAssetExportSession fileLengthLimit 被忽略并且 estimatedOutputFileLength 返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20374313/

相关文章:

ios5 - 如何合并视频和音频文件?

ios - 当 isTranslucent = False 时导航栏展开(Swift 3)

ios - 如何使 AVPlayer 和 AVPlayerLayer 可滚动(AVFoundation)

ios - Fitbit 和 OAuth 2.0

ios - avplayer无法播放通过IOS Objective-C中的设备相机捕获的视频中的音频

ios - 如何在 iOS 和 Swift 中的 Collection View Cell 中停止捕获 session

ios - AVAssetExportSession 不导出时间范围

ios - 在 iOS 上导出视频 : understanding and setting frame duration property?

ios/iphone - [NSNull dataUsingEncoding :]: unrecognized selector sent to instance

ios - 辅助功能检查器不适用于 iOS 11.2