Last active
October 18, 2022 14:49
-
-
Save bsaf/6f04956b14c7637e4826139d6ba4658e to your computer and use it in GitHub Desktop.
Speed up an input video by a given factor (or 2x by default)
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/sh | |
# REQUIREMENTS | |
# ffmpeg (brew install ffmpeg) | |
# | |
# INSTALLATION | |
# 1. Put the file somewhere (e.g. ~/bin) | |
# 2. Add that folder to your $PATH in .zshrc or equivalent (e.g. export PATH="$HOME/bin:$PATH") | |
# 3. Run it (speedvid input.mp4) | |
# if -h or no arguments are provided, print help and exit | |
if [ "$1" = "-h" ] || [ "$#" -eq 0 ]; then | |
echo "Usage: speedvid [options] [input_file] [output_file --optional]" | |
echo "Example: speedvid video.mp4" | |
echo "Options:" | |
echo " -h, --help Show this help message and exit" | |
echo " -s, --speedup Speedup factor (default: 2)" | |
exit 0 | |
fi | |
# if -s or --speedup is provided, set speedup factor | |
if [ "$1" = "-s" ] || [ "$1" = "--speedup" ]; then | |
speedup="$2" | |
shift 2 | |
else | |
speedup=2 | |
fi | |
# get the inverse of the speedup factor (for ffmpeg) | |
inv_speedup=$(echo "1/$speedup" | bc -l) | |
# if only -s or --speedup is provided, print error and exit | |
if [ "$#" -eq 0 ]; then | |
echo "Error: no file provided (try -h or --help for help)" | |
exit 1 | |
fi | |
# get the file name | |
filename="$1" | |
shift 1 | |
# get the filename without the extension | |
filename_without_extension="${filename%.*}" | |
# if there is an outfile, get that too | |
if [ "$#" -eq 1 ]; then | |
outfile="$1" | |
shift 1 | |
else | |
outfile="${filename_without_extension}-@${speedup}x.mp4" | |
fi | |
# speed up the video | |
ffmpeg -i $filename -filter:v "setpts=$inv_speedup*PTS" $outfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment