02.12.07

Here is a script for automatically removing the last seconds of several mp3-files

Here is a script to automatically trim the last seconds of several mp3 files in Linux for the following scenario:

  1. In each file close to the end is a 1-2 sec break of silence and then about 7-12 secs of speaking. The silence and the speaking at the end should be removed.
  2. The tags of the original file should be kept.
  3. The shortened files shouldn't overwrite the existing ones but be saved to a new directory.
If the tags weren't necessary and the end of each file would have the exact same length a fine solution would be available here. Actually this was my starting point for the following solution.

For splitting the mp3-files at the desired point mp3splt seems to be the best tool in the Linux world. Unfortunately has two shortcomings:
  1. No batch mode.
  2. The current version 2.1 has problems with keeping the tags of the original file. The second shortcoming is gone with version 2.2_rc1 which is available as installation file for several distros.
Before starting the following shell-script you have to change to the directory where your mp3-files are stored. The modified files will be saved to a sub-folder called Shortened.

OK, here is the script
#!/bin/bash

# Step 1: Split all mp3 files
for X in *.mp3
do
mp3splt -s -p nt=2,rm,min=1 "$X" -o "$X"_@n -d ./Shortened
done

# Step 2: Remove the unneeded ends of the original mp3 files
rm ./Shortened/*_2.mp3
One still unsolved problem is that mp3splt doesn't support a recent ID3 standard. This can result in shortened tag information. Theoretically another problem could happen with a mp3 file which has a longer break of silence in the middle than at the end. In this case you could try to modify the parameters for mp3splt (man mp3splt). However, I tried my script with several pieces of japanese zen-flute music with breaks in the middle and all were trimmed fine.

UPDATE
I have used the script now for several hundred files and it worked with all of them. However, there is one album I once downloaded from Magnatune.com which for whatever reason resists to get circumcised. I played with several of mp3splts parameters - but no success. Hmm, I might decide to buy it... Otherwise I still could use Audacity...

Keine Kommentare: