3

我正在使用重新编码视频,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 来确定是使用Medium 还是Low 质量编码。

这可能是iOS错误吗?有没有人让这两个属性工作?

4

1 回答 1

0

为后代添加注释,关于 exstimatedOutputFileLength 始终返回 0,我必须在导出会话中添加一个 timeRange。

exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, [asset duration]);
于 2014-09-23T06:06:35.497 回答