Skip to content

Instantly share code, notes, and snippets.

@hdante
Last active April 18, 2020 13:31
Show Gist options
  • Save hdante/6036f7fdc90cd59f92a77cbc610bcbc0 to your computer and use it in GitHub Desktop.
Save hdante/6036f7fdc90cd59f92a77cbc610bcbc0 to your computer and use it in GitHub Desktop.
Lossless screencast for Gnome Shell (supports wayland and X)
#!/usr/bin/env python3
from dbus import SessionBus, Interface
from os import getcwd, path
from sys import argv
BUS_NAME = 'org.gnome.Shell.Screencast'
PATH_NAME = '/org/gnome/Shell/Screencast'
INTERFACE_NAME = BUS_NAME
PIPELINE='x264enc pass=qual quantizer=0 speed-preset=ultrafast ! queue ! matroskamux'
if path.isabs(argv[1]):
name = argv[1]
else:
name = path.join(getcwd(), argv[1])
bus = SessionBus()
screen_cast = bus.get_object(BUS_NAME, PATH_NAME)
screen_cast = Interface(screen_cast, INTERFACE_NAME)
ret, name = screen_cast.Screencast(name, {'pipeline': PIPELINE})
if not ret:
print('Error starting screencast.')
raise SystemExit(1)
try:
i = input()
except (EOFError, KeyboardInterrupt):
pass
finally:
screen_cast.StopScreencast()
@frvannes16
Copy link

Great script! What file format does it output to?

@hdante
Copy link
Author

hdante commented Apr 18, 2020

Great script! What file format does it output to?

It's configured for H.264 Matroska (.mkv) files. It can be configured with the PIPELINE variable, in line 9.

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