在Mac上使用AVFoundation和AVCaptureVideoDataOutput时如何使用自定义视频分辨率 [英] How to use custom video resolution when use AVFoundation and AVCaptureVideoDataOutput on mac
问题描述
我需要处理捕获的视频帧的每一帧,尽管AVCaptureDevice.formats
提供了许多不同尺寸的帧大小,但AVCaptureSession
似乎仅支持预设中定义的那些帧大小.
I need to process each frame of captured video frame, although AVCaptureDevice.formats
provided so many different dimension of frame sizes, it seems AVCaptureSession
only support those frame sizes defined in presets.
我还尝试在AVCaptureInputDevice
之前或之后设置AVCaptureDevice.activeFormat
,无论我设置了什么设置,如果我在AVCaptureSession
中设置AVCaptureSessionPresetHigh
,它总是给我1280x720的帧.类似地,如果我将AVCaptureSessionPreset
设置为640x480,那么我只能获得640x480的帧大小.
I've also tried to set AVCaptureDevice.activeFormat
before AVCaptureInputDevice
or after, no matter what setting I set, if I set AVCaptureSessionPresetHigh
in AVCaptureSession
, it always give me a frame of 1280x720. Similar , If i set AVCaptureSessionPreset
640x480, then I can only get frame size of 640x480.
那么,如何设置自定义视频帧大小(如800x600)? 使用Windows下的Media Foundation或Linux下的V4L2,在捕获时可以轻松设置任何自定义帧大小.
So, How can I set a custom video frame size like 800x600? Using Media Foundation under windows or V4L2 under linux, it's easy to set any custom frame size when capture.
在Mac上似乎无法做到这一点.
It seems not possible to do this under mac.
推荐答案
AFAIK无法执行此操作.我见过的所有用于视频捕获的代码都使用这些预设.
AFAIK there isn't a way to do this. All the code I've seen to do video capture uses the presets.
AVCaptureVideoDataOutput的文档的视频设置属性说
当前唯一支持的密钥是kCVPixelBufferPixelFormatTypeKey密钥.
The only key currently supported is the kCVPixelBufferPixelFormatTypeKey key.
,因此传递视频设置的其他答案将不起作用,并且只会忽略这些参数.
so the other answers of passing in video settings won't work and it will just ignore these parameters.
这篇关于在Mac上使用AVFoundation和AVCaptureVideoDataOutput时如何使用自定义视频分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!