get-tracks/README.md

90 lines
2.9 KiB
Markdown
Raw Permalink Normal View History

# Get Tracks
`get-tracks.sh` allows you to easily extract music tracks from a file with multiple songs, like a CD-in-a-file.
2021-03-27 21:18:08 +01:00
# Required applications
2022-01-26 13:12:37 +01:00
`get-tracks.sh` is a simple shell script based around `ffmpeg`, using only POSIX tools.
2022-01-26 13:12:37 +01:00
It was tested on both OpenBSD and Linux (Ubuntu, Alpine).
2021-03-27 21:18:08 +01:00
# Usage
Download a CD and the starting time of each track in a file, and you're good to go.
2021-03-27 21:18:08 +01:00
```Bash
get-tracks.sh <audio-file> <time-file>
2021-04-06 16:10:02 +02:00
# Example
get-track.sh doom-eternal.opus doom-eternal.txt
2021-03-27 21:18:08 +01:00
```
*audio-file* can be in any format understood by `ffmpeg`.
2021-03-27 21:18:08 +01:00
The *time-file* must have this format:
2021-03-27 21:18:08 +01:00
```
0:00 intro
2:20 First song
2021-03-27 21:18:08 +01:00
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
2021-03-27 21:18:08 +01:00
# 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.
```Bash
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:
```Bash
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.
2021-03-27 21:18:08 +01:00
# More
You can get some help by running `get-track.sh` without arguments.