Add gst-screencast.sh
authorAntonio Ospite <ao2@ao2.it>
Fri, 2 Dec 2016 11:54:20 +0000 (12:54 +0100)
committerAntonio Ospite <ao2@ao2.it>
Fri, 2 Dec 2016 11:54:20 +0000 (12:54 +0100)
shell/gst-screencast.sh [new file with mode: 0755]

diff --git a/shell/gst-screencast.sh b/shell/gst-screencast.sh
new file mode 100755 (executable)
index 0000000..1902f49
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+# gst-screencast - screencasting of a window using GStreamer
+#
+# Copyright (C) 2015  Antonio Ospite <ao2@ao2.it>
+#
+# This program is free software. It comes without any warranty, to
+# the extent permitted by applicable law. You can redistribute it
+# and/or modify it under the terms of the Do What The Fuck You Want
+# To Public License, Version 2, as published by Sam Hocevar. See
+# http://sam.zoy.org/wtfpl/COPYING for more details.
+
+set -e
+set -x
+
+[ "x" = "x$1" ] && { echo "usage: $(basename $0) <output_file> [<ximagesrc_options>]" 1>&2; exit 1; }
+
+[ -f "$1" ] && { echo "ERROR: file already exists!" 1>&2; exit 2; }
+
+FILENAME="$1"
+
+if [ "x" = "x$2" ];
+then
+  # uncomment to capure the whole frame with window manager border and decorations
+  XWININFO_OPTIONS="-frame"
+
+  WIN_INFO="$(xwininfo $XWININFO_OPTIONS)"
+
+  #XID=$(echo "$WIN_INFO" | grep "Window id" | cut -d ' ' -f 4)
+  #XIMAGESRC_ARGS="xid=$XID"
+
+  X=$(echo "$WIN_INFO" | sed -n -e "/^[[:space:]]*Absolute upper-left X:[[:space:]]*/s///p")
+  Y=$(echo "$WIN_INFO" | sed -n -e "/^[[:space:]]*Absolute upper-left Y:[[:space:]]*/s///p")
+  WIDTH=$(echo "$WIN_INFO" | sed -n -e "/^[[:space:]]*Width:[[:space:]]*/s///p")
+  HEIGHT=$(echo "$WIN_INFO" | sed -n -e "/^[[:space:]]*Height:[[:space:]]*/s///p")
+
+  BORDER_SIZE=27
+  XIMAGESRC_ARGS="startx=$(($X - $BORDER_SIZE)) starty=$(($Y - $BORDER_SIZE)) endx=$(($X + $WIDTH + $BORDER_SIZE)) endy=$(($Y + $HEIGHT + $BORDER_SIZE))"
+
+  XIMAGESRC_ARGS="startx=$(($X - $BORDER_SIZE - 1)) starty=$(($Y - $BORDER_SIZE - 7)) endx=$(($X + $WIDTH + $BORDER_SIZE)) endy=$(($Y + $HEIGHT + $BORDER_SIZE + 7))"
+else
+  XIMAGESRC_ARGS="$2"
+fi
+
+VIDEO_CODEC="video/x-raw,format=I420 ! jpegenc quality=90"
+#VIDEO_CODEC="openjpegenc"
+
+gst-launch-1.0 -v \
+  ximagesrc use-damage=0 show-pointer=0 $XIMAGESRC_ARGS ! video/x-raw,framerate=25/1 ! \
+  videoconvert ! videorate ! $VIDEO_CODEC ! queue ! mux. \
+  matroskamux name=mux ! filesink location="$FILENAME"
+  #pulsesrc ! audioconvert ! 'audio/x-raw,rate=44100,channels=2' ! queue ! mux. \