3 # gst-screencast - screencasting of a window using GStreamer
5 # Copyright (C) 2015 Antonio Ospite <ao2@ao2.it>
7 # This program is free software. It comes without any warranty, to
8 # the extent permitted by applicable law. You can redistribute it
9 # and/or modify it under the terms of the Do What The Fuck You Want
10 # To Public License, Version 2, as published by Sam Hocevar. See
11 # http://sam.zoy.org/wtfpl/COPYING for more details.
16 [ "x" = "x$1" ] && { echo "usage: $(basename $0) <output_file> [<ximagesrc_options>]" 1>&2; exit 1; }
18 [ -f "$1" ] && { echo "ERROR: file already exists!" 1>&2; exit 2; }
24 # uncomment to capure the whole frame with window manager border and decorations
25 XWININFO_OPTIONS="-frame"
27 WIN_INFO="$(xwininfo $XWININFO_OPTIONS)"
29 #XID=$(echo "$WIN_INFO" | grep "Window id" | cut -d ' ' -f 4)
30 #XIMAGESRC_ARGS="xid=$XID"
32 X=$(echo "$WIN_INFO" | sed -n -e "/^[[:space:]]*Absolute upper-left X:[[:space:]]*/s///p")
33 Y=$(echo "$WIN_INFO" | sed -n -e "/^[[:space:]]*Absolute upper-left Y:[[:space:]]*/s///p")
34 WIDTH=$(echo "$WIN_INFO" | sed -n -e "/^[[:space:]]*Width:[[:space:]]*/s///p")
35 HEIGHT=$(echo "$WIN_INFO" | sed -n -e "/^[[:space:]]*Height:[[:space:]]*/s///p")
38 XIMAGESRC_ARGS="startx=$(($X - $BORDER_SIZE)) starty=$(($Y - $BORDER_SIZE)) endx=$(($X + $WIDTH + $BORDER_SIZE)) endy=$(($Y + $HEIGHT + $BORDER_SIZE))"
40 XIMAGESRC_ARGS="startx=$(($X - $BORDER_SIZE - 1)) starty=$(($Y - $BORDER_SIZE - 7)) endx=$(($X + $WIDTH + $BORDER_SIZE)) endy=$(($Y + $HEIGHT + $BORDER_SIZE + 7))"
45 VIDEO_CODEC="video/x-raw,format=I420 ! jpegenc quality=90"
46 #VIDEO_CODEC="openjpegenc"
49 ximagesrc use-damage=0 show-pointer=0 $XIMAGESRC_ARGS ! video/x-raw,framerate=25/1 ! \
50 videoconvert ! videorate ! $VIDEO_CODEC ! queue ! mux. \
51 matroskamux name=mux ! filesink location="$FILENAME"
52 #pulsesrc ! audioconvert ! 'audio/x-raw,rate=44100,channels=2' ! queue ! mux. \