Skip to content

Instantly share code, notes, and snippets.

@shanecelis
Created June 5, 2025 07:54
Show Gist options
  • Save shanecelis/fb610eb2d5f9743a86aac0f2c12b9e3b to your computer and use it in GitHub Desktop.
Save shanecelis/fb610eb2d5f9743a86aac0f2c12b9e3b to your computer and use it in GitHub Desktop.
Shell script to label a video using ffmpeg.
#!/bin/bash
# label-video
function usage() {
echo "usage: label-video [-tlrb] [-c COLOR] [-s SIZE] [-f FONT.ttf] MESSAGE INPUT.mp4 OUTPUT.mp4";
echo " [-tlrb] top, left, right, bottom";
echo " -c set text color"
echo " -s set text size"
echo "Adds a label to a video file using ffmpeg."
}
x=10;
y=10;
color="white";
size=24;
font="";
while getopts htbrlc:s:f: opt; do
case $opt in
h) usage; exit 0;;
t) y=10;;
b) y="h-text_h-10";;
r) x="w-text_w-10";;
l) x="10";;
s) size="$OPTARG";;
c) color="$OPTARG";;
f) font=":fontfile=$OPTARG";;
esac
done
shift $[ OPTIND - 1 ];
if [ $# -ne 3 ]; then
echo "error: expects three arguments." >&2;
usage >& 2;
exit 1;
fi
message="$1";
input="$2";
output="$3";
ffmpeg -i "$input" -vf "drawtext=text='$message'$font:fontcolor=$color:fontsize=$size:x=$x:y=$y" -codec:a copy "$output"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment