Skip to content

Instantly share code, notes, and snippets.

@sfan5
Created September 8, 2014 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfan5/8b80bf332ab9066eb3e2 to your computer and use it in GitHub Desktop.
Save sfan5/8b80bf332ab9066eb3e2 to your computer and use it in GitHub Desktop.
Records a window
#!/bin/bash -e
CRF=21
ABITRATE=256k
FILENAME=recording`date +%d-%m-%Y_%H.%M`.mp4
CMD=`xwininfo | awk '/Width/{printf"ffmpeg -f x11grab -s "$2"x"}/Height/{printf$2" -i '$DISPLAY'"}/Corners/{gsub(/\+/,",",$2);sub(/,/,"+",$2);print$2" -f alsa -i pulse -c:v libx264 -preset ultrafast -crf 0 -c:a copy"}'`
CMD="${CMD} -vf scale='iw+mod(iw,2):ih+mod(ih,2)' _tmp_record.nut"
# -vf scale='iw+mod(iw,2):ih+mod(ih,2)' makes sure the width and height are diviseable by 2 (needed for libx264)
echo "Press ^C to stop recording"
$CMD || true
ffmpeg -i _tmp_record.nut -c:v libx264 -pix_fmt yuv420p -crf $CRF -tune film -c:a libfdk_aac -b:a $ABITRATE -movflags +faststart "$FILENAME"
rm -f _tmp_record.nut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment