iOS中的视频捕获,长宽比为1:1

时间:2022-08-27 10:50:24

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

我想用iOS摄像头以1:1的比例拍摄视频。

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

我尝试了UIImagePickerController,但是它不提供改变的纵横比。谁能给我一些建议吗?

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

此外,iPhone应用“Viddy”提供了1:1的纵横比视频捕捉http://gyazo.com/1ccba9990bb589961f1d1d1df23b71b84b .png?1364791668

Thanks!

谢谢!

3 个解决方案

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

where

在哪里

  • asset is the input movie file.
  • asset是输入电影文件。
  • cropRegion is the area to crop.
  • cropRegion是种植作物的地区。
  • movieUrl is the target url to save the cropped movie.
  • movieUrl是保存该影片的目标url。

#2


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

Note:

注意:

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

_preview的videoGravity和AVVideoScalingModeKey的videoSettings应该与320x320相同。

#3


-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

我认为没有应用程序的帮助是不可能实现的,或者即使有应用程序,你也可以捕捉视频,然后将其剪辑成1:1

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

where

在哪里

  • asset is the input movie file.
  • asset是输入电影文件。
  • cropRegion is the area to crop.
  • cropRegion是种植作物的地区。
  • movieUrl is the target url to save the cropped movie.
  • movieUrl是保存该影片的目标url。

#2


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

Note:

注意:

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

_preview的videoGravity和AVVideoScalingModeKey的videoSettings应该与320x320相同。

#3


-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

我认为没有应用程序的帮助是不可能实现的,或者即使有应用程序,你也可以捕捉视频,然后将其剪辑成1:1