ffmpeg - 如何在将流编码到 v4l2-loopback 设备时将相机录制到文件?

标签 ffmpeg v4l2 logitech v4l2loopback

所以我有这个罗技 c920 相机 1920x1080 h264 功能,我想将相机记录到文件中,同时将流复制/编码到环回设备,这样相机仍然可以被其他应用程序使用。
这是我到目前为止得到的代码:

ffmpeg -report -f alsa -i hw:CARD=C920,DEV=0 -r 1500 -s 1920x1080 -f v4l2 -vcodec h264 \
-i /dev/video1 -copyinkf -vcodec copy /home/jonatas/Videos/2021-02-01185658.mp4 \ 
-f v4l2 /dev/video0
错误:
Unknown V4L2 pixel format equivalent for yuvj420p
Could not write header for output file #1 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 1:0 -- 
/dev/video0(loopbackdevice) 上的一些信息:
v4l2-ctl -d /dev/video0

    Device Caps      : 0x05208003
        Video Capture
        Video Output
        Video Memory-to-Memory
        Read/Write
        Streaming
        Extended Pix Format
Priority: 0
Video input : 0 (loopback: ok)
Video output: 0 (loopback in)
Format Video Output:
    Width/Height      : 1280/720
    Pixel Format      : 'YUYV' (YUYV 4:2:2)
    Field             : None
    Bytes per Line    : 2560
    Size Image        : 1843200
    Colorspace        : sRGB
    Transfer Function : Default (maps to sRGB)
    YCbCr/HSV Encoding: Default (maps to ITU-R 601)
    Quantization      : Default (maps to Limited Range)
    Flags             : 
Streaming Parameters Video Capture:
    Frames per second: 30.000 (30/1)
    Read buffers     : 8
Streaming Parameters Video Output:
    Frames per second: 30.000 (30/1)
    Write buffers    : 8

User Controls

                    keep_format 0x0098f900 (bool)   : default=0 value=0
              sustain_framerate 0x0098f901 (bool)   : default=0 value=0
                        timeout 0x0098f902 (int)    : min=0 max=100000 step=1 default=0 value=0
               timeout_image_io 0x0098f903 (bool)   : default=0 value=0
/dev/video1 中关于我的相机的一些信息
v4l2-ctl -d /dev/video1 --all
Driver Info:
    Driver name      : uvcvideo
    Card type        : HD Pro Webcam C920
    Bus info         : usb-0000:00:14.0-7.2
    Driver version   : 5.4.78
    Capabilities     : 0x84a00001
        Video Capture
        Metadata Capture
        Streaming
        Extended Pix Format
        Device Capabilities
    Device Caps      : 0x04200001
        Video Capture
        Streaming
        Extended Pix Format
Media Driver Info:
    Driver name      : uvcvideo
    Model            : HD Pro Webcam C920
    Serial           : EC6C336F
    Bus info         : usb-0000:00:14.0-7.2
    Media version    : 5.4.78
    Hardware revision: 0x00000011 (17)
    Driver version   : 5.4.78
Interface Info:
    ID               : 0x03000002
    Type             : V4L Video
Entity Info:
    ID               : 0x00000001 (1)
    Name             : HD Pro Webcam C920
    Function         : V4L2 I/O
    Flags         : default
    Pad 0x01000007   : 0: Sink
      Link 0x0200001f: from remote pad 0x100000a of entity 'Processing 3': Data, Enabled, Immutable
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
    Width/Height      : 1280/720
    Pixel Format      : 'H264' (H.264)
    Field             : None
    Bytes per Line    : 2560
    Size Image        : 1843200
    Colorspace        : sRGB
    Transfer Function : Default (maps to sRGB)
    YCbCr/HSV Encoding: Default (maps to ITU-R 601)
    Quantization      : Default (maps to Full Range)
    Flags             : 
Crop Capability Video Capture:
    Bounds      : Left 0, Top 0, Width 1280, Height 720
    Default     : Left 0, Top 0, Width 1280, Height 720
    Pixel Aspect: 1/1
Selection Video Capture: crop_default, Left 0, Top 0, Width 1280, Height 720, Flags: 
Selection Video Capture: crop_bounds, Left 0, Top 0, Width 1280, Height 720, Flags: 
Streaming Parameters Video Capture:
    Capabilities     : timeperframe
    Frames per second: 30.000 (30/1)
    Read buffers     : 0
                     brightness 0x00980900 (int)    : min=0 max=255 step=1 default=128 value=128
                       contrast 0x00980901 (int)    : min=0 max=255 step=1 default=128 value=128
                     saturation 0x00980902 (int)    : min=0 max=255 step=1 default=128 value=128
 white_balance_temperature_auto 0x0098090c (bool)   : default=1 value=1
                           gain 0x00980913 (int)    : min=0 max=255 step=1 default=0 value=255
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=2 value=2
                0: Disabled
                1: 50 Hz
                2: 60 Hz
      white_balance_temperature 0x0098091a (int)    : min=2000 max=6500 step=1 default=4000 value=3233 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=255 step=1 default=128 value=128
         backlight_compensation 0x0098091c (int)    : min=0 max=1 step=1 default=0 value=0
                  exposure_auto 0x009a0901 (menu)   : min=0 max=3 default=3 value=3
                1: Manual Mode
                3: Aperture Priority Mode
              exposure_absolute 0x009a0902 (int)    : min=3 max=2047 step=1 default=250 value=333 flags=inactive
         exposure_auto_priority 0x009a0903 (bool)   : default=0 value=0
                   pan_absolute 0x009a0908 (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                  tilt_absolute 0x009a0909 (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                 focus_absolute 0x009a090a (int)    : min=0 max=250 step=5 default=0 value=0
                     focus_auto 0x009a090c (bool)   : default=1 value=0
                  zoom_absolute 0x009a090d (int)    : min=100 max=500 step=1 default=100 value=100
如果我删除脚本的第 3 行,相机会将视频和声音流完美地记录到文件中。我在第 3 行尝试了不同的东西,如 -vcodec 以及与 YUYV 的 pix-format 标志有关的东西,但没有成功。
是否可以仅通过一个 ffmpeg 进程来实现这一目标?
声音是否也可用于环回设备?
如何将其转码为环回设备使用的正确像素格式?

最佳答案

How to transcode it to the proper pixel format used by loopback device?


添加 format筛选:
ffmpeg -f alsa -i hw:CARD=C920,DEV=0 -f v4l2 -i /dev/video1 -c copy output.mp4 -f v4l2 -vf format=yuv420p /dev/video0

Will the sound be made available to the loopback device also?


不可以。V4L2 输出设备只支持视频。

关于ffmpeg - 如何在将流编码到 v4l2-loopback 设备时将相机录制到文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66019334/

相关文章:

video - 尽管使用了 avformat_write_header,mpg 中仍缺少 header

ios - 用 librtmp 编译 ffmpeg

ffmpeg 无效的缩放尺寸 - swScaler

python - Linux 上的 OpenCV(通过 python): Set frame width/height?

linux - 将/dev/video0 的输出转储到 fifo 文件

windows - 仅在 Windows 上按住按钮的 Marble Trackman Scroll

python - 是否可以为罗技 G15 进行 Python 编程?

ffmpeg - 为什么实时视频流不流畅,而音频流编码后用Flash RTMP播放器播放正常

linux - 如何使用v4l2读取视频文件

keyboard - 罗技 MX Keys 键盘上的查找按钮有什么作用?