4

我想用 1:1 纵横比的 iOS 相机拍摄视频。

我试过了UIImagePickerController,但它不提供改变纵横比。谁能给我一些想法?

此外,iPhone 应用程序“Viddy”提供 1:1 纵横比视频捕捉:

Viddy 应用程序

4

3 回答 3

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

笔记:

_preview 的 videoGravity 和 videoSettings AVVideoScalingModeKey 应该相同才能获得 320 x 320 的输出。

于 2013-06-04T05:14:35.243 回答
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是保存裁剪后的电影的目标 url。
于 2013-05-30T12:30:34.557 回答
-1

我认为没有某些应用程序的帮助是不可能做到这一点的,或者即使有一个应用程序可以做到,您也可以捕获视频然后将其裁剪为 1:1

于 2013-04-01T04:56:49.723 回答