Skip to content

Instantly share code, notes, and snippets.

@fffonion
Created September 29, 2024 08:35
Show Gist options
  • Save fffonion/16dfbd669a75f2d3e6c707d04d9df9fd to your computer and use it in GitHub Desktop.
Save fffonion/16dfbd669a75f2d3e6c707d04d9df9fd to your computer and use it in GitHub Desktop.
Prepare telegram stickers
#!/bin/bash
mkdir -p ani ani-s
input_file="$1"
fix_factor="${2:-1}"
# Get the duration of the video
duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$input_file")
# Remove any decimal places from the duration
duration=${duration%.*}
if [ "$duration" -ge 3 ]; then
# If longer than 3 seconds, speed up the video
speed_factor=$(echo "scale=5; 2.5 / $duration * $fix_factor" | bc)
filter=",setpts=$speed_factor*PTS"
echo $filter
fi
ffmpeg -i $input_file -vf "scale='512':'512':force_original_aspect_ratio=increase,crop=w='512':h='512'$filter" -maxrate 450k -b:v 450k -y "ani/$(basename $1).webm" >/dev/null
ffmpeg -i $input_file -vf "scale='100':'100':force_original_aspect_ratio=increase,crop=w='100':h='100'$filter" -maxrate 100k -b:v 100k -y "ani-s/$(basename $1).webm" >/dev/null
#!/bin/bash
mkdir -p sta sta-s
convert -resize "512x512^" -gravity Center -extent 512x512 -background none $1 sta/$1
convert -resize "100x100^" -gravity Center -extent 100x100 -background none $1 sta-s/$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment