首页 > 解决方案 > ffmpeg:kmsgrab 到 v4l2 环回设备

问题描述

我一直在尝试将我的屏幕通过管道传输到 v4l2 环回设备(作为在 Wayland 通话期间共享屏幕的黑客)。这是我到目前为止所尝试的:

$ sudo modprobe vl42loopback 
$ sudo ffmpeg -device /dev/dri/card0 -f kmsgrab -i - -vf 'hwmap=derive_device=vaapi,scale_vaapi=w=1920:h=1080:format=nv12' -f v4l2 /dev/video2 
ffmpeg version n4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 10.1.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-avisynth --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librav1e --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
[kmsgrab @ 0x55f52ac85380] Using plane 55 to locate framebuffers.
[kmsgrab @ 0x55f52ac85380] Template framebuffer is 99: 3840x2160 32bpp 32b depth.
Input #0, kmsgrab, from 'pipe:':
  Duration: N/A, start: 1600327750.235546, bitrate: N/A
    Stream #0:0: Video: wrapped_avframe, drm_prime, 3840x2160, 29.83 tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (wrapped_avframe (native) -> rawvideo (native))
[video4linux2,v4l2 @ 0x55f52ac89e40] Unknown V4L2 pixel format equivalent for vaapi_vld
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 -- 
Conversion failed!

还尝试添加-vcodec rawvideo -pix_fmt yuv420p如下:

sudo ffmpeg -device /dev/dri/card0 -f kmsgrab -i - -vf 'hwmap=derive_device=vaapi,scale_vaapi=w=1920:h=1080:format=nv12' -vcodec rawvideo -pix_fmt yuv420p -f v4l2 /dev/video2

失败了:

....
Stream mapping:
  Stream #0:0 -> #0:0 (wrapped_avframe (native) -> rawvideo (native))
Impossible to convert between the formats supported by the filter 'Parsed_scale_vaapi_1' and the filter 'auto_scaler_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:0
Conversion failed!

我怎样才能得到这个工作?

标签: ffmpegv4l2loopback

解决方案


推荐阅读