Camera V4L2Loopback – How to Create a V4L2 Device That Is a Cropped Version of a Webcam

camerav4lv4l2loopback

I have a Logitech Webcam C930e on /dev/video0. I can use this for doing video conferences (e.g. jitsi). However, the video from this webcam is too high and too broad. I would like to have a "cropped" version of /dev/video0 that does not show the seaside picture on the wall.

First, I tried to set v4l2 options to achieve this, but did not succeed:

$ v4l2-ctl -d /dev/video0 --get-cropcap
Crop Capability Video Capture:
    Bounds      : Left 0, Top 0, Width 640, Height 360
    Default     : Left 0, Top 0, Width 640, Height 360
    Pixel Aspect: 1/1

$ v4l2-ctl -d /dev/video0 --get-selection target=crop_bounds
Selection: crop_bounds, Left 0, Top 0, Width 640, Height 360, Flags:

$ v4l2-ctl -d /dev/video0 --set-selection target=crop_bounds,flags=crop,top=10,left=10,width=100,height=100
VIDIOC_S_SELECTION: failed: Inappropriate ioctl for device

After that, I followed another idea: I tried to use v4l2loopback to create another device /dev/video2. After that I would have tried to use ffmpeg to connect /dev/video0 to /dev/video2 (see https://github.com/umlaeute/v4l2loopback/wiki and https://video.stackexchange.com/questions/4563/how-can-i-crop-a-video-with-ffmpeg).

So now, I am out of ideas. Can someone give advice?

Best Answer

Lines below create a loopback video device /dev/video5. After that ffmpeg is used to connect /dev/video0 to /dev/video5, but crop and hflip the stream on its way.

sudo apt-get install v4l2loopback-dkms 
sudo modprobe v4l2loopback video_nr=5
ffmpeg -i /dev/video0 -f v4l2 -pix_fmt yuv420p -filter:v "hflip,crop=400:400:0:0" /dev/video5
Related Question