Skip to content

Instantly share code, notes, and snippets.

@dllud
Created December 9, 2019 00:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dllud/21771b0160da76ec6e387b054151f4c9 to your computer and use it in GitHub Desktop.
Save dllud/21771b0160da76ec6e387b054151f4c9 to your computer and use it in GitHub Desktop.
Live screencast stream on GNU/Linux through CLI

Live screencast stream on GNU/Linux through CLI

Requirements

Software encoding

ffmpeg -f x11grab -s 1920x1080 -i :0.0 -r 5 -g 10 -vcodec vp9 -f matroska pipe:1 | ./server

  • -f x11grab: Input format set to grab the X11 display.
  • -s 1920x1080: Frame size equal to the X11 dispay resolution.
  • -i :0.0: display.screen numbers of the X11 server that should be grabbed.
  • -r 5: Frame rate, in this case 5 fps.
  • -g 10: Set Group Of Pictures to 10, meaning that there will be a new key-frame (Intra-coded frame) every 10/5=2s.
  • -vcoded vp9: Bitstream format set to VP9. AV1 will be a sensible option in the near future.
  • -f matroska: Output container format set to Matroska as required by mkvserver_mk2.
  • pipe:1: Output to stdout.
  • ./server: mkvserver_mk2.

Values were chosen to minimize lag.

Hardware enconding

Intel

Install libva-intel-driver (up to Coffee Lake) or intel-media-driver (from Broadwell onwards).

ffmpeg -vaapi_device /dev/dri/renderD128 -f x11grab -s 1920x1080 -i :0.0 -r 5 -g 10 -vf 'hwupload,scale_vaapi=format=nv12' -c:v h264_vaapi -qp 24 -f matroska pipe:1 | ./server

Based on FFmpeg wiki VAAPI Screen Capture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment