Slice whole albums into track files.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Karchnu 13dd38ed56 FFOPTS and default behavior doesn't re-encode. 8 months ago
README.md FFOPTS and default behavior doesn't re-encode. 8 months ago
get-tracks.sh FFOPTS and default behavior doesn't re-encode. 8 months ago

README.md

Get Tracks

get-tracks.sh allows you to easily extract music tracks from a file with multiple songs, like a CD-in-a-file.

Required applications

get-tracks.sh is a simple shell script based around ffmpeg, using only POSIX tools.

It was tested on both OpenBSD and Linux (Ubuntu, Alpine).

Usage

Download a CD and the starting time of each track in a file, and you're good to go.

get-tracks.sh <audio-file> <time-file>

# Example
get-track.sh doom-eternal.opus doom-eternal.txt

audio-file can be in any format understood by ffmpeg.

The time-file must have this format:

0:00 intro
2:20 First song
3:18 Awesome song

Environment variables

The behavior of the script can be changed by several environment variables.

  • SIMULATION [empty or not]
    do not invoke ffmpeg

  • FORMAT [mp3,ogg,opus,…]
    see the ffmpeg documentation for the output formats available

  • FFOPTS [any ffmpeg options] (default: '-c:a copy')
    ffmpeg options, can be used to change audio quality
    can be required to change in case input and output file formats differ
    see the ffmpeg documentation for available parameters

  • NONUMBER [empty or 1]
    do not write song numbers

  • SEPARATOR [separator] (default: ' - ')
    separator between number and name
    example with SEPARATOR='_': 01_intro.opus 02_blah.opus…

  • HEADERS [empty or 1]
    print environment parameters (verbosity, simulation, etc.)

  • VERBOSITY [0-3] (default: 1)
    0: no output except errors from ffmpeg
    1: simple indications on the current track being extracted
    2: print actual ffmpeg commands the script currently runs

Different input and output file formats

In case you want to change the file format, let's say from flac to opus, you need to override the default ffmpeg options provided by get-tracks.sh. This is done through the FFOPTS environment variable, which needs to NOT be empty in order to replace the default get-tracks.sh behavior (which is -c:a copy). By default, ffmpeg performs re-encoding by itself.

FORMAT=opus FFOPTS=" " get-tracks.sh cd.flac cd.txt

Warning: sometimes you don't even need to

You may encounter files in some format like webm and you want to convert the output files in opus. But, inside the webm format, you may have opus-encoded audio. In these cases, no re-encoding is necessary, and you can do something like:

FORMAT=opus get-tracks.sh cd.webm cd.txt

You'll have a warning mentionning FFOPTS (based on different formats). But the generated audio files won't have any quality loss. This happens sometimes with the youtube-dl utility.

In case there are actual ffmpeg errors, and you don't have output audio files, then the contained audio hadn't the right format. You'll have to re-encode.

More

You can get some help by running get-track.sh without arguments.