A POSIX shell script to convert flac files to opus/mp3 with many options
Go to file
yosh e663630d39 make find actually portable 2023-10-11 20:16:19 -04:00
CHANGELOG.md add CHANGELOG, bump version 2023-09-06 22:42:17 -04:00
README.md 1.4.0 updates 2023-04-12 12:41:47 -04:00
flacconv make find actually portable 2023-10-11 20:16:19 -04:00

README.md

flacconv

flacconv is a (hopefully) 100% POSIX and portable1 shell script that recursively converts directories of flac files to opus/mp3.

when invoked with no arguments, it recursively converts the current directory's flac files to opus with a bitrate of 128k, retaining all metadata and not deleting the original flac files

it also has options for you to change the bitrate, use a variable quality for mp3, keep/remove metadata, and parallel processing

dependencies

  • Some implementation of a shell and POSIX Utilities (usually, this is GNU coreutils, which you probably have)
  • mktemp -u (again, probably have this already)
  • flac
  • lame (only if encoding to mp3)
  • opus-tools (only if encoding to opus)
  • opustags (optional, to use the -e option)
  • curl (optional, for checking for updates)

usage

usage: flacconv [-huvVipe3] [-b BITRATE] [-l LEVEL] [-k KEYS] [-r KEYS] [-j THREADS] [--] [DIRECTORY...]
flacconv recursively converts directories of flac files to opus/mp3
DIRECTORY can be specified multiple times. if omitted, the current directory is used
by default, this script outputs opus with variable bitrate 128k
IF ENCODING TO MP3, -k AND -r WILL NOT WORK. the only metadata that will be kept is the following:
  TITLE, ARTIST, ALBUM, ALBUMARTIST, DATE, GENRE, TRACKNUMBER, COMMENT, and the cover picture
(blame id3. just use opus)

 -h           show script help
 -u           check for updates
 -v           verbose output (messy with multithreading)
 -V           very verbose output (VERY messy, use only for debugging and with like, -j 1)
 -i           ignore script-stopping warnings
 -d           delete original flac files after transcoding
 -3           switch output filetype to mp3
 -b <BITRATE> output bitrate in kbits (default 128)
              this value is variable for opus & CBR for mp3
 -l <LEVEL>   mp3 only: use specified mp3 variable quality (0-9). integer only
              OVERRIDES -b
 -k <KEYS>    keep specified flac metadata KEYS in output file
              keys can be checked with metaflac --export-tags-to=- FILE
              option argument is a PIPE-separated list of keys to keep, case-insensitive
              (i.e. -k 'artist|title|albumartist|album|date')
              if both -k and -r are not present, all keys are kept.
 -r <KEYS>    remove specified flac metadata KEYS in output file
              option argument is of the same format as -k
              if set to "ALL" (with capitalization), all keys are removed
 -p           remove embedded picture in output files
 -e           remove the "encoder" tags that automatically gets applied with opusenc
              (requires opustags)
 -j <THREADS> use the specified amount of threads for parallel processing
              if omitted, CPU core count will be used

examples

recursively convert a directory of flacs to opus 128k, removing the picture and ENCODER tags for every file

flacconv -p -e /path/to/dir

recursively convert the current directory to mp3 320k

flacconv -b 320 -3

recursively convert current directory to opus 160k, while removing any COMMENT or DESCRIPTION tags

flacconv -b 160 -r "COMMENT|DESCRIPTION"

recursively convert current directory to mp3 v0, removing all pictures

flacconv -3 -l 0 -p


  1. tested with dash, bash, and yash (set -o posixly-correct) on linux. further testing encouraged ↩︎