-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmov2gif.sh
More file actions
33 lines (26 loc) · 961 Bytes
/
mov2gif.sh
File metadata and controls
33 lines (26 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
if [ "$1" == "-h" ] || [ "$1" == "help" ] ; then
echo "mov2gif [input] [output] [resolution]
Example: mov2gif in.mov out.gif 640x400"
exit 0
fi
inputFile=$1;
inputFileBasename=$(basename $inputFile .mov);
outputFile=$2;
resolutionInput=$3;
resolution="400x400";
hash ffmpeg 2>/dev/null || { brew update && brew install ffmpeg; }
hash gifsicle 2>/dev/null || { brew update && brew install gifsicle; }
fileInfo=$(ffprobe -v quiet -print_format json -show_streams $inputFile);
width=$( echo $fileInfo | jq -r ".streams[0].width" );
height=$( echo $fileInfo | jq -r ".streams[0].height" );
if [ $resolutionInput ] ; then
resolution=$resolutionInput;
else
resolution="${width}x${height}"
fi
if ! [ $outputFile ] ; then
outputFile="${inputFileBasename}.gif"
fi
echo "converting ${inputFile} to ${outputFile} at $resolution";
ffmpeg -i $inputFile -s $resolution -pix_fmt rgb24 -r 60 -f gif - | gifsicle --optimize=2 --delay=2 > $outputFile