Home

Advertisement

Thu, Nov. 9th, 2006, 05:19 pm
Trimming mp3s

Does anybody know of a relatively simple way to trim a few seconds off the end of a bunch of mp3s? Even a Windows program under Wine would be okay (I tried mp3trim but to get the batch mode you have to buy the pro version) although a Linux-native solution would obviously be better. I'm pretty sure I could knock up a shell script to convert to wav, trim, then convert back to mp3, but ideally I want a solution which doesn't involve any de/re-compression.

Any thoughts?


Update: [info]wackydave's suggestion was the winner. mp3splt and mp3info combined in a little script work perfectly (mp3splt doesn't seem able to preserve the id3 tags, but that's a minor issue).

#!/bin/bash

for X in *.mp3
do
	total_secs=`mp3info -p "%02S" "$X"`
	secs_minus_eight=$(($total_secs - 8))
	mins=$(($secs_minus_eight / 60))
	rounded_secs=$(($mins * 60))
	leftover_secs=$(($secs_minus_eight - $rounded_secs))
	mp3splt "$X" 0.0 $mins.$leftover_secs -o "$X" -d ./Shortened/
done


Note: this is the third shell script I've ever written and I don't claim to know what I'm doing (it took a long time to get it working: learning what a backtick does was a major step forward...). It's probably ugly and inefficient, but it does the job (trimming eight seconds off the end of every mp3 in the folder) quickly and seemingly with no loss of quality, so I'm happy.

Thu, Nov. 9th, 2006 10:48 pm (UTC)
[info]unsane1

I don't know of any batch tool, but Audacity lets you trim and edit mp3s.

Fri, Nov. 10th, 2006 07:39 pm (UTC)
[info]weemadharold

Yeah, I use Audacity a lot, it's a great tool. It doesn't have a batch mode though, and it doesn't have many command-line options so I can't use it in a script. I cross-posted this to an Ubuntu community and someone there suggested mp3splt. I've only had a quick look so far, but it seems like it can do what I want.

Sun, Dec. 2nd, 2007 11:13 am (UTC)
(Anonymous): Nice script

Nice script. I used it as an inspiration for writing a similar one, but for files where the end of each file has a different length. I also found a way to keep the mp3 tags. Have a look here:
http://qaywsxedcrfv.blogspot.com/2007/12/here-is-script-for-automatically.html

Advertisement