1

I'm trying to switch from one advertised resolution/framerate to a different one on the fly, preferably while other applications are consuming the v4l2loopback feed. As an example, I feed a 1920x1080 black screen video into /dev/video2, and then open it in vlc. This works fine:

$ ffmpeg -f lavfi -i color=c=black:s=1920x1080:r=25/1 -vcodec rawvideo -pix_fmt yuv420p -f v4l2 /dev/video2
$ ffmpeg -f v4l2 -list_formats all -i /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
[video4linux2,v4l2 @ 0x55864f9b06c0] Raw       :     yuv420p :     Planar YUV 4:2:0 : 1920x1080
/dev/video2: Immediate exit requested

However, killing the old feed and then streaming a different resolution into the device does not change the advertised capabilities, and just scrambles the screen in vlc.

$ ffmpeg -f lavfi -i color=c=black:s=1280x800:r=25/1 -vcodec rawvideo -pix_fmt yuv420p -f v4l2 /dev/video2

# The list_formats options are still the same (only 1920x1080)
# vlc shows a green instead of a black screen

Is it possible to change this on the fly?

0

as long as the device is opened, it's resolution (and format) are fixed.

so the answer to your question is: no, you can't change these settings on the fly.

(unless you quit all consumers (in your case: VLC) before starting the new ffmpeg; but that's not what i would call "on the fly")

this is a limitation of the V4L2 API, where you cannot signal a resolution/format change to any attached application.

there also seems to be an issue with ffmpeg, which should either

  • adjust the output frame-size if it cannot change it
  • or refuse to run

(it could also be a bug in the v4l2loopback module (not properly reporting back that the framesize didn't change), but with GStreamer it seems to work as expected, so I'm not sure about it)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.