AVAssetExportSession fileLengthLimit被忽略,estimatedOutputFileLength返回0

时间:2013-12-04 11:36:33

标签: 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错误吗?有没有人有这两个属性工作?

1 个答案:

答案 0 :(得分:0)

为后代添加一个注释,关于exstimatedOutputFileLength总是返回0,我不得不在导出会话中添加一个timeRange。

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