1

How to start gnome's built in screen recorder via command line?

I have gone through this post

the command I am using is

gdbus call --session --dest org.gnome.Shell.Screencast --object-path /org/gnome/Shell/Screencast --method org.gnome.Shell.Screencast.Screencast "test_ %d_ %t.webm" "{}"

So it is happening as if screenshot was taken. I mean Screencast is not starting rather it is generating the file with 1sec in this format "test_ %d_ %t.webm"

How can I start recording and stop it with Ctrl+C in the terminal?

PRATAP
  • 127
  • 3
  • 17
  • This question is better suited for __AskUbuntu__. Consider moving it there. See similar question: [start gnome screen recorder command line](https://askubuntu.com/questions/1190696/start-gnome-screen-recorder-command-line) – hc_dev Mar 04 '21 at 17:57

1 Answers1

3

I've been looking for this answer for years. Finally stumbled upon following shell-script by Tor Hedin Brønner (hedning)

Gist: Start gnome shell screen cast from command line

#!/usr/bin/env nix-shell
#! nix-shell -i python3 -p python3.pkgs.dbus-python

import dbus
import time
bus = dbus.SessionBus()
obj = bus.get_object("org.gnome.Shell", "/org/gnome/Shell/Screencast")

obj.Screencast("Auto %d %t.webm", [],
               dbus_interface="org.gnome.Shell.Screencast")
time.sleep(999999)

️ It uses the nix-shell and dbus-python (Python's D-Bus binding) to communicate with GNOME-shell over the D-Bus protocol.

✔️ Tested it and it works a treat.

hc_dev
  • 8,389
  • 1
  • 26
  • 38
vtwaldo21
  • 66
  • 4
  • Great answer. How can we replace the [nix-shell](https://nixos.org/guides/nix-pills/developing-with-nix-shell.html) by any other common shell? – hc_dev Mar 04 '21 at 06:34
  • Nix shell is anything after `-i` as shell (or by default bash), but with dependency automatically installed @hc_dev. Replace it with python3 shebang and install the dependency yourself (dbus-python package). – Abdillah Jun 27 '23 at 20:13
  • Would someone happen to know how to change format and resolution? – sunknudsen Aug 20 '23 at 00:16
  • you can post process it in VLC but the quality quickly degrades and becomes pretty unusable. better to just start with a screen grab, ffmpeg, and record at the resolution you desire. – vtwaldo21 Aug 28 '23 at 18:53