Skip to content

Instantly share code, notes, and snippets.

@zarac
Created August 26, 2017 17:07
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 zarac/42e76ac8c78ebeb7a69ed410fa3070c0 to your computer and use it in GitHub Desktop.
Save zarac/42e76ac8c78ebeb7a69ed410fa3070c0 to your computer and use it in GitHub Desktop.
#!/bin/sh
FILE=$1 && shift
# screen with and height
wh=$(xrandr | grep '*' | awk '{ print $1 }')
w=$(echo $wh | awk -F'x' '{ print $1 }')
h=$(echo $wh | awk -F'x' '{ print $2 }')
if [ -z $FPS ]; then
FPS=10
fi
if [ -z $Q ]; then
Q=10
fi
if [ -z $Y ]; then
Y=$h
fi
if [ -z $X ]; then
X=$w
fi
if [ -z $FILE ]; then
FILE=$(date).mkv
fi
wmctrl -r :SELECT: -e 0,0,0,$X,$Y
while [ true ] ; do
if [ ! -f "$FILE" ]; then
break
fi
FILE=new-$FILE
done
VIDEO="-f x11grab -s ${X}x$Y -r $FPS -i $DISPLAY -q:v $Q -codec:v libx264"
AUDIO="-f pulse -ac 2 -ar 44100 -i default"
##[pulse @ 0xd845a57520] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
## https://nowardev.wordpress.com/2015/03/24/ffmpeg-and-the-message-thread-message-queue-blocking-consider-raising-the-thread_queue_size-option-current-value-8-alsa-buffer-xrun/
FLAGS="-thread_queue_size 512"
#[x11grab @ 0x7e9bc27320] Stream #0: not enough frames to estimate rate; consider increasing probesize
# https://ffmpeg.org/pipermail/ffmpeg-user/2014-May/021227.html
FLAGS="$FLAGS -probesize 10M"
if [ ! -z $NO_AUDIO ]; then
AUDIO=""
fi
cmd="ffmpeg $FLAGS $AUDIO $VIDEO \"$FILE\""
>&2 echo "$cmd"
>&2 echo -n Live in 3 sleep 0.25
sleep 0.25
>&2 echo -n .
sleep 0.25
>&2 echo -n .
sleep 0.25
>&2 echo -n .
sleep 0.25
>&2 echo -n 2
sleep 0.25
>&2 echo -n .
sleep 0.25
>&2 echo -n .
sleep 0.25
>&2 echo -n .
sleep 0.25
>&2 echo -n 1
sleep 0.25
>&2 echo -n .
sleep 0.25
>&2 echo -n .
sleep 0.25
>&2 echo -n .
sleep 0.25
>&2 echo Recording!
ffmpeg $FLAGS $AUDIO $VIDEO "$FILE"
>&2 echo Created $FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment