-
-
Save metaColin/5ebc432eec141899a8e6 to your computer and use it in GitHub Desktop.
Simple HTML5 video encoding bash script for OS X (Easily ported to Linux)
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 | |
set -e | |
# IMPORTANT! First install ffmpeg with encoders enabled, i.e. like this: | |
# brew install ffmpeg --with-libvpx --with-libvorbis --with-theora | |
# Will not re-encode files, if output file exists. | |
# Quality settings are configured in encoders' command line parameters below, sorry about that. | |
if [ -z "$1" ]; then | |
echo "ERROR: You need to set the original filename as the first parameter!" | |
exit 1 | |
fi | |
if [ ! -f "$1" ]; then | |
echo "ERROR: Input file not found!" | |
exit 1 | |
fi | |
if [ -z "$2" ]; then | |
echo "ERROR: You need to set the resolution as the second parameter, for example: 1280x720" | |
exit 1 | |
fi | |
INPUT="$1" | |
RESOLUTION="$2" | |
OUTPUT=${INPUT%.*} | |
echo "Trying to convert $INPUT ($RESOLUTION)" | |
echo "" | |
# -- h264 | |
if [ ! -f "$OUTPUT"_"$RESOLUTION"_converted.mp4 ]; then | |
echo "Converting to h246 (.mp4) ... " | |
ffmpeg -loglevel warning -hide_banner -i "$INPUT" -an -c:v libx264 -profile:v high -preset slow -b:v 1000k -maxrate 2000k -bufsize 1000k -s "$RESOLUTION" "$OUTPUT"_"$RESOLUTION"_converted.mp4 | |
echo " - done." | |
else | |
echo "h264 (.mp4) already converted." | |
fi | |
echo "" | |
# -- WebM | |
if [ ! -f "$OUTPUT"_"$RESOLUTION"_converted.webm ]; then | |
echo "Converting to WebM (.webm) ..." | |
ffmpeg -loglevel warning -hide_banner -i "$INPUT" -an -c:v libvpx -quality good -cpu-used 0 -qmin 0 -qmax 40 -b:v 1000k -crf 6 -s "$RESOLUTION" "$OUTPUT"_"$RESOLUTION"_converted.webm | |
echo " - done." | |
else | |
echo "WebM (.webm) already converted." | |
fi | |
echo "" | |
# -- Theora/Vorbis | |
if [ ! -f "$OUTPUT"_"$RESOLUTION"_converted.ogv ]; then | |
echo "Converting to Theora/Vorbis (.ogv) ..." | |
ffmpeg -loglevel warning -hide_banner -i "$INPUT" -an -c:v libtheora -q:v 6 -b:v 1000k -s "$RESOLUTION" "$OUTPUT"_"$RESOLUTION"_converted.ogv | |
echo " - done." | |
else | |
echo "Theora/Vorbis (.ogv) already converted." | |
fi | |
echo "" | |
say "Encoding complete" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment