Skip to content

Instantly share code, notes, and snippets.

@mloberg
Created June 17, 2019 23:34
Show Gist options
  • Save mloberg/ed11bfe4b631c46e8f4999632e43930c to your computer and use it in GitHub Desktop.
Save mloberg/ed11bfe4b631c46e8f4999632e43930c to your computer and use it in GitHub Desktop.
Batch convert media files
#!/usr/bin/env bash
set -e
# convert and optmize jpg files to png & gif
# requires imagemagick (brew install imagemagick)
while read -r file; do
echo ">> resizing/converting $file"
name="${file%.*}"
convert "$file" -resize 1600 -quality 85 -strip "${name}.jpg"
convert "$file" -quality 85 -strip -colors 256 "${name}.png"
convert "$file" -strip "${name}.gif"
done < <(find media -name "*.jpg")
# convert and optmize mp4 to mov
# requires ffmpeg (brew install ffmpeg)
while read -r file; do
echo ">> resizing/converting $file"
name="${file%.*}"
ffmpeg -loglevel warning -y -i "$file" -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 "${name}.optim.mp4" </dev/null
ffmpeg -loglevel warning -y -i "$file" -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 "${name}.mov" </dev/null
done < <(find media -name "*.mp4")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment