Following the guide in this question I did:
$ sudo modprobe v4l2loopback
$ ffmpeg -f x11grab -r 15 -s 1280x720 -i :0.0+0,0 -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0
The device /dev/video0
shows up as expected but the ffmpeg command fails with following output:
$ ffmpeg -f x11grab -r 15 -s 1280x720 -i :0.0+0,0 -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0
ffmpeg version 4.0 Copyright (c) 2000-2018 the FFmpeg developers
...
[x11grab @ 0x559767794cc0] Stream #0: not enough frames to estimate rate; consider increasing probesize
....
[v4l2 @ 0x55976779e6c0] ioctl(VIDIOC_G_FMT): Invalid argument
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 --
Conversion failed!
I already tried to follow the suggestions below the answer to no avail. I noticed that v4l2 is listed as demux only in ffmpeg -formats
. Does that mean I can't use it for output to /dev/video0
? If so, what should I use instead? I tried h264
but that crashes after ~1000 frames with following error message:
$ ffmpeg -f x11grab -r 15 -s 1280x720 -i :0.0+0,0 -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f h264 /dev/video0
ffmpeg version 4.0 Copyright (c) 2000-2018 the FFmpeg developers
...
[x11grab @ 0x55da61e29cc0] Stream #0: not enough frames to estimate rate; consider increasing probesize
...
File '/dev/video0' already exists. Overwrite ? [y/N] y
....
Error writing trailer of /dev/video0: Invalid argument
....
Conversion failed!
Answer
v4l2loopback v0.11.0 has a bug which is now fixed, so there is no need to manually change the source code as shown in the bug report. As of now there is no newer release version with the fix, so upgrade to the master branch which contains the fix.
Arch Linux
Until a new release version comes out you can use the AUR package v4l2loopback-dkms-git instead of v4l2loopback-dkms.
Debian & Ubuntu
sudo apt-get remove v4l2loopback-dkms
sudo apt-get install build-essential libelf-dev linux-headers-$(uname -r) unzip
wget https://github.com/umlaeute/v4l2loopback/archive/master.zip
unzip master.zip
cd v4l2loopback-master
make
sudo make install
sudo depmod -a
sudo modprobe v4l2loopback
Grab desktop:
ffmpeg -f x11grab -framerate 25 -video_size 1280x720 -i :0.0+0,0 -f v4l2 /dev/video0
Send file:
ffmpeg -re input.mp4 -f v4l2 /dev/video0
ffplay
ffplay -f v4l2 /dev/video0
mpv
mpv --demuxer-lavf-format v4l2 /dev/video0
VLC
Media → Open Capture Device
No comments:
Post a Comment