Skip to content

Instantly share code, notes, and snippets.

@alukach
Forked from fuba/mpo2gif
Created July 11, 2012 07:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alukach/3088592 to your computer and use it in GitHub Desktop.
Save alukach/3088592 to your computer and use it in GitHub Desktop.
Convert a .mpo file to an animated gif
#!/bin/sh
# mpo2gif
# convert all .mpo files in a directory to a animation gif.
# Source: https://gist.github.com/878450
# this idea is from http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=16275
# this script requires exiftool and imagemagick.
for file in *.[Mm][Pp][Oo0]; do
rjpg=/tmp/$$_r.jpg
ljpg=/tmp/$$_l.jpg
#Remove spaces from filename
if [[ "$file" != "${file// /_}" ]]
then
echo Converting \'$file\' to \'${file// /_}\'
mv "$file" "${file// /_}"
fi
file=${file// /_}
echo $file
#Change filename extension to .gif
gif=${file%.*}.gif
#Create gif
exiftool -trailer:all= $file -o $rjpg
exiftool $file -mpimage2 -b > $ljpg
convert -loop 0 -delay 15 $ljpg -resize 360000@ -delay 15 $rjpg -resize 360000@ $gif #-delay 10 seems about right, 15 is a bit calmer
rm $rjpg $ljpg
#Make directories
if [[ ! -e originals ]]
then
mkdir originals
fi
if [[ ! -e gifs ]]
then
mkdir gifs
fi
#Move files
mv "$file" originals/
mv "$gif" gifs/
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment