record-desktop.sh - randomcrap - random crap programs of varying quality
 (HTM) git clone git://git.codemadness.org/randomcrap
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       record-desktop.sh (1409B)
       ---
            1 #!/bin/sh
            2 # record X11 desktop to .webm file/stdout.
            3 # can record a specific window.
            4 #
            5 # Dependencies: ffmpeg for recording.
            6 #               xrandr for desktop dimensions.
            7 #               xdotool for specific window.
            8 #               xwininfo for selecting a window and getting the $WINDOWID.
            9 
           10 spec="${DISPLAY:-:0.0}"
           11 
           12 # argument 1 is the $WINDOWID.
           13 win=""
           14 if test -n "$1"; then
           15         win="$1"
           16 fi
           17 
           18 # special parameter "sel": click on a window to get the window id and record it.
           19 if test x"$win" = x"sel"; then
           20         win=$(xwininfo | sed -nE 's/.*Window id: (0x[0-9a-f]+).*/\1/p')
           21         if test -z "$win"; then
           22                 echo "could not get window id" >&2
           23                 exit 1
           24         fi
           25 fi
           26 
           27 # get window geometry information if window id specified.
           28 if test -n "$win"; then
           29         # NOTE: a limitation is that the window should not be moved.
           30         eval $(xdotool getwindowgeometry --shell "$win")
           31         if test -z "$X" || test -z "$Y"; then
           32                 echo "unknown window size" >&2
           33                 exit 1
           34         fi
           35         BORDER="3" # workaround: don't record border: for me it's 3 pixels.
           36         X=$((X + BORDER))
           37         Y=$((Y + BORDER))
           38 #        WIDTH=$((WIDTH - BORDER))
           39 #        HEIGHT=$((HEIGHT - BORDER))
           40 
           41         spec="${spec}+$X,$Y"
           42         size="${WIDTH}x${HEIGHT}"
           43 else
           44         # record whole screen.
           45         size=$(xrandr --current | sed -nE 's/.*current ([0-9]+) x ([0-9]+).*/\1x\2/p')
           46         if test -z "$size"; then
           47                 echo "unknown monitor/desktop size" >&2
           48                 exit 1
           49         fi
           50 fi
           51 
           52 ffmpeg -video_size "$size" -f x11grab -framerate 60 -i "$spec" -f webm -