大佬教程收集整理的这篇文章主要介绍了iOS:在视频中裁剪视频奇怪的绿线左侧和底侧,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
视频裁剪方法.
-(void)cropButton { CGRect cropFrame = self.cropView.croppedImageFrame; //load our movie Asset AVAsset *asset; asset = [AVAsset assetWithURL:[NSURL fileURLWithPath:[self.videoDataArr objectATindex:self.SELEctedIndex-1]]]; //create an avassetrack with our asset AVAssetTrack *clipVideoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectATindex:0]; //create a video composition and preset some setTings AVMutableVideoComposition* videoComposition = [AVMutableVideoComposition videoComposition]; videoComposition.frameDuration = CMTimeMake(1,30); //create a video instruction AVMutableVideoCompositioninstruction *instruction = [AVMutableVideoCompositioninstruction videoCompositioninstruction]; instruction.timeRange = CMTimeRangeMake(kCMTimeZero,asset.duration); AVMutableVideoCompositionLayerinstruction* transformer = [AVMutableVideoCompositionLayerinstruction videoCompositionLayerinstructionWithAssetTrack:clipVideoTrack]; UIImageOrientation videoOrientation = [self getVideoOrientationFromAsset:asset]; CGAffineTransform t1 = CGAffineTransformIdentity; CGAffineTransform t2 = CGAffineTransformIdentity; switch (videoOrientation) { case UIImageOrientationUp: t1 = CGAffineTransformMakeTranslation(clipVideoTrack.naturalSize.height - cropFrame.origin.x,0 - cropFrame.origin.y); t2 = CGAffineTransformRotate(t1,M_PI_2); break; case UIImageOrientationDown: t1 = CGAffineTransformMakeTranslation(0 - cropFrame.origin.x,clipVideoTrack.naturalSize.width - cropFrame.origin.y ); // not fixed width is the real height in upside down t2 = CGAffineTransformRotate(t1,- M_PI_2); break; case UIImageOrientationRight: t1 = CGAffineTransformMakeTranslation(0 - cropFrame.origin.x,0 ); break; case UIImageOrientationLeft: t1 = CGAffineTransformMakeTranslation(clipVideoTrack.naturalSize.width - cropFrame.origin.x,clipVideoTrack.naturalSize.height - cropFrame.origin.y ); t2 = CGAffineTransformRotate(t1,M_PI); break; default: NSLog(@"no supported orientation has been found in this video"); break; } CGAffineTransform finalTransform = t2; videoComposition.renderSize = CGSizeMake(cropFrame.size.width,cropFrame.size.height); [transformer setTransform:finalTransform atTime:kCMTimeZero]; //add the transformer layer instructions,then add to video composition instruction.layerinstructions = [NSArray arrayWithObject:transformer]; videoComposition.instructions = [NSArray arrayWithObject: instruction]; //Create an Export Path to store the cropped video NSString * documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectATindex:0]; __block NSString *exportPath = [documentsPath StringByAppendingFormat:@"/CroppedVideo.mp4"]; NSURL *exportUrl = [NSURL fileURLWithPath:exportPath]; //Remove any prevouis videos at that path [[NSFileManager defaultManager] removeItemAtURL:exportUrl error:nil]; AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality] ; exporter.videoComposition = videoComposition; exporter.outputURL = exportUrl; NSLog(@"exported url : %@",exportUrl); exporter.outputFileType = AVFileTypeQuickTimeMovie; [exporter exportAsynchronouslyWithCompletionHandler:^ { dispatch_async(dispatch_get_main_queue(),^{ switch ([exporter status]) { case AVAssetExportSessionStatusCompleted: { self.navigationController.toolbarHidden = YES; NSError *error = nil; NSString *targetPath; targetPath = [self.videoDataArr objectATindex:self.SELEctedIndex-1]; [FILEMANAGER removeItemAtPath:targetPath error:&error]; if(error) { NSLog(@"Error is : %@",error); } error = nil; [FILEMANAGER moveItemAtPath:exportPath toPath:targetPath error:&error]; if(error) { NSLog(@"Error is : %@",error); } self.mySAVideoRangeSlider.videoUrl = self.videourl; [self.mySAVideoRangeSlider getMovieFrame]; } break; } case AVAssetExportSessionStatusFailed: NSLog(@"Export Failed: %@",[[exporter error] localizedDescription]); break; case AVAssetExportSessionStatusCancelled: NSLog(@"Export canceled"); break; default: NSLog(@"NONE"); dispatch_async(dispatch_get_main_queue(),^{ }); break; } }); }]; }
视频裁剪后看到视频裁剪绿线,如何解决它.
以上是大佬教程为你收集整理的iOS:在视频中裁剪视频奇怪的绿线左侧和底侧全部内容,希望文章能够帮你解决iOS:在视频中裁剪视频奇怪的绿线左侧和底侧所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。