Created
April 21, 2014 02:48
-
-
Save raidzero/11130929 to your computer and use it in GitHub Desktop.
Record a window ('s size) with ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# do we have the necessary software? | |
FFMPEG=`which ffmpeg` | |
XWININFO=`which xwininfo` | |
XDGOPEN=`which xdg-open` | |
if [ -z "$FFMPEG" ]; then | |
echo "ffmpeg not available" | |
exit 1 | |
fi | |
if [ -z "$XWININFO" ]; then | |
echo "xwininfo not found." | |
exit 1 | |
fi | |
OUTPUT="$1" | |
echo "Please click the window you wish to record. Press q to quit recording." | |
data=`$XWININFO` | |
XPOS=`echo "$data" | grep "Absolute upper-left X:" | cut -d ':' -f2 | sed 's/^ *//'` | |
YPOS=`echo "$data" | grep "Absolute upper-left Y:" | cut -d ':' -f2 | sed 's/^ *//'` | |
WIDTH=`echo "$data" | grep "Width:" | cut -d ':' -f2 | sed 's/^ *//'` | |
HEIGHT=`echo "$data" | grep "Height:" | cut -d ':' -f2 | sed 's/^ *//'` | |
# let's get the window borders too, they are 1px in each direction | |
#let XPOS-=1 | |
#let YPOS-=1 | |
#let HEIGHT+=2 | |
#let WIDTH+=2 | |
echo "Will record size ${WIDTH}x${HEIGHT} at position ${XPOS}x${YPOS}." | |
$FFMPEG -f alsa -ac 2 -i pulse -f x11grab -r 30 -s ${WIDTH}x${HEIGHT} -i :0.0+${XPOS},${YPOS} -acodec pcm_s16le -vcodec libx264 -threads 0 $OUTPUT | |
if [ $? -eq 0 ]; then | |
printf "\n\n\nFile created:\n" | |
ls -l $OUTPUT | |
printf "\nSuccess! File [$OUTPUT] created." | |
if [ -n "$XDGOPEN" ]; then | |
printf "Open now? [Y/N] " | |
read response | |
if [ "$response" == "y" ] || [ "$response" == "Y" ]; then | |
echo "Opening..." | |
xdg-open $OUTPUT | |
fi | |
fi | |
else | |
echo "Something went wrong :(" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment