我用前置摄像头录制了一段视频,输出被镜像了......
我尝试使用AVMutablecomposition
和layerinstructions
翻转视频,但没有运气.
谷歌搜索和搜索Stack Overflow一直没有结果,所以我打赌一个简单,直接的例子,说明如何做到这一点会使许多人受益.
没有迹象表明您正在使用什么来录制视频,生病假设AVCaptureSession
+AVCaptureVideoDataOutput
lazy var videoFileOutput: AVCaptureVideoDataOutput = AVCaptureVideoDataOutput() let v = videoFileOutput.connectionWithMediaType(AVMediaTypeVideo) v.videoOrientation = .Portrait v.videoMirrored = true
您可以使用 -[AVMutableVideoCompositionLayerInstruction setTransform:atTime:]
CGAffineTransform transform = CGAffineTransformMakeTranslation(self.config.videoSize, 0); transform = CGAffineTransformScale(transform, -1.0, 1.0); [videoCompositionLayerInstruction setTransform:transform atTime:videoTime]; // then append video tracks // [compositionTrack insertTimeRange:timeRange ofTrack:track atTime:atTime error:&error]; // apply instructions videoCompositionInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, composition.duration); videoCompositionInstruction.layerInstructions = @[videoCompositionLayerInstruction]; videoComposition = [AVMutableVideoComposition videoComposition]; videoComposition.renderSize = CGSizeMake(self.config.videoSize, self.config.videoSize); videoComposition.frameDuration = CMTimeMake(1, self.config.videoFrameRate); videoComposition.instructions = @[videoCompositionInstruction];
https://github.com/ElfSundae/AVDemo/tree/ef2ca437d0d8dcb3dd41c5a272c8754a29d8a936/AVSimpleEditoriOS
出口构成:
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:composition presetName:presetName]; exportSession.outputFileType = AVFileTypeMPEG4; exportSession.outputURL = outputURL; exportSession.shouldOptimizeForNetworkUse = YES; // videoComposition contains transform instructions for video tracks exportSession.videoComposition = videoComposition; // audioMix contains background music for audio tracks exportSession.audioMix = audioMix; [exportSession exportAsynchronouslyWithCompletionHandler:^{ AVAssetExportSessionStatus status = exportSession.status; if (status != AVAssetExportSessionStatusCompleted) { // exportSession.error } else { // exportSession.outputURL } }];