Streaming OPENRNDR live coding on Linux

I just customized openrndr-template to use v4l2loopback in order to stream OPENRNDR output. Might be useful for creating on the fly camera filters in the time of social distancing:

https://github.com/morisil/openrndr-camera-filter

1 Like

Ah interesting, I just have v4l2loopback setup here, will try to find some time to get this going.

I changed default pixel format to rgb24 from yuv420p, and ffmpeg CPU usage dropped from 94% to 50% for FullHD resolution (one core). After this change I was still able to pick the camera in Jitsi opened in Chrome. I see that availability of the camera to certain application depends a lot on the resolution. If it’s too big Skype will not pick it for example. I guess also the output frame rate specification should be fixed in my code. Still not sure how. I guess just the extra -r parameter for the output video.I see that in the VideoWriter it’s only allowed to specify integer value frame rate for the input video stream and this one right now gets inherited for the output and defaults to 25 fps. But I was thinking that maybe this value should be actually floating point in general if someone’s screen has weird refresh rate like 59,93Hz? But it seems that it makes any timing quite difficult. Still my screen is currently 60Hz, so I guess input video frame rate should be set to 60 fps, and output to something more reasonable for streaming, maybe 25, maybe 20.

I believe @abe worked on something similar using akvcam, if I am not mistaken he was able to write to /dev/videoN directly and bypassing FFMPEG altogether.

Yes, I talked with him about it, but I was not able to get akvcam to work on my computer. Now it seems that it’s because I enabled secure boot, which means I have to sign newly compiled kernel modules :slight_smile:

I was finally able to use akvcam and I adapted @abe 's code as an Extension and pushed it. I used NIO channels directly instead of allocating extra byte array. Still I am quite disappointed with the performance and stability. Going FullHD is crashing my computer immediately. Trying with just 640x480 resolution sooner or later blocks something, causing a crash after a while and I have to do the hard reset, which actually I realized is almost never happening to me on linux, maybe once in 6 months. :frowning: I had to do this as well:

$ echo "1" >/sys/devices/virtual/video4linux/video7/controls/vflip

Even with such a limited resolution akvcam seems to be heavily dropping frames while v4l2loopback goes quite well with FullHD 60 fps and 50% of CPU on 1 core. Maybe it works better with other drivers. I’m on intel here.