4

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

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

Additionally, the iPhone app "Viddy" provides 1:1 aspect ratio video capturing:

Viddy app

Vukašin Manojlović
  • 3,717
  • 3
  • 19
  • 31
ksh
  • 399
  • 2
  • 16

3 Answers3

6
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.

arunit21
  • 670
  • 1
  • 11
  • 25
  • What is self in above coding ??? please let me know because i think this is the right solution for video croping. – Parvez Belim Aug 31 '13 at 12:13
  • self is a custom class for me I have "CameraRecorder.h .m classes" and I have a property AVAssetWriterInput* videoInput. – arunit21 Apr 18 '14 at 05:32
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];
    }];

where

  • asset is the input movie file.
  • cropRegion is the area to crop.
  • movieUrl is the target url to save the cropped movie.
Sugan S
  • 1,782
  • 7
  • 25
  • 47
arunit21
  • 670
  • 1
  • 11
  • 25
  • I tried the above method but it is taking to much time.For 12 second video it is taking more than 12 seconds to trim...Please let me know if there is any solution available to improve speed. – Parvez Belim Aug 31 '13 at 12:03
-1

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