this script truncates videos to mp4 files of 29 second clips and fixes audio compatibility for Twitter's janky fleets
Last active
March 5, 2021 08:04
-
-
Save kairusds/3a3f8934e4531ab73c03d44e53506923 to your computer and use it in GitHub Desktop.
credits: endrift and MarioMasta64, slightly modified by me
This file contains hidden or 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/sh | |
if [ $# -eq 0 ]; then | |
echo "Usage: fleeter FILE\n" | |
exit 1 | |
fi | |
VIDEO=$1 | |
LEN=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$VIDEO") | |
CHUNKSIZE=29 | |
EPSILON=0.1 | |
CHUNKS=$(echo "scale=0;($LEN + $CHUNKSIZE - $EPSILON) / $CHUNKSIZE" | bc) | |
for C in $(seq 0 $(($CHUNKS-1))); do | |
# add echo to the front to see output as test | |
ffmpeg -ss $(printf "%02i" $(( $C * $CHUNKSIZE / 3600 ))):$(printf "%02i" $(( $C * $CHUNKSIZE / 60 % 60 ))):$(printf "%02i" $(( $C * $CHUNKSIZE % 60))) -i "$VIDEO" -t $CHUNKSIZE -sn -c:a aac -b:a 256k -pix_fmt yuv420p -c:v libx264 -crf 14 $(($C+1)).mp4 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment