-gc6bw
Last Updated: January 06, 2019
·
346
· skyzyx

MP4 → Animated WebP

Assuming you're adding this to a Makefile (which requires all $ to be $$), and the MP4 files are in a directory called ./remote-assets, you can use the following to produce an animated WebP version of the MP4 file.

find ./remote-assets -type f -name '*.mp4' | xargs -P $$(nproc) -I {} bash -c 'ffmpeg -i $$1 -color_primaries film -quality 80 -loop 0 -hide_banner "$${1%.mp4}.webp"' _ {} \;

This will:

  1. Find all .mp4 files in the directory (recursively)
  2. Pass the list of matches to xargs
  3. Determine the number of CPU cores you have
  4. Spin up that many threads in order to parallelize the work
  5. Use Bash to call ffmpeg
  6. Output the file with the same name, but with a .webp file extension