Issues using Sony digital camera RX100M4 as a webcam on Ubuntu 20.04

Followed instructions to install the v4l2loopback kernel module and gphoto2.
I can control the camera and take pictures using Entangle, and also see the live preview video within Entangle, but I cannot stream the video using ffmpeg to use it in other applications.

$ gphoto2 --abilities
Abilities for camera : Sony DSC-RX100M4
Serial port support : no
USB support : yes
Capture choices : : Image : Preview : Trigger Capture
Configuration support : yes
Delete selected files on camera : yes
Delete all files on camera : no
File preview (thumbnail) support : yes
File upload support : yes

Killing all existing instances

$ sudo killall gvfs-gphoto2-volume-monitor
gvfs-gphoto2-volume-monitor: no process found

There are 3 /dev/video*

$ ll /dev/video*
crw-rw----+ 1 root video 81, 0 Nov 7 08:46 /dev/video0
crw-rw----+ 1 root video 81, 1 Nov 7 08:46 /dev/video1
crw-rw----+ 1 root video 81, 2 Nov 7 09:35 /dev/video2

Running the command to pipe the video to the /dev/video* doesn't work on any of them:

$ gphoto2 --stdout --capture-movie | gst-launch-1.0 fdsrc ! decodebin3 name=dec ! queue ! videoconvert ! v4l2sink device=/dev/video2
Capturing preview frames as movie to 'stdout'. Press Ctrl-C to abort.
Setting pipeline to PAUSED ...
ERROR: Pipeline doesn't want to pause.
ERROR: from element /GstPipeline:pipeline0/GstV4l2Sink:v4l2sink0: Device '/dev/video2' is not a output device.
Additional debug info:
v4l2_calls.c(636): gst_v4l2_open (): /GstPipeline:pipeline0/GstV4l2Sink:v4l2sink0:
Capabilities: 0x85208000
Setting pipeline to NULL ...
Freeing pipeline ...
*** Error ***
Sorry, your Sony camera does not seem to return a JPEG image in LiveView mode
ERROR: Movie capture error... Exiting.
Movie capture finished (0 frames)

I tried different ways of toggling between AUTO and MOVIE modes on the camera as explained in the official instructions, without luck...

Any idea what am I missing?

Does Sorry, your Sony camera does not seem to return a JPEG image in LiveView mode mean it doesn't work with my camera? (Sony DSC-RX100M4)

Another command (ffmpeg):

$ gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video1
Capturing preview frames as movie to 'stdout'. Press Ctrl-C to abort.
ffmpeg version n4.1.4 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 7 (Ubuntu 7.4.0-1ubuntu1~18.04.1) configuration: --prefix= --prefix=/usr --disable-debug --disable-doc --disable-static --enable-avisynth --enable-cuda --enable-cuvid --enable-libdrm --enable-ffplay --enable-gnutls --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopus --enable-libpulse --enable-sdl2 --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-nonfree --enable-nvenc --enable-omx --enable-openal --enable-opencl --enable-runtime-cpudetect --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-xlib libavutil 56. 22.100 / 56. 22.100 libavcodec 58. 35.100 / 58. 35.100 libavformat 58. 20.100 / 58. 20.100 libavdevice 58. 5.100 / 58. 5.100 libavfilter 7. 40.101 / 7. 40.101 libswscale 5. 3.100 / 5. 3.100 libswresample 3. 3.100 / 3. 3.100 libpostproc 55. 3.100 / 55. 3.100
[mjpeg @ 0x55bb2836b0c0] 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, yuvj422p(pc, bt470bg/unknown/unknown), 1024x680, 25 tbr, 1200k tbn, 25 tbc
Stream mapping: Stream #0:0 -> #0:0 (mjpeg (native) -> rawvideo (native))
[swscaler @ 0x55bb283bef00] deprecated pixel format used, make sure you did set range correctly
[video4linux2,v4l2 @ 0x55bb28370dc0] Unable to open V4L2 device '/dev/video1'
Could not write header for output file #0 (incorrect codec parameters ?): Operation not permitted
Error initializing output stream 0:0 --
Conversion failed!

1 Answer

  1. From this thread:

The libgphoto2 2.5.26 we have some fixes also for sony preview capture.

So, either use modern distro with libgphoto2>=2.5.26 or upgrade using the following script:

Check libgphoto2 version with

gphoto2 --version
  1. After that, switch camera USB mode to PC Control (PC Remote) mode. Alter power save settings if needed (so that it doesn't turn off after timeout).

  2. Check photo capture

gphoto2 --capture-image-and-download
  1. If that works proceed to the movie capture test
gphoto2 --capture-movie=10s
  1. If movie capture succeeds, create a virtual V4L2 camera, receive a stream from real camera and write it with ffmpeg to /dev/video2. Then open the V4L2 camera stream with VLC to test. (v4l2-ctl is to list V4L2 devices, rmmod to optionally unload v4l2loopback afterwards).
sudo apt install v4l2loopback-utils
sudo modprobe v4l2loopback devices=1 exclusive_caps=1 max_buffers=2 video_nr=2 card_label="fake-cam"
v4l2-ctl --list-devices
gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt rgb32 -threads 0 -f v4l2 /dev/video2
vlc v4l2:///dev/video2
sudo rmmod v4l2loopback
3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like