>>108738423
zsh
addMemeStyleCaptionToTopOfVideo() {
if [ $# -lt 3 ]; then
echo "Usage: addMemeStyleCaptionToTopOfVideo <input_file> <caption_text> <output_file>"
return 1
fi
# Escape single quotes and other special characters in the text
local escaped_text=$(echo "$2" | sed "s/'/'\\\\\\\\''/g")
# Estimate number of lines (rough calculation: ~25 chars per line at fontsize 50 for 1920px width)
local text_length=${#2}
local chars_per_line=25
local estimated_lines=$(( (text_length + chars_per_line - 1) / chars_per_line ))
# Calculate dynamic padding (60px per line + 40px margin)
local padding_height=$(( estimated_lines * 60 + 40 ))
# Use text wrapping with dynamic padding
ffmpeg -i "$1" -vf "pad=iw:ih+${padding_height}:0:${padding_height}:color=white,drawtext=text='${escaped_text}':x=(w-text_w)/2:y=(${padding_height}-text_h)/2:fontcolor=black:fontsize=50:fontfile=/System/Library/Fonts/Supplemental/Arial.ttf:text_w=1800" "$3"
}