Last active
September 3, 2022 16:22
-
-
Save HirbodBehnam/21942fe87728888d3f8656ae5208f83b to your computer and use it in GitHub Desktop.
A meme generator based on code of esmBot
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/bash | |
# This script is based on esmBot caption command. See code here: https://github.com/esmBot/esmBot/blob/master/natives/caption.cc | |
# It needs ffmpeg + ffprobe + vips installed. The meme is created with dark mode caption | |
# I used vips 8.13 and ffmepg build of 2022-06-16 | |
# It must be used like this: bash meme-generator.sh template.png "my caption of meme" | |
# Font is also available at https://github.com/esmBot/esmBot/blob/master/assets/caption.otf | |
WIDTH=$(ffprobe -v error -select_streams v -show_entries stream=width -of csv=p=0:s=x "$1") | |
FONT_SIZE=$((WIDTH/10)) | |
vips text caption.png "<span foreground=\"white\" background=\"black\">$2</span>" --width $WIDTH --font "futura bold $FONT_SIZE" --align centre --rgba | |
ffmpeg -i caption.png -vf "pad=$WIDTH:ih+$FONT_SIZE:(ow-iw)/2:(oh-ih)/2" caption2.png | |
OUTPUT_NAME="output." | |
FPS="" | |
if [[ "${1##*.}" == "mp4" ]]; then | |
OUTPUT_NAME+="mp4" | |
FPS=$(ffprobe -v error -select_streams v -of default=noprint_wrappers=1:nokey=1 -show_entries stream=r_frame_rate "$1") | |
FPS=$(($FPS)) | |
FPS="-r $FPS" | |
echo "FPS IS $FPS" | |
else | |
OUTPUT_NAME+="png" | |
fi | |
ffmpeg $FPS -i caption2.png -i "$1" -filter_complex vstack "$OUTPUT_NAME" | |
rm caption.png caption2.png |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment