Skip to content

Instantly share code, notes, and snippets.

@Gummibeer
Last active May 10, 2019 11:55
Show Gist options
  • Save Gummibeer/380156b0f3a66e7b0f777ebeb946adbb to your computer and use it in GitHub Desktop.
Save Gummibeer/380156b0f3a66e7b0f777ebeb946adbb to your computer and use it in GitHub Desktop.
ffmpeg snippets
#!/bin/bash
function error_exit {
echo "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
exit "${2:-1}" ## Return a code specified by $2 or 1 by default.
}
if [ $# -eq 0 ]; then
error_exit "No input filepath given"
fi
if [ ! -f "$1" ]; then
error_exit "Input file does not exist"
fi
if [[ $(file --mime-type -b "$1") != image/gif ]]; then
error_exit "Input file is not a gif image"
fi
INPUT=$1
if [ $# -eq 2 ]; then
OUTPUT=$2
else
OUTPUT="$INPUT.mp4"
fi
echo "convert [$INPUT] to [$OUTPUT]"
ffmpeg -f gif -i $INPUT -pix_fmt yuv420p -y $OUTPUT
#!/bin/bash
function error_exit {
echo "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
exit "${2:-1}" ## Return a code specified by $2 or 1 by default.
}
if [ $# -eq 0 ]; then
error_exit "No input filepath given"
fi
if [ ! -f "$1" ]; then
error_exit "Input file does not exist"
fi
if [[ $(file --mime-type -b "$1") != video/mp4 ]]; then
error_exit "Input file is not a mp4 video"
fi
INPUT=$1
LENGTH=10
OUTPUT="part_%03d.mp4"
if [ $# -eq 2 ]; then
LENGTH=$2
fi
if [ $# -eq 3 ]; then
LENGTH=$2
OUTPUT=$3
fi
echo "split [$INPUT] every [$LENGTH]s"
ffmpeg -i $INPUT -map 0 -c copy -f segment -segment_time $LENGTH -reset_timestamps 1 $OUTPUT
#!/bin/bash
function error_exit {
echo "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
exit "${2:-1}" ## Return a code specified by $2 or 1 by default.
}
if [ $# -eq 0 ]; then
error_exit "No input filepath given"
fi
if [ ! -f "$1" ]; then
error_exit "Input file does not exist"
fi
if [[ $(file --mime-type -b "$1") != video/mp4 ]]; then
error_exit "Input file is not a mp4 video"
fi
INPUT=$1
OUTPUT=$1'.out'
if [ $# -eq 2 ]; then
OUTPUT=$2
fi
echo "encode [$INPUT] as theora.OGV"
ffmpeg -i $INPUT -vcodec libtheora -q:v 7 -c:a libvorbis -q:a 4 $OUTPUT'.theora.ogv'
echo "encode [$INPUT] as x264.MP4"
ffmpeg -i $INPUT -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level 3 $OUTPUT'.x264.mp4'
echo "encode [$INPUT] as vp8.WEBM"
ffmpeg -i $INPUT -vcodec libvpx -qmin 0 -qmax 50 -crf 10 -b:v 1M -acodec libvorbis $OUTPUT'.vp8.webm'
echo "encode [$INPUT] as vp9.WEBM"
ffmpeg -i $INPUT -vcodec libvpx-vp9 -b:v 1M -acodec libvorbis $OUTPUT'.vp9.webm'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment