Question / Help OBS to v4l2loopback

BeTmAsTeR

New Member
I'm trying to redirect the output of OBS Studio to Skype, Hangout and all the softwares that get video stream from V4L devices.

I found this project that looks like the ideal solution for my problem, a kernel module that allow me to create a V4L loopback device which can be subsequently fed with the video stream i want to show.

The examples for using the module are pretty simple, in fact by following them everything works fine, however with OBS as producer nothing works :(.

I'm using this settings, outputting a rawvideo (like the examples) to the V4L device i created (/dev/video1)

VCu.png



Every time i click "Start Recording" i get this
Code:
warning: Error opening '/dev/video1': Invalid Argument
warning: ffmpeg_data_init failed
info: ==== Recording Stop ================================================

I'm thinking about a different approach, by passing the stream to a middleman, with a named pipe or something else
OBS -> [ffmpeg?/gstreamer?] -> V4L2loopback -> consumer

Any ideas?

Thanks in advance
 
Last edited:

BeTmAsTeR

New Member
i have write permission on any /dev/video* device, with ffmpeg for example i can write without any problems
 

Refutationalist

New Member
One way I was able to get it to work was to save to a url in the settings, and then run ffmpeg externally to pump it into the loopback device.

For example, I set it to send to udp://localhost:55555 with (just picking one) an mpeg2 transport stream.

The in a terminal, I run:

Code:
ffmpeg -re -i udp://localhost:55555 -f v4l2 /dev/videoX

And it appears to work. The problem is we're adding extra layers of encoding and decoding. If we could get obs-studio to output into the v4l2 format natively and pump the pixels into /dev/videoX, we're good to go. I suspect it's possible given the use of ffmpeg's libraries, but that's not something I'd know for sure.

Unfortunately, the only time I need this is when I'm not hosting the video myself, and tomorrow is the first and last time I'm likely to do it, so I won't be poking around much after this. But that's my findings so far. If I learn anything else, I'll follow up.
 

smartptr

New Member
Hello,

A possibility to stream to the v4l2loopback looks like a must for this kind of software on linux.

Here is my log with audio failure:
Code:
22:56:04.955: Processor: 8 logical cores
22:56:04.955: Processor: Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz
22:56:04.955: Physical Memory: 7663MB Total
22:56:04.955: Kernel Version: Linux 4.10.0-24-generic
22:56:04.955: Distribution: "Ubuntu" "17.04"
22:56:04.956: Portable mode: false
22:56:04.966: OBS 19.0.3 (linux)
22:56:04.966: ---------------------------------
22:56:04.966: ---------------------------------
22:56:04.966: audio settings reset:
22:56:04.966:     samples per sec: 44100
22:56:04.966:     speakers:        2
22:56:04.972: ---------------------------------
22:56:04.972: Initializing OpenGL...
22:56:04.989: OpenGL version: 4.5 (Core Profile) Mesa 17.1.2
22:56:05.035: ---------------------------------
22:56:05.035: video settings reset:
22:56:05.035:     base resolution:   1920x1080
22:56:05.035:     output resolution: 1280x720
22:56:05.035:     downscale filter:  Bicubic
22:56:05.035:     fps:               30/1
22:56:05.035:     format:            NV12
22:56:05.035: ---------------------------------
22:56:05.040: No blackmagic support
22:56:05.061: os_dlopen(libnvidia-encode.so.1->libnvidia-encode.so.1): libnvidia-encode.so.1: cannot open shared object file: No such file or directory
22:56:05.061:
22:56:05.066: VLC found, VLC video source enabled
22:56:05.066: ---------------------------------
22:56:05.066:   Loaded Modules:
22:56:05.066:     vlc-video.so
22:56:05.066:     text-freetype2.so
22:56:05.066:     rtmp-services.so
22:56:05.066:     obs-x264.so
22:56:05.066:     obs-transitions.so
22:56:05.066:     obs-outputs.so
22:56:05.066:     obs-libfdk.so
22:56:05.066:     obs-filters.so
22:56:05.066:     obs-ffmpeg.so
22:56:05.066:     linux-v4l2.so
22:56:05.066:     linux-pulseaudio.so
22:56:05.066:     linux-jack.so
22:56:05.066:     linux-decklink.so
22:56:05.066:     linux-capture.so
22:56:05.066:     linux-alsa.so
22:56:05.066:     image-source.so
22:56:05.066:     frontend-tools.so
22:56:05.066: ==== Startup complete ===============================================
22:56:05.066: All scene data cleared
22:56:05.066: ------------------------------------------------
22:56:05.077: Switched to scene 'Scene'
22:56:05.077: ------------------------------------------------
22:56:05.077: Loaded scenes:
22:56:05.077: - scene 'Scene':
22:56:05.077:     - source: 'Text (FreeType 2)' (text_ft2_source)
22:56:05.077: ------------------------------------------------
22:56:16.102: ==== Recording Start ===============================================
22:56:16.105: receive_audio: Error writing packet: Invalid argument
22:56:16.105: Output 'adv_ffmpeg_output': stopping
22:56:16.105: Output 'adv_ffmpeg_output': Total encoded frames: 4294966969
22:56:16.105: Output 'adv_ffmpeg_output': Total drawn frames: 1
22:56:16.105: ==== Recording Stop ================================================

Hope this helps. I can patch and test on my side if needed. With the version from github I get exactly the same issue: receive_audio warning and then stopping. I should probably file a bug eventually with some more debug information.

Hugs.
 
Last edited:

smartptr

New Member
Interesting,
if I create a test sink:
v4l2loopback-ctl set-caps "video/x-raw,width=640,height=480" /dev/video1
I can start recording to my loopback device, but the picture is corrupted (mix of the gstreamer test and my scene).
 

SandUhrGucker

New Member
Old Thread, current Problem. Sorry.

Maybe one of You could spend me a hint what else I could try:
I installed newest OBS (21.0.1), and v4l2-loopback, both without any errors.
I created a new loopback (/dev/video3)
I chmoded the device to 777
I did a realtime ffmpeg recoder as mentioned: ffmpeg -re -i udp://localhost:55555 0:v -f v4l2 /dev/video3
I pointed OBS to stream to local adress as mentioned: udp://127.0.0.1:55555

But OBS alway shows an error like "Cannot connect to Streaming Server"
Here a Part of the log:

info: ---------------------------------
info: [x264 encoder: 'streaming_h264'] settings:
rate_control: CBR
bitrate: 2500
buffer size: 2500
crf: 0
fps_num: 30
fps_den: 1
width: 1680
height: 1050
keyint: 250

info: [rtmp stream: 'adv_stream'] Connecting to RTMP URL udp://127.0.0.1:55555...
info: Unknown protocol!

info: No application or playpath in URL!
info: 127.0.0.1:55555 is offline. Try a different server (ECONNREFUSED).
info: [rtmp stream: 'adv_stream'] Connection to udp://127.0.0.1:55555 failed: -2
info: ==== Streaming Stop ================================================

Please help!
Regards
Rene'
 

smartptr

New Member
Salut René,

Here is my command:
Bash:
ffmpeg -re -listen 1 -i rtmp://localhost:5050/ \
  -c:v rawvideo -an -pix_fmt yuyv422 \
  -f v4l2 /dev/video1

OBS streaming configuration:
1526124156558.png


OBS output configuration:
1526123937803.png


This adds an unfortunate 4 seconds delay on my computer though. I'm looking for how to reduce the delay.
 

dreamer

New Member
So yesterday I was playing with v4l2loopback again (since ages ago). Because everybody is using videochat services and we need to make things a bit more interesting ;)

The only setup that works fairly reliably for me right now is if I run an nginx-rtmp instance, stream to that from OBS and then grab this stream with ffmpeg like:

ffmpeg -re -i rtmp://localhost/streaminput/tester -c:v rawvideo -preset ultrafast -tune zerolatency -an -pix_fmt yuv420p -f v4l2 /dev/video2

This still adds the mentioned ~4 seconds delay.

In terms of functionality it would of course be great of OBS can stream directly to a v4l2loopback device.
A custom output type with ffmpeg that adds this type would be ideal I think.

I haven't dived into OBS code yet (have compiled it from scratch before), but I'll have a look at how difficult it will be to add this.
 

dreamer

New Member
Hey, interesting. I did not find this and I will have a look to see if this does things like we want :)
 

dreamer

New Member
After compiling both obs and the plugin from scratch and playing around a bit with settings it's working pretty well on 720p.
Thnx for the tip @Leadpumper :)
 

mikemacd

New Member
After compiling both obs and the plugin from scratch and playing around a bit with settings it's working pretty well on 720p.
Thnx for the tip @Leadpumper :)

Could you share settings? I've got obs running with the plugin, started the loopback:
modprobe v4l2loopback
but I'm struggling with the caps settings. What's the right combination of something like:
v4l2loopback-ctl set-caps "video/x-raw,format=(fourcc)YUV2,width=640,height=480" /dev/video2
and obs output settings?
 

dreamer

New Member
Hey @mikemacd
I basically ended up compiling obs, v4l2loopback and obs-v4l2sink from scratch.

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

And in obs video settings I use 1280x720, 1280x720, bicubic, 30fps
 

mikemacd

New Member
thanks @dreamer, that helped - I can view my loopback video in vlc now with OBS effects using
vlc v4l2:///dev/video10
Although I get errors when I try to use Cheese/guvcview etc. or Chime in a browser. I'll try building everything from source :)
 

mikemacd

New Member
Yep, got it working. I had to remove my browser permissions for sharing video on Chime and then re-allow, now sharing my OBS Cam. Thanks for the help :)
 
Top