Skip to content

Instantly share code, notes, and snippets.

@fkztw
Forked from goncalossilva/gifenc.sh
Created October 8, 2015 05:37
Show Gist options
  • Save fkztw/532f67d20eff0d94e6c9 to your computer and use it in GitHub Desktop.
Save fkztw/532f67d20eff0d94e6c9 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!
#!/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
#!/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
#!/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