Skip to content

Instantly share code, notes, and snippets.

@mloberg mloberg/media.sh
Created Jun 17, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.