As someone who runs RPGs across a number of genres, I end up collecting a large amount of ambient audio tracks for use in playlists or soundboards to enhance the mood of my sessions; maybe the party is creeping along through a dangerous cavern, enjoying a peaceful evening under the star-decked heavens, or engaged in a tense battle with corporate security forces. While there is a great deal of audio out there that artists have released for free or are available for purchase from content providers, often it is in a format that isn’t great for either storage or streaming performance. Today, I help you fix that.
For decades, two standard formats of digital audio are WAV and MP3. Appearing first, WAVs are relatively large (roughly 10mb per minute of audio) but are lossless, meaning they contain all of the digital information of the source. MP3s are much, much smaller (roughly 1mb per minute) but are lossy, meaning that the compression comes at the cost of some audio fidelity. While both have their uses—and other formats such as FLAC and AAC entering the mix to complicate things—I find that neither provides what I need for streaming to my gaming parties.
Using the below steps I was able to shrink more than 70gb of music to roughly 3gb—a reduction of almost 96%!—and improve the experience during game time all in one fell swoop. The specific settings you’ll want to use for your own setup vary, but I found that most of the defaults worked well enough for my use-cases.
Note: the following commands were all run on a desktop running Linux, but the commands will be similar on Windows or Mac provided you have the “FFMPEG” program installed. In order to create output in the format I wanted I had to install a later version than my distribution had available, hence the notation of “ffmpeg6” in the commands.
Converting WAV to MP3
First for a single file, then for an entire directory.
poetics@tengu:~$ ffmpeg6 -i [INPUT_FILE] -f mp3 [OUTPUT_FILE].mp3
poetics@tengu:~$ for i in *.wav; do ffmpeg6 -i "$i" -f mp3 "${i%.*}.mp3"; done
Converting MP3 to WEBM
Similarly to the webp format described in my article about mass-converting pictures for online presentation, Google engineers have released the “webm” format for use with streaming audio and video. While MP3 is a great format for most uses, I find that the virtual table-top software I use plays more nicely with webm files, which also have the benefit of being a smaller file size.
poetics@tengu:~$ for i in *.mp3 ; do ffmpeg6 -i "$i" -f webm -b:a 128k -vn -compression_level 5 -c:a libvorbis "${i%.*}.webm"; done
It is also possible to encode webm files recursively, descending into sub-directories and performing the same operation. This is very beneficial if your media is carefully organized and you don’t feel like running the same command once per directory.
poetics@tengu:~$ find . -type f -name '*.mp3' -print0 -exec sh -c '
> name="${1%.*}"
> echo "$name"
> ffmpeg6 -i "$1" -f webm -b:a 128k -vn -compression_level 5 -c:a libvorbis "${name}.webm"
> ' find-sh {} \;
Converting Video to Audio
Though while in a graphical context (like Microsoft Windows) I often make use of the open-source program Audacity for my audio-editing needs, if I’m pulling audio out of multiple video files, it’s often just easier for me to script the work and leave it to the command line, especially if I don’t need to do any per-file fine-tuning. Our old friend FFMPEG once again answers the call and can create audio output from a video source.
Though this example exports to MP3, you can combine it with the flags and options shown above to export directly to webm if that’s your preference. The first line is for a single file, while the second iterates through an entire directory.
poetics@tengu:~$ ffmpeg6 -i sample.avi -q:a 0 -map a sample.mp3
poetics@tengu:~$ for i in *.avi ; do ffmpeg6 -i "$i" -q:a 0 -map a "${i%.*}.mp3"; done
Header image by Jorge Gryntysz from Pixabay, a great source for royalty-free stock images