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