Last active
October 18, 2016 11:49
-
-
Save coderbyheart/863aabb3a190999660ee202eabfbc77a to your computer and use it in GitHub Desktop.
web-video-conversion.sh
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 | |
IN=$1 | |
OUT="`echo "$IN" | cut -d'.' -f1`-web" | |
rm -f ffmpeg2pass* | |
# 1/3 of 1920x1090 | |
WIDTH=1280 | |
HEIGHT=720 | |
# webm | |
if [ ! -f "${OUT}.webm" ]; then | |
ffmpeg -i ${IN} -c:v libvpx -pass 1 -an -f rawvideo -y /dev/null # Generates ffmpeg2pass-0.log | |
ffmpeg -i ${IN} -c:v libvpx -pass 2 -f webm -s ${WIDTH}x${HEIGHT} -b:v 1000k -crf 10 -c:a libvorbis -aq 4 -y ${OUT}.webm | |
else | |
echo "${OUT}.webm exists, skipping" | |
fi | |
# mp4 | |
if [ ! -f "${OUT}.mp4" ]; then | |
ffmpeg -i ${IN} -hide_banner -loglevel error -stats -codec:v libx264 -threads 0 -profile:v main -preset slow -b:v 1000k -maxrate 1000k -bufsize 2000k -pass 1 -f mp4 -y /dev/null | |
ffmpeg -i ${IN} -hide_banner -loglevel error -stats -codec:v libx264 -threads 0 -profile:v main -preset slow -b:v 1000k -maxrate 1000k -bufsize 2000k -codec:a aac -b:a 128k -pass 2 -f mp4 -s ${WIDTH}x${HEIGHT} -y ${OUT}.mp4 | |
else | |
echo "${OUT}.mp4 exists, skipping" | |
fi | |
# ogg (if you want to support older Firefox) | |
if [ ! -f "${OUT}.ogv" ]; then | |
ffmpeg2theora ${IN} -o ${OUT}.ogv -x ${WIDTH} -y ${HEIGHT} --videoquality 5 --audioquality 1 --audiobitrate 128 --frontend | |
else | |
echo "${OUT}.ogv exists, skipping" | |
fi | |
# still | |
if [ ! -f "${OUT}.jpg" ]; then | |
eval "$(ffprobe -v error -of flat=s=_ -show_entries format=duration ${IN})" | |
ffmpeg -ss "$(echo "$format_duration/2" | bc)" -i ${IN} -s ${WIDTH}x${HEIGHT} -q:v 2 -frames:v 1 ${OUT}.jpg | |
else | |
echo "${OUT}.jpg exists, skipping" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment