v4l2:限制网络摄像头提供的分辨率

v4l2:限制网络摄像头提供的分辨率

我使用 HDMI 采集卡将普通无反光镜相机用作网络摄像头。这在 1080p 或 720p 分辨率下效果很好,但采集卡不仅提供 16:9 宽高比的分辨率,还提供 4:3 的分辨率。如果选择这样的分辨率,则视频信号会被拉伸/扭曲。不幸的是,我使用的程序之一总是选择这种扭曲的分辨率。

以下是输出v4l2-ctl -d /dev/video0 --list-formats-ext

ioctl: VIDIOC_ENUM_FMT
    Type: Video Capture

    [0]: 'MJPG' (Motion-JPEG, compressed)
        Size: Discrete 1920x1080
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
        Size: Discrete 1600x1200
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
        Size: Discrete 1360x768
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
        Size: Discrete 1280x1024
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
        Size: Discrete 1280x960
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.020s (50.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
        Size: Discrete 1024x768
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.020s (50.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
        Size: Discrete 800x600
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.020s (50.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
        Size: Discrete 720x576
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.020s (50.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
        Size: Discrete 720x480
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.020s (50.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
        Size: Discrete 640x480
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.020s (50.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
    [1]: 'YUYV' (YUYV 4:2:2)
        Size: Discrete 1920x1080
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1600x1200
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1360x768
            Interval: Discrete 0.125s (8.000 fps)
        Size: Discrete 1280x1024
            Interval: Discrete 0.125s (8.000 fps)
        Size: Discrete 1280x960
            Interval: Discrete 0.125s (8.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.100s (10.000 fps)
        Size: Discrete 1024x768
            Interval: Discrete 0.100s (10.000 fps)
        Size: Discrete 800x600
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 720x576
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 720x480
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)

有没有办法禁用其中一些分辨率,以便访问网络摄像头的软件不会选择非 16:9 的宽高比?

答案1

我发现的一个解决方法是使用 v4l2-loopback 创建第二个虚拟设备,然后使用 ffmpeg 将所需的分辨率流式传输到该设备。

首先,创建虚拟设备/dev/video7

sudo modprobe v4l2loopback devices=1 video_nr=7 card_label="VirtualCam" exclusive_caps=1

要将视频数据从 传输/dev/video0/dev/video7

ffmpeg -f video4linux2 -framerate 25 -video_size 1280x720 -input_format mjpeg -i /dev/video0 -f v4l2 -pix_fmt yuv420p /dev/video7

但是这感觉像是黑客行为,如果我可以直接更改原始视频设备的宣传功能,那就更好了。因此,如果有人能回答这个问题,我将不胜感激。

相关内容