Skip to content

Instantly share code, notes, and snippets.

@TimothyGu
Last active March 24, 2020 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimothyGu/e5e1e4f69c41409a741352176adc6313 to your computer and use it in GitHub Desktop.
Save TimothyGu/e5e1e4f69c41409a741352176adc6313 to your computer and use it in GitHub Desktop.
#!/usr/env/bin python3
import signal
import sys
import dbus
from gi.repository import GLib, GObject
from dbus.mainloop.glib import DBusGMainLoop
import soundcard
DBusGMainLoop(set_as_default=True)
loop = GLib.MainLoop()
bus = dbus.SessionBus()
screencast = bus.get_object('org.gnome.Shell.Screencast', '/org/gnome/Shell/Screencast')
screencast_iface = dbus.Interface(screencast, dbus_interface='org.gnome.Shell.Screencast')
default_speaker = soundcard.default_speaker()
pulse_audio_sink = default_speaker.id + '.monitor'
pipeline = (f'vp8enc min_quantizer=10 max_quantizer=50 cpu-used=5 deadline=1000000 threads=%T ! queue ! mux. '
f'pulsesrc device={pulse_audio_sink} ! audioconvert ! opusenc bitrate=128000 bitrate-type=vbr ! queue ! mux. '
f'webmmux name=mux')
print(screencast_iface.Screencast(
'/home/timothy-gu/Videos/test2.webm',
{
'framerate': 30,
'draw-cursor': True,
'pipeline': pipeline
}))
def signal_handler(sig, frame):
print(screencast_iface.StopScreencast())
sys.exit(1)
signal.signal(signal.SIGINT, signal_handler)
loop.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment