Last active
September 15, 2022 12:15
-
-
Save mrcoles/51530f33c16f7f54e8fc74f478d243a2 to your computer and use it in GitHub Desktop.
Script for compressing a video to .mp4 and .webm with ffmpeg
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
#!/usr/bin/env bash | |
# inspired by: https://gist.github.com/Vestride/278e13915894821e1d6f | |
INPUT=$1 | |
OUTDIR="out/" | |
if [ -z "$INPUT" ]; then | |
echo "No file specified" | |
exit 1 | |
fi | |
if [ ! -f "$INPUT" ]; then | |
echo "Input is not a file: $INPUT" | |
exit 1 | |
fi | |
echo $INPUT | |
FILENAME=$(basename -- "$INPUT") | |
FILENAME="${FILENAME%.*}" | |
mkdir -p "$OUTDIR" | |
OUTFILE_NO_EXT="$OUTDIR$FILENAME" | |
set -e | |
date -u | |
# make mp4 file | |
# | |
# * -an = disable audio stream | |
# * -pix_fmt yuv420p = quicktime support | |
# * -profile:v baseline = maximum compatability but may increase bitrate a bit | |
# | |
ffmpeg -an -i "$INPUT" -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level 3 "$OUTFILE_NO_EXT.mp4" | |
date -u | |
# make webm file | |
# | |
ffmpeg -i "$INPUT" -vcodec libvpx-vp9 -b:v 1M -acodec libvorbis "$OUTFILE_NO_EXT.webm" | |
date -u | |
# # make super webm file! | |
# # | |
# ffmpeg -i "$INPUT" -c:v libvpx-vp9 -pass 1 -b:v 1000K -threads 1 -speed 4 \ | |
# -tile-columns 0 -frame-parallel 0 -auto-alt-ref 1 -lag-in-frames 25 \ | |
# -g 9999 -aq-mode 0 -an -f webm /dev/null | |
# ffmpeg -i "$INPUT" -c:v libvpx-vp9 -pass 2 -b:v 1000K -threads 1 -speed 0 \ | |
# -tile-columns 0 -frame-parallel 0 -auto-alt-ref 1 -lag-in-frames 25 \ | |
# -g 9999 -aq-mode 0 -c:a libopus -b:a 64k -f webm "$OUTFILE_NO_EXT.super.webm" | |
# date -u | |
set +e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🎥 Video compressor
Installation 💻
Install Homebrew: https://brew.sh/ or if you already have it, run
brew update
from the Terminal App.Run:
brew install ffmpeg
Download this file
compress-video.sh
into a folder where you’ll run these scriptsRunning the script 🏃♂️
Using the Terminal App, navigate to wherever this script lives and then run it, e.g., if it lives in a folder on your desktop called "compressor":
Then wait for it to do its work (compression takes about ~10x the length of the video to complete). It will create files in the "out/" directory next to the script.
For extra webm compression (takes a lot longer), comment out the "make super webm file!" section and run that. ✨