Skip to content

Instantly share code, notes, and snippets.

@jorgemfm
Forked from anonymous/rec.sh
Last active December 18, 2015 05:59
Show Gist options
  • Save jorgemfm/5736965 to your computer and use it in GitHub Desktop.
Save jorgemfm/5736965 to your computer and use it in GitHub Desktop.
script to record a screen window with avconv or ffmpeg
#!/bin/sh
#
#script to record a screen window with avconv or ffmpeg.
#uses xwininfo to get info about the window to record
#based on https://gist.github.com/anonymous/3927068 (http://www.youtube.com/watch?v=_XDa1ahl7fw)
INFO=$(xwininfo -frame)
WIN_GEO=$(echo $INFO | grep -oEe 'geometry [0-9]+x[0-9]+' |\
grep -oEe '[0-9]+x[0-9]+')
WIN_XY=$(echo $INFO | grep -oEe 'Corners:\s+\+[0-9]+\+[0-9]+' |\
grep -oEe '[0-9]+\+[0-9]+' | sed -e 's/+/,/' )
#checks if width and height are odd numbers and adds +1 if true
#because libx264 complaints if width/height are not divisible by 2
WIDTH=`echo $WIN_GEO| cut -d'x' -f 1`
HEIGHT=`echo $WIN_GEO| cut -d'x' -f 2`
REM=$(( $HEIGHT % 2 ))
if [ $REM -ne 0 ]
then
HEIGHT=$(( HEIGHT + 1 ))
fi
REM=$(( $WIDTH % 2 ))
if [ $REM -ne 0 ]
then
WIDTH=$(( WIDTH + 1 ))
fi
WIN_GEO="${WIDTH}x${HEIGHT}"
avconv -f x11grab -y -r 30 -s $WIN_GEO -i :0.0+$WIN_XY -vcodec libx264 $1.avi
#original command
#ffmpeg -f x11grab -y -r 15 -s $WIN_GEO -i :0.0+$WIN_XY -vcodec ffv1 -sameq -f alsa -ac 2 -i pulse -acodec ac3 -threads 2 $1.avi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment