0

I have a AVMutableVideoComposition and I want to set the export frame rate (e.g. 10 fps):

videoComposition.frameDuration = CMTimeMakeWithSeconds(1, 10);

I've got various other instructions like transform on the composition and they all work, however, the exported video just ignores this property and exports at the original video's frame rate.

Here is my code:

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.
}];

I've also tried AVAssetExportPresetPassthrough instead of AVAssetExportPresetHEVCHighestQuality as the export session preset, but nothing changed.

Why is the frameDuration ignored, and how can I make it work without the use of another 3rd party library such as SDAVAssetExportSession?

I've already seen Setting AVMutableComposition's frameDuration but there's no solution there. However, when I examine the SDAVAssetExportSession's source, it uses the frameDuration property just as I am (see https://github.com/rs/SDAVAssetExportSession/blob/master/SDAVAssetExportSession.m#L308), but for some reason mine is not working. But as that works, there must be a workaround even if there's a bug with Apple's AVKit. What am I missing?

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389

0 Answers0