Software zoom for DJI action cams used as webcam

Since return to office after COVID19, I also had to bring my company-sponsored Logitech webcam back with me.
In order to have decent video on my homeoffice days, I first experimented with my Sony Alpha but in the end I bought a Razer Kiyo. It has decent video/audio quality and an integrated ringlight - that really did nothing for me ^^.

Exactly two weeks after I threw away the bill and the packaging during spring cleaning in March, the Kiyo stopped working. When I plugged it in, the LED ringlight started flickering and Linux reported a USB disconnect.

I opened it recently just to find some grease smeared all over the place (probably not a dialectric one). Looking at the highly integrated cicuit board and given my amateur soldering/electronics skills, I gave up my hope I could simply disconnect the ringlight that I suspect to be the problem.

When the Razer failed, I started to use my DJI Osmo Action 4 as a webcam. The quality is great, but the field of view is too wide for my desk setup. I have been looking for a way to zoom in - sadly the camera does not offer any camera controls whatsoever beyond the bare minimum:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ cameractrls -l -d /dev/video2

Advanced / Cameractrlsd
systemd_cameractrlsd = False ( default: None min: None max: None )
Capture / Capture
pixelformat = MJPG ( values: MJPG, H264 )
resolution = 1920x1080 ( values: 1920x1080, 1280x720 )
fps = 30 ( values: 30 )
Capture / Info
card = OsmoAction4: OsmoAction4
driver = uvcvideo
path = /dev/video2
real_path = /dev/video2
Settings / Save
preset ( buttons: load_1, load_2, load_3, load_4, save_1, save_2, save_3, save_4 )

Also it is not possible to use the device menu on the camera to zoom in, as it is possible when taking regular videos.

Thinking about it I remembered that I already successfully used v4l2-loopback to create a virtual webcam device and cast my screen to it. So I thought, why not use the camera as a source for v4l2-loopback and then use ffmpeg to crop the image and send it to the virtual webcam device.

1
$ sudo modprobe v4l2loopback video_nr=10 card_label="DJI cropped" exclusive_caps=1

This creates a new virtual webcam device /dev/video10 that can be used in any application that supports webcams.

Then using ffmpeg I can crop the image and send it to the virtual webcam device:

1
$ ffmpeg -f pulse -ac 2 -i default -f v4l2 -i /dev/video2 -vf "format=yuv420p,crop=iw/2:ih/2:(iw-iw/2)/2:(ih-ih/2)/2" -f v4l2 /dev/video10

This will crop the image by half in the center resulting in something like this:

Actually, for this image I cropped the image by 2/3.

Naturally this comes with a loss of quality, because it reduces your resolution by the same factor, but still better than nothing. d^.^b