CatxFish / obs-v4l2sink

obs studio output plugin for Video4Linux2 device
GNU General Public License v2.0
931 stars 99 forks source link

alternative approach using rtmp/avconv #84

Open e-c-d opened 3 years ago

e-c-d commented 3 years ago

I tried using the plugin but the browser/guvcview strangely refused to read from the video device (on Debian Buster). Oh well. I eventually succeeded using an alternative approach using a local rtmp server and using avconv to send video data from rtmp into the v4l2loopback device. I'm sharing my approach for anyone who might find it useful.

Idea

OBS sends rtmp to nginx. nginx forwards rtmp to avconv. avconv decodes video and sends to v4l2loopback. v4l2loopback camera is used normally by browser/jitsi/whatever.

Prerequisites

Prerequisites on Debian Buster:

sudo apt install nginx libnginx-mod-rtmp v4l2loopback-dkms obs-studio libav-tools

Steps

Setup a local rtmp server by adding at the end of your /etc/nginx/nginx.conf:

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
            record off;
        }
    }
}

Start OBS and tell it to stream to the custom address rtmp://localhost/live.

Create a virtual camera (you'll need the v4l2loopback kernel module installed):

sudo modprobe v4l2loopback devices=1 video_nr=10 card_label="OBS Cam" exclusive_caps=1

Use avconv/ffmpeg to send the rtmp from nginx to the virtual camera.

avconv -i "rtmp://localhost/live" -vcodec rawvideo -vf hflip -y -f v4l2 /dev/video10

You can remove the -vf hflip if your teleconference app doesn't flip the video.

Now you can open your camera-using app and tell it to use /dev/video10 aka "OBS Cam".

Protip: you can lower the latency by going in the OBS settings, under "Output", setting "Output Mode" to "Advanced", then setting "Tune" to "zerolatency".

(Latest guide here)