我有一个AVMutableVideoComposition
,我想设置导出帧率(例如10 fps):
videoComposition.frameDuration = CMTimeMakeWithSeconds(1, 10);
我已经获得了各种其他说明,例如转换合成并且它们都有效,但是,导出的视频只是忽略此属性并以原始视频的帧速率导出。
这是我的代码:
AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoCompositionWithPropertiesOfAsset:asset];
...
videoComposition.frameDuration = CMTimeMakeWithSeconds(1, 10);
AVMutableVideoCompositionLayerInstruction *transformInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack];
instruction.timeRange = videoTrack.timeRange;
[transformInstruction setTransform:matrix atTime:kCMTimeZero];
instruction.layerInstructions = @[ transformInstruction ];
videoComposition.instructions = @[ instruction ];
[[NSFileManager defaultManager] removeItemAtURL:exportURL error:nil];
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:asset presetName:AVAssetExportPresetHEVCHighestQuality];
exportSession.outputURL = exportURL;
exportSession.outputFileType = exportOptions.fileType;
exportSession.videoComposition = videoComposition;
exportSession.shouldOptimizeForNetworkUse = exportOptions.shouldOptimizeForNetworkUse;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
//video is exported with all the settings correctly, except the frame rate.
}];
我还尝试AVAssetExportPresetPassthrough
代替AVAssetExportPresetHEVCHighestQuality
作为导出会话预设,但没有任何改变。
为什么忽略frameDuration
,如何在不使用SDAVAssetExportSession 之类的其他第三方库的情况下使其工作?
我已经看过Setting AVMutableComposition's frameDuration,但那里没有解决方法。但是,当我检查SDAVAssetExportSession
的来源时,它会像我一样使用frameDuration
属性(请参阅https://github.com/rs/SDAVAssetExportSession/blob/master/SDAVAssetExportSession.m#L308),但出于某种原因,我的工作无效。但是,尽管如此,即使Apple的AVKit存在错误,也必须有一个解决方法。我错过了什么?