0
비디오를 사각형으로 자르려고합니다. 사각형 해상도 .mov 파일을 생성하는 AVCaptureSession 설정이 이미 있습니다. 그래서 나는 단지 내가 발견 한 코드로 그것을 자르려고 시도하고 있습니다. here.AVAsset/AVCaptureSession으로 비디오 자르기
-(void)cropVideo:(NSURL*)videoURL{
// input file
AVAsset* asset = [AVAsset assetWithURL:videoURL];
AVMutableComposition *composition = [AVMutableComposition composition];
[composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
// input clip
AVAssetTrack *clipVideoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
// make it square
AVMutableVideoComposition* videoComposition = [AVMutableVideoComposition videoComposition];
videoComposition.renderSize = CGSizeMake(clipVideoTrack.naturalSize.height, clipVideoTrack.naturalSize.height);
videoComposition.frameDuration = CMTimeMake(1, 30);
AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
instruction.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(60, 30));
// rotate to portrait
AVMutableVideoCompositionLayerInstruction* transformer = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:clipVideoTrack];
CGAffineTransform t1 = CGAffineTransformMakeTranslation(clipVideoTrack.naturalSize.height, -(clipVideoTrack.naturalSize.width - clipVideoTrack.naturalSize.height) /2);
CGAffineTransform t2 = CGAffineTransformRotate(t1, M_PI_2);
CGAffineTransform finalTransform = t2;
[transformer setTransform:finalTransform atTime:kCMTimeZero];
instruction.layerInstructions = [NSArray arrayWithObject:transformer];
videoComposition.instructions = [NSArray arrayWithObject: instruction];
// export
exporter = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality] ;
exporter.videoComposition = videoComposition;
NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"final"] URLByAppendingPathExtension:@"mov"];
exporter.outputURL=fileURL;
exporter.outputFileType=AVFileTypeQuickTimeMovie;
[exporter exportAsynchronouslyWithCompletionHandler:^(void){
NSLog(@"Exporting done!");
NSLog(@"exporter's outputURL is %@", exporter.outputURL);
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:self.moviePlayer.view];
self.moviePlayer.fullscreen = YES;
[self.moviePlayer play];
}];}
그러나, 수출을 실행 한 후, 영화가 self.moviePlayer
에서 재생되지 않습니다 여기 내 코드입니다. 그냥 "로드 중 .."갑니다. 원래 videoURL 매개 변수를 사용하여 moviePlayer
을 테스트했는데 문제가 없습니다. 내가 뭘 잘못하고 있는지에 대한 아이디어가 있습니까?
감사