Created
September 29, 2024 08:35
-
-
Save fffonion/16dfbd669a75f2d3e6c707d04d9df9fd to your computer and use it in GitHub Desktop.
Prepare telegram stickers
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 | |
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 |
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 | |
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