I'm following this guide trying to use my Canon EOS 550D as a webcam. It is listed as supported by gphoto2.
So, I connected my Canon to my laptop using a USB-cable, and I had no problems running
$ sudo apt-get install gphoto2 v4l2loopback-utils v4l2loopback-dkms ffmpeg
and
$ sudo modprobe v4l2loopback exclusive_caps=1 max_buffers=2
I can also take a still photo using my Canon using this command
$ gphoto2 --capture-image-and-download
But then, when I try to run
gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0
I get this output:
$ gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
configuration: --prefix=/usr --extra-version=1ubuntu0.1 --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-nvenc --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
Capturing preview frames as movie to 'stdout'. Press Ctrl-C to abort.
[mjpeg @ 0x55cb3671a780] Format mjpeg detected only with low score of 12, misdetection possible!
Input #0, mjpeg, from 'pipe:':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 1056x704, 25 tbr, 1200k tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> rawvideo (native))
[swscaler @ 0x55cb3678c5c0] deprecated pixel format used, make sure you did set range correctly
which is all to be expected, but it stops immediately with this error:
[video4linux2,v4l2 @ 0x55cb36720280] 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!
And I really don't know where to go after this. Any help would be appreciated.
Many device access problems can be resolved through group membership changes.
Specifically, if
ls -l
shows that the group permissions (the second "rwx
" triplet) is "rw
" (e.g."-rw-rw----
"), then, adding oneself to the group that owns the device will grantrw
access.Here's how:
This allows you membership in the group that can
rw
the device, but there is one more step.To make all your processes members of the new group, logout and login. Group memberships are set up at
login
time.To create a single process in the new group (for testing, prior to logout/login):
or, just type the group name. See
man newgrp
.You can get this error if you attempt to output to an existing
/dev/video*
device, such as the webcam integrated into your laptop. So try outputting/dev/video1
or/dev/video2
instead.Or choose the device number when you enable v4l2loopback:
Now you can output to
/dev/video76
.See v4l2loopback README.md for more info.