Skip to content

Instantly share code, notes, and snippets.

@leo-cheron
Last active November 29, 2024 10:21
Show Gist options
  • Save leo-cheron/6371b69499e13dd0d0f6 to your computer and use it in GitHub Desktop.
Save leo-cheron/6371b69499e13dd0d0f6 to your computer and use it in GitHub Desktop.
FFMPEG - mp4 & webm conversion
ffmpeg -framerate 25 -y -start_number 1 -i %04d.png -pass 1 -c:v libvpx-vp9 \
-b:v 1800k -maxrate 2000k -minrate 1200k \
-deadline best -cpu-used 0 \
-auto-alt-ref 1 -lag-in-frames 25 \
-f webm /dev/null
ffmpeg -framerate 25 -start_number 1 -i %04d.png -pass 2 -c:v libvpx-vp9 \
-b:v 1800k -maxrate 2000k -minrate 1200k \
-deadline best -cpu-used 0 \
-auto-alt-ref 1 -lag-in-frames 25 \
output.webm
#!/bin/bash
SRC="$(dirname $0)/sources"
DEST="$(dirname $0)/export"
BITRATE="1600k"
BITRATE_MAX="3200k"
WIDTH=1280
for file in $SRC/*
do
filename=`basename "$file"`
#vignette
$(dirname $0)/ffmpeg -y -i "$file" -qscale:v 2 -q:v 1 "$DEST/${filename%%.*}.jpg"
#x264
$(dirname $0)/ffmpeg -y -i "$file" -an -codec:v libx264 -pix_fmt yuvj420p -profile:v main -preset veryslow -level 3.1 -refs 4 -b:v $BITRATE -bt:v $BITRATE_MAX -qmin 0 -qmax 50 -pass 1 -vf "scale=$WIDTH:trunc($WIDTH/a/2)*2" -f mp4 -threads 0 "/dev/null"
$(dirname $0)/ffmpeg -y -i "$file" -acodec aac -ab 112k -codec:v libx264 -pix_fmt yuvj420p -profile:v main -preset veryslow -level 3.1 -refs 4 -b:v $BITRATE -bt:v $BITRATE_MAX -qmin 0 -qmax 50 -pass 2 -vf "scale=$WIDTH:trunc($WIDTH/a/2)*2" -f mp4 -threads 0 -strict -2 "$DEST/${filename%%.*}.mp4"
#webm
$(dirname $0)/ffmpeg -y -i "$file" -an -codec:v libvpx -quality good -cpu-used 0 -b:v $BITRATE -maxrate $BITRATE_MAX -qmin 0 -qmax 50 -threads 0 -pass 1 -vf "scale=$WIDTH:trunc($WIDTH/a/2)*2" -f webm "/dev/null"
$(dirname $0)/ffmpeg -y -i "$file" -codec:a libvorbis -b:a 112k -codec:v libvpx -quality good -cpu-used 0 -b:v $BITRATE -maxrate $BITRATE_MAX -qmin 0 -qmax 50 -threads 0 -pass 2 -vf "scale=$WIDTH:trunc($WIDTH/a/2)*2" -f webm "$DEST/${filename%%.*}.webm"
done
@leo-cheron
Copy link
Author

You'll need to chmod 0755 video.command.

For a better MP4 audio quality, consider using libfdk_aac codec. For this, you'll need to build ffmpeg with --enable-libfdk_aac.

As a reminder, libfdk_aac > libfaac > Native FFmpeg AAC encoder (aac) > libvo_aacenc.

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