Skip to content

markus-wa/convert-to-opus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

convert-to-opus

Small command-line tool to help convert your music library from lossless formats (Wave/WAV, FLAC, Ogg/FLAC & AIFF) to Opus.

Build Status Python Version License

Purpose

I mainly wrote this for myself to synchronize the smaller, lossy Opus music files from my PC to mobile. That way I have enough storage to keep everything on my phone. The lossless versions are kept for use on the desktop and for backup into the cloud (Google Drive).

To do this I suggest to do the conversion to a output directory on your PC and synchronize it with something like Resilio.

You can automate the conversion with a cronjob or Windows Task Scheduler.

Requirements

  • opusenc must be installed and in your PATH environment variable.
  • Python 3.6 or higher
  • pip install -r requirements.txt

Usage

to_opus.py

Recursively copies all files in the source directory to the target directory. Files ending with .flac, .wav, .aiff and .ogg are converted and renamed to .opus.

python to_opus.py --source /path/to/source-dir --target /path/to/output-dir

With DB and log:

python convert-to-opus/to_opus.py -s Music -t Opus -db opus-db.json >> convert_to_opus.log

opusenc arguments:

To set the bitrate of the opus encoder to 128 you can pass the following arguments:

python convert-to-opus/to_opus.py -s Music -t Opus -a "'--bitrate'" -a 128 >> convert_to_opus.log

Options:

$ python to_opus.py -h
usage: to_opus.py [-h] [-c CONFIG] -s SOURCE -t TARGET [-thr COUNT] [-del]
                  [-a OPUSENC_ARGS] [-db DATABASE] [-v] [-x EXCLUDE]

Args that start with '--' (eg. -s) can also be set in a config file (specified
via -c). Config file syntax allows: key=value, flag=true, stuff=[a,b,c] (for
details, see syntax at https://goo.gl/R74nmi). If an arg is specified in more
than one place, then commandline values override config file values which
override defaults.

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        config file path
  -s SOURCE, --source SOURCE
                        path to source directory
  -t TARGET, --target TARGET
                        path to target directory
  -thr COUNT, --threads COUNT
                        thread count for parallel processing
  -del, --del-removed   delete converted opus files, for which source files do
                        not exist anymore
  -a OPUSENC_ARGS, --opusenc-args OPUSENC_ARGS
                        arguments to pass to opusenc. (see
                        https://mf4.xiph.org/jenkins/view/opus/job/opus-
                        tools/ws/man/opusenc.html)
  -db DATABASE, --database DATABASE
                        path to the database file
  -v, --verbose         print debug information
  -x EXCLUDE, --exclude EXCLUDE
                        files (Python REGEX) to exclude in the migration. see
                        https://docs.python.org/3/howto/regex.html

Config File

You can specify a path to a config file with --config or -c.

Example config file contents:

source = /path/to/src
target = /path/to/out
verbose = true
exclude = [desktop.ini, Folder.jpg, AlbumArtSmall.jpg]
opusenc-args = ['--cvbr', '--quiet', '--bitrate', 144]

Note the wrapping single quotes ' on opusenc-args with leading --

Check out the ConfigArgParse project for more details on the format.

base_diff.py

Outputs a diff between the source and target directory, ignoring file extensions (only 'base' names). Can be useful to see if there are new, unconverted files.

python base_diff.py /path/to/source-dir /path/to/output-dir

Troubleshooting

You might need to set the environment variable PYTHONIOENCODING=UTF-8 for it to work with files that contain special characters.

About

Convert your music library from Wave/WAV, FLAC, Ogg/FLAC & AIFF to Opus for smaller, more portable files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages