Video capture with 1:1 aspect ratio in iOS

血红的双手。 提交于 2019-12-12 07:06:45

问题


I want to capture videos with iOS camera with 1:1 aspect ratio.

I tried with UIImagePickerController, but it don't provide changing aspect ratio. Could anyone give me ideas?

Additionally, iPhone app "Viddy" provides 1:1 aspect ratio video capturing http://gyazo.com/1ccba9990bb589961f1d5df23b71b84b.png?1364791668

Thanks!


回答1:


 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];
    }];

where

  • asset is the input movie file.
  • cropRegion is the area to crop.
  • movieUrl is the target url to save the cropped movie.



回答2:


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];

Note:

_preview's videoGravity and the videoSettings AVVideoScalingModeKey should be same to get the output as 320 x 320.




回答3:


I don't think it's possible to do so without help of some app, or even if it's possible with an app, you can capture video then crop it to 1:1



来源:https://stackoverflow.com/questions/15737781/video-capture-with-11-aspect-ratio-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!