Skip to content

Instantly share code, notes, and snippets.

@dylanferguson
Last active October 30, 2019 11:28
Show Gist options
  • Select an option

  • Save dylanferguson/c38536e2b1f9ea4c359012bec4419a76 to your computer and use it in GitHub Desktop.

Select an option

Save dylanferguson/c38536e2b1f9ea4c359012bec4419a76 to your computer and use it in GitHub Desktop.
#!/bin/bash
cmprss() {
name=$(echo "$1" | cut -d'.' -f1)_out
ext=$(echo "$1" | cut -d'.' -f2)
if [[ -f "$1" ]]; then
case "$1" in
*.jpg) convert "$1" -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace sRGB "${name}.jpg";;
*.png) convert "$1" -strip "${name}.png";;
*.gif) ffmpeg -i "$1" -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" "${name}.mp4";;
*.mp4) ffmpeg -an -i "$1" -vcodec h264 -crf 17 "${name}.mp4";;
*) echo "$ext is not supported";;
esac
else
echo "'$1' is not a valid file"
fi
}
cmprss "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment