rendered paste body#!/bin/bashset -x__TMPDIR=~/tmp/function stopCapture{
if [ -e "~/tmp/capture.pid" ]; then
sleep 10
kill `cat ~/tmp/capture.pid`
rm ~/tmp/capture.pid -f
fi
if [ -e "~/tmp/capture.avi" ]; then
saveCapture
fi
if [ -e "~/tmp/capture.win" ]; then
rm ~/tmp/capture.win -f
fi
return 0
}
function saveCapture{ mv ~/tmp/capture.avi ~/Desktop/capture.avi
zenity --question --text "Export to the non-proprietary format Ogg/Ogm?"
if [ "$?" == "0" ]; then
xterm -T "Exporting to Ogg/Ogm..." -e ffmpeg2theora ~/Desktop/capture.avi
fi
}
function modeCapture{cMode=$(zenity --list --radiolist --column "" --column "Select capture mode" TRUE "Whole screen" FALSE "Select a window")
if [ "$?" == "1" ]; then
return 1
fi
if [ "$cMode" == "Whole screen" ]; then
xwininfo -root > ~/tmp/capture.win
else
xwininfo -frame > ~/tmp/capture.win
fi
cMessage=`cat ~/tmp/capture.win`
zenity --question --text="$cMessage" --title="Begin capture?"
return "$?"
}
function startCapture{modeCapture
if [ "$?" == "1" ]; then
return 1
fi
nLeft=$(cat ~/tmp/capture.win | grep 'Absolute upper-left X:' | awk '{print $NF}')
nTop=$(cat ~/tmp/capture.win | grep 'Absolute upper-left Y:' | awk '{print $NF}')
nWidth=$(cat ~/tmp/capture.win | grep Width: | awk '{print $NF}')
nHeight=$(cat ~/tmp/capture.win | grep Height: | awk '{print $NF}')
if [ $(( nWidth % 2 )) -gt 0 ];then
nWidth=$(( nWidth + 1 ))fi
if [ $(( nHeight % 2 )) -gt 0 ]; then
nHeight=$(( nHeight + 1 ))
fi
cFileAvi=~~/tmp/capture.avi
$(ffmpeg -vcodec mpeg4 -b 1000 -r 10 -g 300 -vd x11:"$nLeft","$nTop" -s "$nWidth"x"$nHeight" "$cFileAvi" & echo "$!" > ~/tmp/capture.pid)
return 0
}
function checkIfRunning{if [ ! -e "~/tmp/capture.pid" ]; then
return 0
fi
zenity --question --text="Detected active capture process. Stop previous capture?"
if [ "$?" == "1" ]; then
return 1
fi
stopCapture
return 0
}
if [ "$1" == "-stop" ]; then
stopCapture
exit 0
fi
if [ "$1" == "-start" ]; then
checkIfRunning
if [ "$?" == "0" ]; then
startCapture
fi
exit "$?"
fi