Instantly share code, notes, and snippets.

Embed
What would you like to do?
Screen cast with ffmpeg / xwininfo.
#!/usr/bin/zsh
SAVE_DIR=/home/foo/Videos/
even_round() {
perl -n -e '/(\d+)(.)(\d+)/; print( $1 % 2 == 0 ? $1 : $1 - 1 ); print $2; print( $3 % 2 == 0 ? $3 : $3 - 1 )' <<< "$1"
}
mic_arg() {
if (( $mic == 1 ))
then
print -- "-f alsa -i pulse -acodec aac"
fi
}
integer wmode=0
typeset -g mic=0
for i in "$@"
do
#Window mode ( -w option. )
if [[ $i == "-w" ]]
then
integer wmode=1
fi
#Pulse mic
if [[ $i == "-m" ]]
then
typeset -g mic=1
fi
done
if (( wmode == 1 ))
then
xwininfo=$(xwininfo -frame)
geo=$(perl -n -e '/geometry (\d+x\d+)/; print $1;' <<< "$xwininfo")
corn=$(perl -n -e '/Corners:\s+\+(\d+)\+(\d+)/ && print $1 . "," . $2;' <<< "$xwininfo")
ffmpeg -show_region 1 -f x11grab -video_size $(even_round $geo) -i "$DISPLAY+$(even_round $corn)" ${=$(mic_arg)} -vcodec libx264 -preset ultrafast -qp 0 "$SAVE_DIR/$(date +"%y%m%d%H%M%S")".mp4
else
geo=$(xwininfo -root | perl -n -e '/geometry (\d+x\d+)/ && print $1;')
ffmpeg -f x11grab -video_size $(even_round $geo) -i "$DISPLAY" ${=$(mic_arg)} -vcodec libx264 -preset ultrafast -qp 0 "$SAVE_DIR/$(date +"%y%m%d%H%M%S")".mp4
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment