3 # gst-screencast - screencasting of a window using GStreamer
5 # Copyright (C) 2015-2017 Antonio Ospite <ao2@ao2.it>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 usage: $(basename $0) [OPTIONS] <output_file> [<ximagesrc_options>]
26 Screencast script based on GStreamer.
29 --audio record audio from pulsesrc
30 --frame include the window manager border, without the shadows
31 --pointer capture the mouse pointer
32 --single-shot capture a single snapshot as a PNG instead of a video
33 -h, --help display this usage message and exit
63 echo "Error: Unknown option '${1}'" 1>&2
71 [ "x" = "x$1" ] && { usage 1>&2; exit 1; }
73 [ -f "$1" ] && { echo "Error: file '${1}' already exists!" 1>&2; exit 2; }
83 if [ $WINDOW_FRAME -eq 1 ];
85 XWININFO_OPTIONS="-frame"
87 # XXX the values below are still hardcoded, they may be different
88 # depending on the theme and the window manager.
94 WIN_INFO="$(xwininfo $XWININFO_OPTIONS)"
96 X=$(echo "$WIN_INFO" | sed -n -e "/^[[:space:]]*Absolute upper-left X:[[:space:]]*/s///p")
97 Y=$(echo "$WIN_INFO" | sed -n -e "/^[[:space:]]*Absolute upper-left Y:[[:space:]]*/s///p")
98 WIDTH=$(echo "$WIN_INFO" | sed -n -e "/^[[:space:]]*Width:[[:space:]]*/s///p")
99 HEIGHT=$(echo "$WIN_INFO" | sed -n -e "/^[[:space:]]*Height:[[:space:]]*/s///p")
101 XIMAGESRC_ARGS="startx=$(($X + $SHADOW_SIZE - $SHADOW_X_OFFSET)) starty=$(($Y + $SHADOW_SIZE - $SHADOW_Y_OFFSET)) endx=$(($X + $WIDTH - 1 - $SHADOW_SIZE - $SHADOW_X_OFFSET)) endy=$(($Y + $HEIGHT - 1 - $SHADOW_SIZE - $SHADOW_Y_OFFSET))"
106 if [ $SINGLE_SHOT -eq 1 ];
109 ximagesrc use-damage=0 show-pointer=$SHOW_POINTER $XIMAGESRC_ARGS num-buffers=1 ! \
110 videoconvert ! pngenc ! filesink location="$FILENAME"
112 VIDEO_CODEC="video/x-raw,format=I420 ! jpegenc quality=90"
114 if [ $CAPTURE_AUDIO -eq 1 ];
116 # Record from everything
117 if ! pactl list short sinks | grep -q module-null-sink;
120 PA_IDS=$(pactl load-module module-null-sink)
122 trap 'trap INT; for pa_id in $PA_IDS; do pactl unload-module "$pa_id"; done' EXIT
124 SOURCES=$(pactl list short sources | cut -f 2 | grep -v "^null\.monitor$")
125 for source in $SOURCES;
127 MODULE_ID=$(pactl load-module module-loopback latency_msec=1 source="$source" sink=null)
128 PA_IDS="$MODULE_ID $PA_IDS"
131 pactl set-sink-mute null 0
134 AUDIO_PIPELINE="pulsesrc device=null.monitor ! audioconvert ! audio/x-raw,rate=44100,channels=2 ! vorbisenc ! queue ! mux."
137 gst-launch-1.0 -v -e \
138 matroskamux name=mux ! filesink location="$FILENAME" \
139 ximagesrc use-damage=0 show-pointer=$SHOW_POINTER $XIMAGESRC_ARGS ! video/x-raw,framerate=25/1 ! \
140 videoconvert ! videorate ! $VIDEO_CODEC ! queue ! mux. \