ffmpegpuppeteerxvfb

Getting ffmpeg to capture the full screen of xfvb-run screen running puppeteer script, and send it over rtmp


My problem

I can't get ffmpeg or xvfb-run to stream the full screen to ffplay/videolan, it only captures a part of the screen.

Update 2

I answered the question myself in a follow up answer, hopefully it can be useful for someone else with the same problem.

Update 1

So the problem is definitely with xvfb-run, since the two following commands, still give a webm file, that only show parts of the screen

ffmpeg -f x11grab -i :99 -g 50 -b:v 4000k -maxrate 4000k -bufsize 8000k -f webm -s 384x216 "blank.webm"

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

What I've tried

But still no luck. That's why I'm reaching out to the stackoverflow community.

xvfb-run command

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

ffmpeg command to capture xvfb-run virtual screen

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

And finally to show the rtmp stream

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

The puppeteer script (index.js) which xfvb-runs



import puppeteer from 'puppeteer';
let initPuppeteer = async () => {
  const launchArgs = [
    //'--window-size=1280,1024',
    '--disable-web-security',
    '--disable-features=IsolateOrigins',
    '--disable-site-isolation-trials',
    '--app',
    '--kiosk',
  ]
  await puppeteer.launch({headless: false, ignoreDefaultArgs: ["--enable-automation"], args: launchArgs});
  const page = await this.browser.newPage();
  const device = puppeteer.devices['Nexus 10'];
  await page.emulate(device);
  await page.goto("https://google.com");
}
initPuppeteer()

Solution

  • So I kept debugging and trying to solve it. And the problem was with ffmpeg and in which order I added flags.

    Note to self: When using ffmpeg order of flags is very important.

    Solution

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

    Where I added -video_size 640x1208 right after ffmpeg command.

    I found the video_size flag in this stackoverflow answer - https://stackoverflow.com/a/32748769/337587