Created
October 27, 2021 01:36
-
-
Save gwollman/7a40ce5a96160ad5a21f2cca0b44f4e8 to your computer and use it in GitHub Desktop.
A simple shell script to record the contents of a window to a video file using only 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 | |
outfile="${1-screencast.mp4}" | |
echo -n 'Click on the window you wish to record...' | |
tmpfile=$(mktemp /tmp/screencast.XXXXXX) | |
trap "rm -f $tmpfile" 0 1 3 15 | |
xwininfo > $tmpfile | |
echo 'done.' | |
origin=$(awk '/Corners:/ { print $2 }' $tmpfile | sed 's/\(+[[:digit:]]*\)+/\1,/') | |
width=$(awk '/Width:/ { print $2 }' $tmpfile) | |
height=$(awk '/Height:/ { print $2 }' $tmpfile) | |
rm -f $tmpfile | |
trap - 0 1 3 15 | |
echo "Recording to ${outfile}..." | |
ffmpeg -video_size "${width}x${height}" -framerate 24 -f x11grab -i ":0${origin}" -preset ultrafast -qp 0 -y "$outfile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apparently both Android and Firefox object to native 4:4:4 chroma format that the
x11grab
driver generates; you'll probably want to postprocess the video anyway for better compression, so add-pix_fmt yuv420p
if compatibility matters to you.