Skip to content

Instantly share code, notes, and snippets.

@sagax
Last active October 10, 2018 10:03
Show Gist options
  • Save sagax/76b9a179445b1b8406fdd1a04970381c to your computer and use it in GitHub Desktop.
Save sagax/76b9a179445b1b8406fdd1a04970381c to your computer and use it in GitHub Desktop.
record screen with ffmpeg
#!/bin/bash
# how to use
#
# |----------------------- $1 - filename; can be _
# | |------------------ $2 - window coordinate x
# | | |---------------- $3 - window coordinate y
# | | | |------------ $4 - width
# | | | | |------- $5 - height
# | | | | | |--- $6 - display number
# | | | | | |
# screen_video well 0 100 1280 600 0
#
# and after we got file well.flv
if [[ -z $(command -v ffmpeg) ]]; then echo "need istall ffmpeg"; exit 1; fi
if [[ -z "$1" || "$1" == "_" ]]; then
name="temp_screen_video_$(\
cat /dev/urandom |\
tr -dc 'a-zA-Z0-9' |\
fold -w 4 |\
head -n 1)"
else
name="$1"
fi
if [[ -n "$2" ]]; then x=$2; else x=0; fi
if [[ -n "$3" ]]; then y=$3; else y=0; fi
if [[ -n "$4" ]]; then width=$4; else width=1280; fi
if [[ -n "$5" ]]; then height=$5; else height=800; fi
if [[ -n "$6" ]]; then display=$6; else display=0; fi
video_size="${width}x${height}"
position="${x},${y}"
trap ctrl_c INT
ctrl_c() {
echo "record was stopped: ${name}.flv"
exit 0
}
echo "run record: ${name}.flv"
ffmpeg -v 0 -y -video_size ${video_size} -framerate 25 -f x11grab -i :${display}.0+${position} -strict -2 -qscale 5 "${name}".flv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment