x11 – what’s the fastest way of writing data to ffmpeg for video streams?

I’m live streaming my x11 screen to a v4l2 webcam device (/dev/video0) with FFmpeg through stdin (ffmpeg -re -probesize 32 -analyzeduration 0 -i pipe:0 -s 1280x720 -vf scale=1280:720 -preset veryfast -tune zero_latency -vf format=yuv420p -f v4l2 /dev/video0). I wrote a simple Rust program to grab the screenshot with rxscreen (rust bindings to libX11) and write it to ffmpeg’s stdin. I’m sending >30 frames per seconds (average frame size is 200000bytes (200kb)).

Unfortunately, there’s a 5-9 seconds delay when streaming through this method, but if I use ffmpeg’s built-in x11 grab (ffmpeg -framerate 30 -video_size 500x500 -draw_mouse 0 -f x11grab -i :1.0+0,0 -s 1280x720 -vf scale=1280:720 -preset veryfast -tune zero_latency -vf format=yuv420p -f v4l2 /dev/video0), there’s a very small delay (1-2ms). I’ve tried everything I can to decrease the video delay with my original method but I’m getting the same result. This delay must be because of my data’s transport method (writing large amounts of data to stdin) while ffmpeg built-in screen grab implementation can just reads and write data directly from memory.

What’s the fastest way I can write data to FFmpeg from an external program? Stdin vs. UDP vs. Named Pipes vs. Memory Mapped Files

Preferably a method that FFmpeg supports out of the box.

Read more here: Source link