未知的 V4L2 像素格式等效于 yuvj420p

Unknown V4L2 pixel format equivalent for yuvj420p

我正在尝试将位于 Videos/video.mp4 的 mp4 视频传输到位于 /dev/video0.

的虚拟网络摄像头设备

我试过了运行: ffmpeg -re -i Videos/video.mp4 -map 0:v -f v4l2 /dev/video0 我不断收到以下错误:

[video4linux2,v4l2 @ 0x5580cf270100] Unknown V4L2 pixel format equivalent for yuvj420p
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 -- 
Conversion failed!

完整日志:

ffmpeg version 4.2.2-1+b1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9 (Debian 9.2.1-28)
  configuration: --prefix=/usr --extra-version=1+b1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Videos/video.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2020-03-23T04:24:01.000000Z
    com.android.version: 8.1.0
  Duration: 00:01:00.14, start: 0.000000, bitrate: 20048 kb/s
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuvj420p(pc, smpte170m), 1920x1080, 19898 kb/s, SAR 1:1 DAR 16:9, 29.43 fps, 29.58 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      rotate          : 270
      creation_time   : 2020-03-23T04:24:01.000000Z
      handler_name    : VideoHandle
    Side data:
      displaymatrix: rotation of 90.00 degrees
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
    Metadata:
      creation_time   : 2020-03-23T04:24:01.000000Z
      handler_name    : SoundHandle
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> rawvideo (native))
Press [q] to stop, [?] for help
[video4linux2,v4l2 @ 0x5580cf270100] Unknown V4L2 pixel format equivalent for yuvj420p
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 -- 
Conversion failed!

期望的结果是尝试查看网络摄像头的应用程序可以看到 mp4 视频。我 运行 在没有网络摄像头或视频界面的桌面上,这就是我使用 /dev/video0

的原因

添加 -vf format=yuv420p(或别名 -pix_fmt yuv420p)。

v4l2 输出设备不支持 yuvj420p,这是您输入的像素格式。大多数情况下ffmpeg会自动选择支持的像素格式,但V4L2输出无法这样做,所以你必须手动选择:

ffmpeg -re -i Videos/video.mp4 -map 0:v -vf format=yuv420p -f v4l2 /dev/video0