我想用iOS相机以1:1的宽高比捕捉视频。
我尝试使用UIImagePickerController,但它没有提供更改的宽高比。 任何人都可以给我一些想法吗?
此外,iPhone应用程序“Viddy”提供1:1宽高比视频捕捉 http://gyazo.com/1ccba9990bb589961f1d5df23b71b84b.png?1364791668
谢谢!
答案 0 :(得分:5)
AVCaptureVideoPreviewLayer *_preview = [AVVideoCaptureVideoPreviewLayer layerWithSession:_session];
_preview.frame = CGRectMake(0,0,320,320);
_preview.videoGravity = AVLayerVideoGravityResizeAspectFill;
NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
[NSNumber numberWithInt:320], AVVideoWidthKey,
[NSNumber numberWithInt:320], AVVideoHeightKey,
AVVideoScalingModeResizeAspectFill,AVVideoScalingModeKey,
nil];
self.videoInput = [AVAssetWriterInput assetWriterInputWithMediaType: AVMediaTypeVideo
outputSettings: videoSettings];
self.videoInput.transform = CGAffineTransformMakeRotation(M_PI);
if([_writer canAddInput:_videoInput]) // AVAssetWriter *_writer
[_writer addInput:_videoInput];
注意:
_preview的videoGravity和videoSettings AVVideoScalingModeKey应相同,以使输出为320 x 320.
答案 1 :(得分:4)
GPUImageMovie* movieFile = [[GPUImageMovie alloc] initWithAsset:asset];
GPUImageCropFilter *cropFilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0.0, 0.1, 1.0, 0.8)];
[movieFile addTarget:cropFilter];
GPUImageMovieWriter* movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(320.0, 320.0)];
[cropFilter addTarget:movieWriter];
[movieWriter startRecording];
[movieFile startProcessing];
[movieWriter finishRecordingWithCompletionHandler:^{
NSLog(@"Completed Successfully");
[cropFilter removeTarget:movieWriter];
[movieFile removeTarget:cropFilter];
}];
<强>,其中强>
asset
是输入电影文件。cropRegion
是要裁剪的区域。movieUrl
是保存已裁剪影片的目标网址。答案 2 :(得分:-1)
我不认为没有某些应用程序的帮助就可以这样做,或者即使可以使用应用程序,您也可以捕获视频,然后将其裁剪为1:1