After failing to remove the songs’s silences only from the start or the end with FFmpeg, I ended up using an open-source tool (mp3splt-gtk) to achieve this. It did not have a particular good default settings for this purpose but it ended up doing a perfect job.
In case you don’t know I have an ongoing project of restoring an old radio which has kept me busy (more or less) for the last 5 years. In fact, this is the second post related to this topic. The first post is about organising your music library. In that case the organising was required so that each song has the correct idiom, decade, and genre in order to create different radio stations (playlists).
The radio is fully functional now, and it does exactly what I wanted. Mimic a radio. I will try to be brief because this post is not about the radio. But basically, I have several playlists that are “radio stations”. That playlist should reproduce a song at a precise moment based on the system’s internal clock. That is at 12:00:00 you might be hearing Bon Jovi - Bed of Roses at time 45 seconds, and if you return to the station at 12:01:10 then you will be listening to the same song but this time in the 115-second position. When a song ends, it just skips to the next one.
You can probably see where this is going. If a song has an ending silence of up to 25 seconds, and the next song has a silence at the start of 5 seconds. This appears as 30 seconds of silence which is extremely awkward or you could tune in right in the silence and think it broke. The easiest solution is to trim these silences. If you are curious, herein-below there is a video of the radio working.
Initially, this post was going to be about FFmpeg and how I used it for this purpose, but I couldn’t work out the specific command to remove a silence only if starts at time 0, and only if it finishes at time “song’s end”. So I had to keep investigating, I investigated Audacity, MPsplit and mp3splt-gtk before deciding to proceed with the latest one.
FFmpeg is a great tool but you need to be an expert to control it properly, which I am not, for instance here is the page for the silence removal command. I tried to work out a command that would delete a silence if and only if the silence started at time 0 or the silence finished at time “song’s end”. But I failed, here is the Powershell + FFmpeg script that as it is, will delete any silence that encounters in a song regardless of its position.
FFmpeg’s main caveat is that it deals with one and only one file at a time. So you need to use another language (in my case Powershell) to control everything else.
FFmpeg is destructive, it will uncompress and recompress, but unless Audacity, you can configure the bit-rate of the output.
It keeps a copy of all ID tags in the new mp3. But only ID3v2, all the ID3v1 and APE are gone.
It messes up with song duration, sometimes making it appear to be longer than it is.1
The script is based on this FFmpeg command:
ffmpeg -i "input.mp3" -af "silenceremove=start_periods=1:start_duration=0.046:start_threshold=-50dB,silenceremove=stop_periods=-1:stop_duration=0.046:stop_threshold=-46dB" -b:a 320k -write_xing 0 -y "output_trimmed.mp3"
I am surprised with the quality of Audacity has gotten in the latest versions. However, whilst doing a very good job at finding silences and trimming them. It has a few caveats:
Audacity does not have a batch tool per se. It uses a macro system which does not allow you to control which songs will be modified or not. It will modify every single song in the folder.
Audacity does not make it easy to script around itself. You are limited to the macros it has and no control structures such as if-else.
It is not able to deal with folder structures, it will process all mp3s in a folder, and then you must reorganise as you please.
It exports at whatever bit-rate you did for your last export. That means that if you use 320kbps, it will export every song of the folder at that bit-rate, even songs with smaller bit-rate, increasing their size massively. And making now believe that the song is a higher bit-rate than actually is.2
It is destructive, it will read the song, get the waveform, and then export it. Meaning that some quality will be lost in the process.
MPtrim is a paid software that does an excellent job at trimming one and only one song, with plenty of options and free to use.
You need the PRO version in order to batch songs or folders.
The PRO version costs 70 American dollars, and it is only for a yearly license!3
If I had less than 20 songs, I would go for this, but with the amount ranking over 300, I shall pass.
Mp3splt is a great tool to deal with silences. It has not been updated since 2014, so do not expect any new features. The software is focused on splitting recordings of a whole CD/Vinyl/Cassette, into different files. However, also is able to deal with silences only at the start and end of a song.
It uses a not destructive4 method.
It trims the song perfectly.
You need some configuration tweaking that is not very straightforward if you want to keep the original ID tags, and mimic folder structure.
Go to the Mp3splt website and make sure you donwload the mp3splt-gtk 0.9.2 version. Uncompress the zip and then locate the mp3splt-gtk.exe and run it. You need to use the second tab, the one called “Batch & Automatic split”, the first one is kind of useless for our purpose as it is to remove silence manually one by one.
From the options below, make sure to select the one that says Trim using silence detection, and set up the threshold level you want (Anything between -50dB and -42dB is fine). The program has some questionable default values, but if you click on the Batch split button on the top right corner it should kind of work.
Lets gonna configure the application to keep the original ID tags and replicate the folder structure. Go to Application > Preferences.
Split tab:
Make sure to use a custom directory and point it to an empty folder
On Split options, make sure that only the option to Create directories from filenames is selected. However, this option is not enough by itself to do what it claims it does.
Tags tab:
on Tag version; make sure that Same tags version as the input file is selected
on Split files tags; make sure that Original file tags is selected
Output format:
Select Custom format and write, this step is necessary to mimic the folder structure:
Windows: @d\@f
Linux/Mac: @d/@f
If you want to have the song with a suffix, like input_trim.mp3, add trim at the end like @d\@f__trim
Now you can close the preferences, press the Batch split button, go for a coffee and let the software do its job.
This took me a lot of searching and trial and error and it seems that the flag -write_xing 0
must be added right before the output filename to solve it.↩︎
I could have dealt with the other problems, but this one was the real deal-breaker.↩︎
I do not support any subscription business. So game over.↩︎
I tried to test this by inverting one of the trimmed songs, aligning it, and then combining the tracks. If they carbon-copies the results should be silent, but it wasn’t. However, I did not spend much time aligning as it is a tedious task.↩︎