Skip to content

Instantly share code, notes, and snippets.

@zehfernandes
Last active August 28, 2023 14:18
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zehfernandes/4c38ef7ac4c3533e6bd4b306ad8369db to your computer and use it in GitHub Desktop.
Save zehfernandes/4c38ef7ac4c3533e6bd4b306ad8369db to your computer and use it in GitHub Desktop.
Recursively optimize MOV, MP4, WEBp using command line

Optimize assets

.mov to .mp4

Convert and remove the .mov file from all folders in the given directory.

find . -type f -name "*.mov" -exec bash -c 'ffmpeg -i "$0" -vcodec h264 "${0%.*}.mp4" && rm "$0"' "{}" \;

Compress .mp4

Decrease .mp4 file size.

find . -type f -name "*.mp4" -exec bash -c 'ffmpeg -i "$0" -c:v libx264 -preset slow -crf 22 -an "$0_opt.mp4"' "{}" \;

Resize and convert images to .webp

find -E . -regex '.*\.(jpg|png|jpeg)' -exec bash -c 'convert "$0" -quality 85 -define webp:auto-filter=true -define webp:image-hint=photo -define webp:method=6 -resize 1080x1920 "${0%.*}.webp"' "{}" \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment