gphoto2 icon indicating copy to clipboard operation
gphoto2 copied to clipboard

canon 6d dslr as a webcam

Open norayr opened this issue 2 years ago • 3 comments

not sure it is a bug, or it is a gphoto2 bug.

i used to use my canon 6d dslr as a webcam with ffmpeg and gphoto2.

i was loading v4lloopabck module

modprobe v4l2loopback exclusive_caps=1 max_buffers=2

now it doesn't work i also tried to load module without any arguments but it doesn't help.

then i was doing:

gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -s 1024x683 -threads 2 -f v4l2 /dev/video4

or

gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -s 1368x912 -threads 2 -f v4l2 /dev/video4

in order to create a /dev/video4 device and start using it as a webcam. i specifically calculated the resolutions, because with those there is no distortion.

then i remember i had different problems with the setup last half of a year 2021.

right now i made new tests, and here are my problems now:

 # gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -s 1024x683 -threads 2 -f v4l2 /dev/video4
ffmpeg version 4.4.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11.2.1 (Gentoo 11.2.1_p20220115 p4) 20220115
  configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --docdir=/usr/share/doc/ffmpeg-4.4.1-r3/html --mandir=/usr/share/man --enable-shared --cc=x86_64-pc-linux-gnu-gcc --cxx=x86_64-pc-linux-gnu-g++ --ar=x86_64-pc-linux-gnu-ar --nm=x86_64-pc-linux-gnu-nm --strip=x86_64-pc-linux-gnu-strip --ranlib=x86_64-pc-linux-gnu-ranlib --pkg-config=x86_64-pc-linux-gnu-pkg-config --optflags='-O2 -march=tigerlake -pipe' --extra-libs= --disable-static --enable-avfilter --enable-avresample --disable-stripping --disable-optimizations --disable-libcelt --disable-indev=oss --disable-indev=sndio --disable-outdev=oss --disable-outdev=sndio --enable-bzlib --disable-runtime-cpudetect --disable-debug --enable-gcrypt --enable-gnutls --disable-gmp --enable-gpl --disable-hardcoded-tables --enable-iconv --disable-libxml2 --disable-lzma --enable-network --disable-opencl --disable-openssl --enable-postproc --disable-libsmbclient --enable-ffplay --enable-sdl2 --disable-vaapi --disable-vdpau --disable-vulkan --enable-xlib --enable-libxcb --enable-libxcb-shm --enable-libxcb-xfixes --enable-zlib --disable-libcdio --disable-libiec61883 --disable-libdc1394 --disable-libcaca --enable-openal --enable-opengl --disable-libv4l2 --disable-libpulse --disable-libdrm --enable-libjack --disable-libopencore-amrwb --disable-libopencore-amrnb --disable-libcodec2 --enable-libdav1d --disable-libfdk-aac --disable-libopenjpeg --disable-libbluray --enable-libgme --enable-libgsm --disable-libaribb24 --disable-mmal --disable-libmodplug --enable-libopus --disable-libilbc --enable-librtmp --disable-libssh --enable-libspeex --disable-libsrt --enable-librsvg --disable-ffnvcodec --enable-libvorbis --enable-libvpx --disable-libzvbi --disable-appkit --disable-libbs2b --disable-chromaprint --disable-cuda-llvm --disable-libflite --disable-frei0r --disable-libvmaf --disable-libfribidi --disable-fontconfig --disable-ladspa --disable-libass --disable-libtesseract --disable-lv2 --enable-libfreetype --disable-libvidstab --disable-librubberband --disable-libzmq --enable-libzimg --disable-libsoxr --enable-pthreads --disable-libvo-amrwbenc --enable-libmp3lame --enable-libkvazaar --disable-libaom --disable-libopenh264 --disable-librav1e --enable-libsnappy --disable-libsvtav1 --enable-libtheora --disable-libtwolame --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --disable-amf --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-neon --disable-vfp --disable-vfpv3 --disable-armv8 --disable-mipsdsp --disable-mipsdspr2 --disable-mipsfpu --disable-altivec --disable-vsx --disable-power8 --disable-amd3dnow --disable-amd3dnowext --disable-aesni --disable-avx --disable-avx2 --disable-fma3 --disable-fma4 --disable-sse3 --disable-ssse3 --disable-sse4 --disable-sse42 --disable-xop --enable-pic --cpu=tigerlake --disable-doc --disable-htmlpages --enable-manpages
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Capturing preview frames as movie to 'stdout'. Press Ctrl-C to abort.
[mjpeg @ 0x55790ffbfe90] Format mjpeg detected only with low score of 25, misdetection possible!
Input #0, mjpeg, from 'pipe:':
  Duration: N/A, bitrate: N/A
  Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 960x640, 25 tbr, 1200k tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> rawvideo (native))
[swscaler @ 0x557910022400] deprecated pixel format used, make sure you did set range correctly
[video4linux2,v4l2 @ 0x55790ffc25e0] Unable to open V4L2 device '/dev/video4'
Could not write header for output file #0 (incorrect codec parameters ?): No such file or directory
Error initializing output stream 0:0 --
Conversion failed!

i tried to remove the pixel format, or to use yuvj422p like i see in the output. tried to remove the resolution from the commandline, nothing helped.

so my two main problems might be: Format mjpeg detected only with low score of 25, misdetection possible!

and

deprecated pixel format used, make sure you did set range correctly.

tried to list pixel formats and set a couple randomly and it did not help.

some more tests for you, those are successful:

 # env LANG=C gphoto2 --debug --debug-logfile=capture-preview.txt --capture-preview
Saving file as capture_preview.jpg

actually gets the jpeg file.

and the following actually captures movie:

 # env LANG=C gphoto2 --debug --debug-logfile=capture-movie.txt --capture-movie
Capturing preview frames as movie to 'movie.mjpg'. Press Ctrl-C to abort.
^C
Cancelling...
Ctrl-C pressed ... Exiting.
Movie capture finished (188 frames)

here, i can play it:

# mplayer movie.mjpg
MPlayer 1.4-11.2.1 (C) 2000-2019 MPlayer Team

Playing movie.mjpg.
libavformat version 58.76.100 (external)
libavformat file format detected.
[lavf] stream 0: video (mjpeg), -vid 0
VIDEO:  [MJPG]  960x640  0bpp  25.000 fps    0.0 kbps ( 0.0 kbyte/s)
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
libavcodec version 58.134.100 (external)
[mjpeg @ 0x7fbe016779c0]Requested frame threading with a custom get_buffer2() implementation which is not marked as thread safe. This is not supported anymore, make your callback thread-safe.
Selected video codec: [ffmjpeg] vfm: ffmpeg (FFmpeg MJPEG)
==========================================================================
Load subtitles in ./
Audio: no sound
Starting playback...
Could not find matching colorspace - retrying with -vf scale...
Opening video filter: [scale]
Movie-Aspect is undefined - no prescaling applied.
[swscaler @ 0x7fbe01f7d120]bicubic scaler, from yuv422p to yuyv422 using MMXEXT
[swscaler @ 0x7fbe01f7d120]using unscaled yuv422p -> yuyv422 special converter
VO: [xv] 960x640 => 960x640 Packed YUY2
Movie-Aspect is undefined - no prescaling applied.
VO: [xv] 960x640 => 960x640 Packed YUY2
V:   4.1   0/  0 16%  1%  0.0% 0 0

Exiting... (Quit)
 

Name the camera camera is detected:

# gphoto2 --auto-detect
Model                          Port
----------------------------------------------------------
Canon EOS 6D                   usb:003,031

libgphoto2 and gphoto2 version output of: gphoto2 --version

# gphoto2 --version
gphoto2 2.5.28

Copyright (c) 2000-2021 Marcus Meissner and others

gphoto2 comes with NO WARRANTY, to the extent permitted by law. You may
redistribute copies of gphoto2 under the terms of the GNU General Public
License. For more information about these matters, see the files named COPYING.

This version of gphoto2 is using the following software versions and options:
gphoto2         2.5.28         x86_64-pc-linux-gnu-gcc, popt(m), exif, cdk, aa, jpeg, readline
libgphoto2      2.5.29         NON-STANDARD CAMLIB SET (canon fuji ptp2), x86_64-pc-linux-gnu-gcc, no ltdl, EXIF
libgphoto2_port 0.12.0         iolibs: disk ptpip usb1 usbdiskdirect usbscsi, x86_64-pc-linux-gnu-gcc, no ltdl, EXIF, USB, no serial

i use gentoo, and i only compiled ptp2, canon, fuji backends. it always worked for me.

To Reproduce please see the above

If its a camera misbehavior, attach debug output using --debug --debug-logfile=debug.log (if considered useful).

norayr avatar Apr 02 '22 12:04 norayr

solved:

# v4l2-ctl --list-devices
Dummy video device (0x0000) (platform:v4l2loopback-000):
	/dev/video2

Laptop Camera: Laptop Camera (usb-0000:00:14.0-7):
	/dev/video0
	/dev/video1
	/dev/media0

found out that dummy video device is /dev/video2

so, changed command to:

gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -s 1024x683 -threads 2 -f v4l2 /dev/video2

and it worked!

norayr avatar May 06 '22 20:05 norayr

if you see this: [video4linux2,v4l2 @ 0x55790ffc25e0] Unable to open V4L2 device '/dev/video4'

you need check which device your video4linux loopback driver is on, it might be another one like /dev/video3 or so. Use: v4l2-ctl --list-devices

to see which one is the v4l2loopback device.

msmeissn avatar May 09 '22 13:05 msmeissn

I have a similar issue with Canon Poweshot G7 Max Mark iii. I made sure my v4l2l is on and, I could able to capture video running this command gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -s 1024x683 -threads 2 -f v4l2 /dev/video2

My device is video2 which I found out via v4l2-ctl --list-devices .

Second time when I tried the same I get below error

*** Error ***
Canon EOS M Full-Press failed (0x2019: PTP Device Busy) ERROR: Could not capture image. ERROR: Could not capture. *** Error (-110: 'I/O in progress') ***

Also, I am able to capture movies at irregular instances. It doesn't work always if I reboot the camera. Let me know if I need to provide any other information.

bhvi150 avatar Jan 23 '23 10:01 bhvi150