Skip to content

Instantly share code, notes, and snippets.

@ryanlerch

ryanlerch/screencaster.py

Last active Nov 1, 2017
Embed
What would you like to do?
screencaster.py
## 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)
self.add(self.button)
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)
win.set_keep_above(True)
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])
win.show_all()
signal.signal(signal.SIGINT, signal.SIG_DFL)
Gtk.main()
subprocess.call(["xdg-open", filename[1]])
print(filename)
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.