diff --git a/gif.sh b/gif.sh index 4f43795..b5c14af 100755 --- a/gif.sh +++ b/gif.sh @@ -1,7 +1,8 @@ #!/bin/sh -# Converts any video to animated gif +# Converts video to high-quality animated GIF using FFmpeg +# Script parameters usage() { echo "Usage:"; echo "\t./gif.sh [] -i input.avi -o output.gif"; @@ -20,16 +21,10 @@ usage() { # Temporary palette file PALETTE="/tmp/palette.png" + # Set start time START=00:00 -## Speed up or slow down -#SETPTS="0.4*PTS" -## Set crop area -#CROP="440:440:135:15" -## Scale if needed -#SCALE="440:-1:flags=lanczos" - # Parse arguments while getopts "i:o:s:d:f:x:" option; do case "${option}" in @@ -43,22 +38,25 @@ while getopts "i:o:s:d:f:x:" option; do esac done -# Abort without required arguments +# TODO: Implement speed up or slow down using SETPTS="0.4*PTS" +# TODO: Define cropping area using CROP="440:440:135:15" + +# Abort if required arguments are missing if [ -z "${INPUT}" ] || [ -z "${OUTPUT}" ]; then usage fi -# Fetch duration from video if not provided +# Fetch duration from video, if not provided if [ -z "${DURATION}" ]; then DURATION=`ffmpeg -i ${INPUT} 2>&1 | grep -oE 'Duration: [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}.[[:digit:]]{2}' | cut -d : -f 4` fi -# Fetch fps from video if not provided +# Fetch fps from video, if not provided if [ -z "${FPS}" ]; then FPS=`ffmpeg -i ${INPUT} 2>&1 | grep -oE '[[:digit:]]{1,4} fps' | cut -d ' ' -f 1` fi -# Fetch width from video if not provided +# Fetch width from video, if not provided if [ -z "${SCALE}" ]; then SCALE=`ffmpeg -i ${INPUT} 2>&1 | grep -oE ', [[:digit:]]{1,4}x[[:digit:]]{1,4}' | cut -d ' ' -f 2 | cut -d 'x' -f 1` fi @@ -73,7 +71,6 @@ echo "fps = ${FPS}" echo "width = ${SCALE}px" # Apply filters -#filters="fps=15,setpts=0.4*PTS,crop=440:440:135:15,scale=440:-1:flags=lanczos" FILTERS="fps=${FPS},scale=${SCALE}:-1:flags=lanczos" # Run two pass conversion @@ -81,3 +78,4 @@ echo "\nProcessing..." ffmpeg -v warning -ss ${START} -t ${DURATION} -i ${INPUT} -vf "$FILTERS,palettegen" -y ${PALETTE} ffmpeg -v warning -ss ${START} -t ${DURATION} -i ${INPUT} -i ${PALETTE} -lavfi "$FILTERS [x]; [x][1:v] paletteuse" -y ${OUTPUT} echo "Done!" +