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 AUDIO_PIPELINE="pulsesrc ! audioconvert ! audio/x-raw,rate=44100,channels=2 ! queue ! mux."
120 matroskamux name=mux ! filesink location="$FILENAME" \
121 ximagesrc use-damage=0 show-pointer=$SHOW_POINTER $XIMAGESRC_ARGS ! video/x-raw,framerate=25/1 ! \
122 videoconvert ! videorate ! $VIDEO_CODEC ! queue ! mux. \