AVAssetExportSession fileLengthLimit игнорируется, а оцениваемый OutputFileLength возвращает 0

Я перекодирую видео с помощью 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;

            }
            }];
         }

однако оцениваемыйOutputFileLength всегда возвращает 0, а fileLengthLimit, похоже, полностью игнорируется. Я хотел использовать предполагаемыйOutputFileLength, чтобы определить, следует ли использовать кодирование среднего или низкого качества.

Может ли это быть ошибкой iOS? Кто-нибудь заставил эти 2 свойства работать?


person Darren    schedule 04.12.2013    source источник


Ответы (1)


Добавив примечание для потомков о том, что exstimatedOutputFileLength всегда возвращает 0, мне пришлось добавить timeRange в сеанс экспорта.

exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, [asset duration]);
person Henry Green    schedule 23.09.2014