]>
git.slaskete.net - einar-bin/blob - ffmpeg-grab-window-with-sound.bash
2dfa61dcd1becc76cd53bca7761c150af86202b1
2 # A simple script to grab a screencast of a window using ffmpeg
3 # Once started, select the window you want to record, and start
4 # talking/using the indicated program
6 # Select window to grab info from
7 INFO
=$(xwininfo -frame)
10 WIN_SIZE
=$(echo $INFO | grep -oEe 'geometry [0-9]+x[0-9]+' | grep -oEe '[0-9]+x[0-9]+')
11 # Get the window position
12 WIN_XY
=$(echo $INFO | grep -oEe 'Corners: \+[0-9]+\+[0-9]+' | grep -oEe '[0-9]+\+[0-9]+' | sed -e 's/\+/,/')
13 # Determine window width and window height, and adjust to be divisible by two
14 WIN_WIDTH
=$(echo $WIN_SIZE | cut -d "x" -f 1 | awk '{print $1+$1%2}')
15 WIN_HEIGHT
=$(echo $WIN_SIZE | cut -d "x" -f 2 | awk '{print $1+$1%2}')
18 # Audio from alsa, using one channel, using the default pulse input device
19 # Video from X11, framerate 30
20 # Use the libx264 video encoder with the lossless_ultrafast preset
21 # Use the libmp3lame audio encoder
22 # Output to a file in the user's homedir, using current date and time
25 -f alsa
-ac 1 -i pulse \
26 -f x11grab
-r 30 -s ${WIN_WIDTH}x
${WIN_HEIGHT} -i :0.0+${WIN_XY} \
27 -vcodec libx264
-vpre lossless_ultrafast \
29 ${HOME}/screencast
-$(date +%F-%H-%M-%S).mkv