Skip to content

Instantly share code, notes, and snippets.

@goncalossilva
Last active December 12, 2023 22:31
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save goncalossilva/865e90b66e4bddc58f40 to your computer and use it in GitHub Desktop.
Save goncalossilva/865e90b66e4bddc58f40 to your computer and use it in GitHub Desktop.
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 [ -n "$3" ]; then
if [ -n "$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 [ -n "$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 [ -n "$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"
@goncalossilva
Copy link
Author

@Zettt Apologies for the multi-year delay here, I missed your comments before! I've applied your suggestion, we certainly don't want word splitting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment