gpt4 book ai didi

objective-c - 视频捕获 1 :1 aspect ratio in iOS

转载 作者:搜寻专家 更新时间:2023-10-30 19:56:18 27 4
gpt4 key购买 nike

我想使用 1:1 宽高比的 iOS 相机拍摄视频。

我试过使用 UIImagePickerController,但它不提供改变纵横比的功能。谁能给我点意见?

此外,iPhone 应用程序“Viddy”提供 1:1 宽高比视频捕获:

Viddy app

最佳答案

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 的输出。

关于objective-c - 视频捕获 1 :1 aspect ratio in iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15737781/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com