Skip to content

Instantly share code, notes, and snippets.

@ryanlerch ryanlerch/
Last active Nov 1, 2017

What would you like to do?
## Run the script, select the area you want to screencast, then stop the script by closing the window.
## The video should output into ~/Videos/pants.webm
from gi.repository import Gtk, Gdk
import dbus
import signal
import subprocess
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Screencaster")
self.button = Gtk.Button(label="Finish Screencast")
self.button.connect("clicked", Gtk.main_quit)
bus = dbus.SessionBus()
screenshot_object = bus.get_object('org.gnome.Shell.Screenshot', '/org/gnome/Shell/Screenshot')
screenshot_interface = dbus.Interface(screenshot_object, 'org.gnome.Shell.Screenshot')
screencast_object = bus.get_object('org.gnome.Shell.Screencast', '/org/gnome/Shell/Screencast')
screencast_interface = dbus.Interface(screencast_object, 'org.gnome.Shell.Screencast')
win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
selectedarea = screenshot_interface.SelectArea()
#filename = screencast_interface.ScreencastArea(selectedarea[0], selectedarea[1], selectedarea[2], selectedarea[3], "pants.webm", {})
## this is supposed to pull in sound from the mic. Not sure if it works or not. havent tested it yet.
filename = screencast_interface.ScreencastArea(selectedarea[0], selectedarea[1], selectedarea[2], selectedarea[3], "pants.webm", {'pipeline': 'queue ! videorate ! vp8enc min_quantizer=13 max_quantizer=13 cpu-used=5 deadline=1000000 threads=%T ! queue ! mux. pulsesrc ! queue ! audioconvert ! vorbisenc ! queue ! mux. webmmux name=mux'})
print filename
win.move(selectedarea[0]+selectedarea[2], selectedarea[1]+selectedarea[3])
signal.signal(signal.SIGINT, signal.SIG_DFL)
Gtk.main()["xdg-open", filename[1]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.