Created
June 17, 2019 23:34
-
-
Save mloberg/ed11bfe4b631c46e8f4999632e43930c to your computer and use it in GitHub Desktop.
Batch convert media files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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