Using Sony Alpha6400 as webcam from Linux
Sunday 8 December 2024

Thanks to Christian for the guide, here is the gist:

Using USB cable

Prepare the camera

  • Ctrl. with smartphone -> off
  • PC remote control -> on
  • USB setting -> PC remote control

Prepare the machine

  1. install packages
1sudo apt install ffmpeg gphoto2 v4l2loopback-dkms v4l2loopback-utils
  1. Load the kernel module
1sudo modprobe v4l2loopback exclusive_caps=1 max_buffers=2
  1. Check the camera is detected
1➜ gphoto2 --auto-detect
2Model                          Port                                            
3----------------------------------------------------------
4Sony ILCE-6400 (PC Control)    usb:001,017
  1. Take one still picture just to be sure it works
1gphoto2 --capture-image-and-download
  1. Redirect the video to virtual camera
1# Without hardware acceleration
2gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video2
3# With hardware acceleration (I have a NVIDIA RTX 2060)
4gphoto2 --stdout --capture-movie | ffmpeg -hwaccel nvdec -c:v mjpeg_cuvid -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video2

Tips

  • I tried connecting the device to USB port in the front of the PC and the lag was high. connecting it to one of the back ports (USB 3.1 Gen2) was faster. still laggy but less.
  • Also I have 2 RTX2060, 1 of them is connected to the monitor. I used the other for ffmpeg hardware acceleration by adding -hwaccel_device 1 for ffmpeg commang. (I got an overview of the cards usage with nvidia-smi command). This reduces the lag

Using capture card

This is what gave me the least lag. I recommend it over the USB cable

Hardware

  • I’m using Mirabox (the older version of this)
  • Micro-HDMI cable (Micro not Mini, I made a mistake when I got this cable and now I have a mini HDMI cable I have no use of)
  • HDMI dummy

Prepating the camera

  • turn on Clean HDMI output

Software

  • v4l2loopback seems to be needed. however I didn’t install anything after the setup the first method.

Setup

  1. Connect the camera with micro-HDMI to the capture card
  2. Connect the dummy to the capture card
  3. Connect the capture card to the PC using your fastest possible USB port.
  4. Connect the camera to the USB and to a power brick. as HDMI won’t give it power.
  5. Connect a microphone to the camera if you need to or use stand-alone microphone connected to your PC.
  6. Turn on the camera.
  7. Now you should see a new web cam connected to your PC with your capture card name on it.
 1sudo v4l2-ctl --device=/dev/video0 --all
 2Driver Info:
 3	Driver name      : uvcvideo
 4	Card type        : MiraBox Video Capture : MiraBox
 5	Bus info         : usb-0000:02:00.0-7.1.3.4
 6	Driver version   : 6.12.1
 7	Capabilities     : 0x84a00001
 8		Video Capture
 9		Metadata Capture
10		Streaming
11		Extended Pix Format
12		Device Capabilities
13	Device Caps      : 0x04200001
14		Video Capture
15		Streaming
16		Extended Pix Format
17Media Driver Info:
18	Driver name      : uvcvideo
19	Model            : MiraBox Video Capture : MiraBox
20	Serial           : 20000130041415
21	Bus info         : usb-0000:02:00.0-7.1.3.4
22	Media version    : 6.12.1
23	Hardware revision: 0x00000100 (256)
24	Driver version   : 6.12.1
25Interface Info:
26	ID               : 0x03000002
27	Type             : V4L Video
28Entity Info:
29	ID               : 0x00000001 (1)
30	Name             : MiraBox Video Capture : MiraBox
31	Function         : V4L2 I/O
32	Flags            : default
33	Pad 0x01000007   : 0: Sink
34	 Link 0x02000010: from remote pad 0x100000a of entity 'Extension 4' (Video Pixel Formatter): Data, Enabled, Immutable
35Priority: 2
36Video input : 0 (Camera 1: ok)
37Format Video Capture:
38	Width/Height      : 1920/1080
39	Pixel Format      : 'MJPG' (Motion-JPEG)
40	Field             : None
41	Bytes per Line    : 0
42	Size Image        : 4147200
43	Colorspace        : sRGB
44	Transfer Function : Rec. 709
45	YCbCr/HSV Encoding: ITU-R 601
46	Quantization      : Default (maps to Full Range)
47	Flags             : 
48Crop Capability Video Capture:
49	Bounds      : Left 0, Top 0, Width 1920, Height 1080
50	Default     : Left 0, Top 0, Width 1920, Height 1080
51	Pixel Aspect: 1/1
52Selection Video Capture: crop_default, Left 0, Top 0, Width 1920, Height 1080, Flags: 
53Selection Video Capture: crop_bounds, Left 0, Top 0, Width 1920, Height 1080, Flags: 
54Streaming Parameters Video Capture:
55	Capabilities     : timeperframe
56	Frames per second: 60.000 (60/1)
57	Read buffers     : 0