裁剪 CMSampleBufferRef 样本

3
我正在使用AVCaptureVideoDataOutput来捕获相机视频。我想裁剪CMSampleBufferRef以使最终视频成为正方形,但我找不到解决方法。你有什么想法吗?
请不要提供AVAssetExportSession
谢谢。

1
你可以利用CoreImage对其进行过滤,通过利用ciimages initWithCVImageBuffer:的优势。 - Jack
1个回答

1

暂时地,你可以尝试在类似以下的东西上设置一个字典,其中包含你的widthheight

NSDictionary* videoSettingsDictionary = @{
    (id)kCVPixelBufferWidthKey : @(width),
    (id)kCVPixelBufferHeightKey : @(height),
    AVVideoScalingModeKey : AVVideoScalingModeFit
};
[yourAVCaptureVideoDataOutput setVideoSettings:videoSettingsDictionary];

据说,AVVideoScalingModeFit会强制AVCaptureVideoDataOutput裁剪掉边缘处理区域,并通过减少指定的宽度或高度来保持裁剪源的纵横比。(链接到AVF文档

有趣的是,文档中只提到支持 kCVPixelBufferPixelFormatTypeKey 这个键,但实际上也支持其他提到的键。(https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureVideoDataOutput_Class/Reference/Reference.html#//apple_ref/occ/instp/AVCaptureVideoDataOutput/videoSettings) - miguelao
2
很遗憾,似乎这个不再起作用了。尝试使用给定的键设置视频设置字典会打印出“videoSettings字典包含一个或多个不受支持(被忽略)的键:(AVVideoScalingModeKey,Height,Width)”。 - vedosity
还有其他的解决方案吗?我卡住了...谢谢。 - famfamfam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接