我想在自定义视图中录制视频,因此我按照以下代码使用AVFoundation。
client.execute(request)
但视频只能以横向模式保存。 我已经提到了this并添加了以下代码
request.getURI()
但添加后没有得到正确的结果。 所以请帮我解决这个问题...
答案 0 :(得分:2)
你应该使用AVMutableVideoCompositionInstruction和layerInstruction
AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
instruction.timeRange = CMTimeRangeMake(kCMTimeZero, asset.duration);
AVMutableVideoCompositionLayerInstruction *layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:compositionVideoTrack];
CGAffineTransform rotationTransform = CGAffineTransformMakeRotation(M_PI_2);
[layerInstruction setTransform:rotationTransform atTime:kCMTimeZero];
instruction.layerInstructions = @[layerInstruction];
AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition];
videoComposition.renderSize = CGSizeMake(videoWidth, videoHeight);
videoComposition.instructions = @[instruction];
videoComposition.frameDuration = CMTimeMake(1, 30);
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetHighestQuality];
exporter.outputURL = exportURL;
exporter.outputFileType = AVFileTypeQuickTimeMovie;
exporter.videoComposition = videoComposition;
[exporter exportAsynchronouslyWithCompletionHandler:^{
}];