-
-
Save pavlos/4273ea8ebfd16e61d977fe7d1456b3ad to your computer and use it in GitHub Desktop.
Handy scripts to encode mp4, webm and gif using ffmpeg (2.6 or above). Audio is discarded on all of these!
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 | |
# sh gifenc.sh input.mp4 output.gif | |
# Optionally accepts width / height (one or both). | |
palette="/tmp/palette.png" | |
filters="fps=15" | |
if [ ! -z $3 ]; then | |
if [ ! -z $4 ]; then | |
filters="$filters,scale=$3:$4" | |
else | |
filters="$filters,scale=$3:-1" | |
fi | |
filters="$filters:flags=lanczos" | |
fi | |
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette | |
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2 |
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 | |
# sh mp4enc.sh input.mp4 output.mp4 [quality] | |
# Optionally accepts a "quality" parameter (defaults to 640). | |
# https://www.virag.si/2012/01/web-video-encoding-tutorial-with-ffmpeg-0-9 | |
quality="640k" | |
if [ ! -z $3 ]; then | |
quality="$3k" | |
fi | |
options="-c:v libx264 -b:v $quality -maxrate $quality -bufsize 1000k -profile:v high -preset veryslow -tune film -movflags +faststart -threads 1" | |
ffmpeg -y -i $1 $options -pass 1 -an -f rawvideo /dev/null && ffmpeg -i $1 $options -pass 2 -an $2 |
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 | |
# sh wemenc.sh input.mp4 output.webm [quality] | |
# Optionally accepts a "quality" parameter (defaults to 700). | |
# https://www.virag.si/2012/01/webm-web-video-encoding-tutorial-with-ffmpeg-0-9 | |
quality="700k" | |
if [ ! -z $3 ]; then | |
quality="$3k" | |
fi | |
options="-c:v libvpx -b:v $quality -maxrate $quality -bufsize 1000k -preset veryslow -tune film -movflags +faststart -threads 1" | |
ffmpeg -y -i $1 $options -pass 1 -an -f rawvideo /dev/null && ffmpeg -i $1 $options -pass 2 -an $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment