gpt4 book ai didi

iphone - 如何在 iOS 中翻转视频帧

转载 作者:行者123 更新时间:2023-11-28 17:54:25 24 4
gpt4 key购买 nike

我正在录制视频并将其保存在应用程序的文档文件夹中。我想翻转视频帧并保存它,以便视频像镜像视频一样以翻转模式播放。我不知道如何实现这一点。我试图翻转视频,但它保存为空白视频。这是翻转视频的代码

NSURL *assetURL = self.outPutUrl;
AVAsset *movieAsset = [AVAsset assetWithURL:assetURL];
NSLog(@"Asset: %0.1f",CMTimeGetSeconds(movieAsset.duration));
NSLog(@"Asset Preferred Transform %@", NSStringFromCGAffineTransform(movieAsset.preferredTransform));
//Output Composition
AVMutableComposition *outputComposition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *videoTrack = [outputComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
[videoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, movieAsset.duration)
ofTrack:[[movieAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
atTime:kCMTimeZero
error:nil];

[videoTrack setPreferredTransform:CGAffineTransformMakeScale(1, -1)];
AVMutableVideoCompositionLayerInstruction *videoLayerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack];
[videoLayerInstruction setTransform:CGAffineTransformMakeScale(1, -1) atTime:kCMTimeZero];
AVMutableVideoCompositionInstruction *videoInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
videoInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, movieAsset.duration);
videoInstruction.layerInstructions = [NSArray arrayWithObjects:videoLayerInstruction, nil];
AVMutableVideoComposition *outputVideoComposition = [AVMutableVideoComposition videoComposition];
outputVideoComposition.instructions = [NSArray arrayWithObjects:videoInstruction, nil];
outputVideoComposition.frameDuration = CMTimeMake(1, 30);
outputVideoComposition.renderSize = CGSizeMake(480, 640);
//Export

AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:outputComposition presetName:AVAssetExportPresetHighestQuality] ;
exporter.videoComposition = outputVideoComposition;
NSArray *filePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [filePath objectAtIndex:0];
NSString *newPath = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat:@"FinalVideo-%d.mov",arc4random() % 1000]];
[[NSFileManager defaultManager] removeItemAtPath:newPath error:nil];
exporter.outputURL = [NSURL fileURLWithPath:newPath];
exporter.outputFileType = AVFileTypeQuickTimeMovie;
NSLog(@"Starting export%@",exporter.outputURL);
[exporter exportAsynchronouslyWithCompletionHandler:^(void){
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Video exported");
NSLog(@"%@", newPath);
NSURL *newAssetURL = [NSURL fileURLWithPath:newPath];
AVAsset *newMovieAsset = [AVAsset assetWithURL:newAssetURL];
NSLog(@"New Asset %@",newMovieAsset);
NSLog(@"New Asset Duration: %0.1f",CMTimeGetSeconds(newMovieAsset.duration));
NSLog(@"New Asset Preferred Transform %@", NSStringFromCGAffineTransform(newMovieAsset.preferredTransform));
UISaveVideoAtPathToSavedPhotosAlbum(newPath, nil, nil, nil);


});
}];

求助!谢谢!

最佳答案

检查这个link ..我想你想反转视频剪辑..它对我有用..

关于iphone - 如何在 iOS 中翻转视频帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17653506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com