How to use ffmpeg to stream the entire xvfb-run screen with puppeteer to rtmp?

Help needed with screen capture

I’m trying to stream my xvfb-run screen with puppeteer to rtmp using ffmpeg. But I’m only getting part of the screen. I’ve tried different ffmpeg commands and xvfb-run settings, but no luck.

Here’s what I’ve done:

  • Changed ffmpeg settings (added filters, changed formats)
  • Tried other apps instead of puppeteer
  • Recorded to file instead of streaming

My setup:

xvfb-run -n 99 -a --server-args='-screen 0 1024x8000x24 -ac -nolisten tcp -dpi 96 +extension RANDR' 'node index.js'

ffmpeg -f x11grab -i :99 -f pulse -i default -c:v libx264 -c:a aac -g 50 -b:v 4000k -maxrate 4000k -bufsize 8000k -f flv -listen 1 rtmp://localhost:4444/stream

ffplay -fflags -nobuffer -flags low_delay -probesize 32 -flags low_delay -analyzeduration 0 -i rtmp://localhost:4444/stream

The puppeteer script opens Google in a Nexus 10 emulation. Any ideas why I’m not getting the full screen?

I’ve dealt with similar streaming challenges using xvfb and ffmpeg. One thing that often gets overlooked is the importance of synchronization between the virtual framebuffer and ffmpeg’s capture rate. Try adding the ‘-framerate’ option to your ffmpeg command to match the refresh rate of your xvfb screen:

ffmpeg -f x11grab -framerate 30 -video_size 1024x8000 -i :99 -f pulse -i default -c:v libx264 -preset ultrafast -c:a aac -f flv rtmp://localhost:4444/stream

Also, ensure your puppeteer script isn’t causing any unexpected scrolling or resizing that might affect the capture. You might want to add a short delay after the page load before starting the ffmpeg capture to allow everything to stabilize.

If you’re still having issues, consider using a tool like ‘x11vnc’ to mirror your xvfb screen, then capture from that. It can sometimes provide a more stable source for ffmpeg to work with.

I’ve encountered similar issues when streaming xvfb screens. Have you considered using a virtual framebuffer like Xvfb with a fixed resolution that matches your streaming dimensions? This approach often resolves partial screen capture problems.

For your ffmpeg command, try specifying the exact dimensions you want to capture:

ffmpeg -f x11grab -video_size 1024x8000 -i :99 -f pulse -i default -c:v libx264 -preset ultrafast -c:a aac -f flv rtmp://localhost:4444/stream

This explicitly tells ffmpeg to grab the full 1024x8000 screen. Also, the ‘ultrafast’ preset might help with real-time streaming performance.

If you’re still having issues, you could try using a tool like pyvirtualdisplay in conjunction with selenium instead of puppeteer. This combination has worked well for me in similar setups.

hey mike, have u tried adjusting the capture region in ffmpeg? sometimes it helps to explicitly set the offset like this:

ffmpeg -f x11grab -video_size 1024x8000 -i :99+0,0 …

the +0,0 tells it to start at the top left. might fix ur issue if its only grabbing part of the screen