ffmpeg_scripts

posted: May 30, 2021

using ffmpeg. I use ffmpeg to convert videos from one format to the other. In order to create small video files from gifs I use this script:

#!/usr/bin/sh
# two-pass video-conversion with resizing to width 
echo "$1 >> $2 resizing to width=$3 with target video-bitrate of $4"

ffmpeg -y -i "$1" -vf scale=$3:-1 -c:v vp9 -preset quality -b:v $4 -pass 1 -an -auto-alt-ref 0 -f webm /dev/null && \
ffmpeg -i "$1" -vf scale=$3:-1 -c:v vp9 -preset quality -b:v $4 -pass 2 -an -auto-alt-ref 0 $2

explanation

  • -an (no audio)
  • -vf (video filtering -> see below)
  • -c:v (video codec options - e.g. vp9 or libx264 )
  • -c:a (audio codec - e.g. vorbis)
  • -preset ([ultrafast, superfast, veryfast, faster, fast, medium (default), slow, slower, veryslow])
  • -b:v 1M (video bitrate )
  • -b:a (audio bitrate)

[*] some video filter options

  • scale=400:-1 (resize to width=400, keep aspect ratio)
  • scale=iw/2:-1 (resize image to 50% of input_width resolution, might stretch/squash the image)
  • scale=400:300 (resize image to 400x300 resolution, might stretch/squash the image)
  • negate (invert colors)

other useful command:

  • -codecs (print out a list of all codecs available on this computer)

links: