Public
Authored by kalopsio

Convert Audio Files Using FFMPEG

Summary

Convert files from SOURCE directory to a specific format/bitrate, and store in DESTINATION directory.

Details

ffmpeg-convert.py is a Python3 script that will attempt to make DESTINATION directory look like SOURCE directory, by mapping the files in SOURCE to paths in DESTINATION. If a file is not found for this mapping under DESTINATION, a file is created, and ffmpeg is invoked to perform conversion to the desired format. If a file is found, the last-modified times are checked to see if the source file was changed (e.g. maybe tags were updated).

This program is threaded, and by default the number of threads utilized is os.cpu_count(), which will resolve to the number of cores on the CPU (on some systems this returns None, in which case the default is 1). You can find the defaults for your system by running ./ffmpeg-convert.py --help, which prints help text as well as defaults for certain arguments.

The current supported command-line flags are:

  • -h, --help
    • Display the help message and exit.
  • -y, --yes
    • Confirm any possible destructive action automatically (only recommended after you are sure the command is correct - helps with automation).
  • -q, --quiet
    • Won't print anything to stdout. Note that one error, the program may still print to stderr.
  • -t, --threads
    • Specify an exact thread count (default is same as the number of cores on your system).
  • -f, --format
    • The format (e.g. 'mp3') to save the output file as.
    • IMPORTANT: I have not thoroughly tested combinations of this, you should do testing if you want to specify a non-default parameter.
  • -b, --bitrate
    • The bitrate (e.g. '128k') to save the output file in.
    • IMPORTANT: I have not thoroughly tested combinations of this, you should do testing if you want to specify a non-default parameter.

Example Usage

Example: ./ffmpeg-convert.py /path/to/music/raw /path/to/dest/

Application will ask for confirmation of paths:

Source     : /path/to/music/raw
Destination: /path/to/dest/
Begin the conversion process? [Y/n] 

Some basic error checking is done, but you should still be careful - for example, mixing up source and destination is bound to cause some problems (overwrite your original raw source files - that'd be bad). Most notably, I have not tested this with anything but the default input parameters for ffmpeg (mp3, 128k).

Edited
ffmpeg-convert.py 11.5 KB
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment