Skip to content

Instantly share code, notes, and snippets.

@stranger-danger-zamu
Created November 7, 2021 19:33
Show Gist options
  • Save stranger-danger-zamu/faa9cc9e6672dac0f5a065168ec7c1a7 to your computer and use it in GitHub Desktop.
Save stranger-danger-zamu/faa9cc9e6672dac0f5a065168ec7c1a7 to your computer and use it in GitHub Desktop.
Parallel convert FLAC files to MP3 with `fd` or `find`
#!/usr/bin/env bash
ffmepg -i "${1}" -ab 320k -map_metadata 0 -id3v2_version 3 "${2}"
kid3-cli -c 'fromtag "%{artist} - %{album} - %{track}. %{title}" 2' "${2}"

What this?

This is a simple script to utilize along with something like find or fd to make converting music files much easier. It finds all FLAC files in a subdirectory and then converts them to mp3. Then using id3v2 tags renames the files based on them.

Setup?

Simply:

cp convert_flac_for_usb.sh ~/.local/bin/convert_flac_for_usb
chmod +x ~/.local/bin/convert_flac_for_usb

NB: Feel free to swap out ~/.local/bin/ to any directory in your $PATH

How do?

Ah, simply:

convert_flac_to_usb $INPUT_FILE $OUTPUT_FILE

But this isn't just for one off files, but for batch, parallel conversions!

fd 'flac' $MUSIC_DIR -t f -j "${THREAD_COUNT}" -x convert_flac_for_usb {} "$OUTPUT_DIR"/{/.}.mp3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment