While this job is probably best-suited for a tool like Audacity (where you would just select a portion of what you want deleted with a cursor, and then go to Edit -> Cut to get it deleted), you may fail to impress that hot girl at the coffeeplace you go to in doing it with a cowardly GUI tool. That's right. Mitchell loves a man who knows his way around bash.
Suppose that you've an mp3 file, all of it is beautiful, except some arbitrary portion in the middle. You just don't like it. Mitchell doesn't like it either. Therefore, it has to be dealt with.
Let's work on a file foo.mp3, which is 6 minutes and 16 seconds long. We want to do away with the portion starting at 1:22 and ending at 1:47.
Step 1. We figure out how big the file is
Code:
$ ls -l foo.mp3
-rwxrwxrwx 1 kh kh 6022715 2010-05-04 23:55 foo.mp3
Step 2. We recall that the file was 6 minutes and 16 seconds long (that's 376 seconds in total, 6*60+16 is 376), so now we figure out how big each second of this file will be. We will impress Mitchell at this stage by demonstrating our perl-fu:
Code:
$ perl -e "print 6022715/376"
16017.8590425532
Alright. There's our answer. There are 16017 bytes to every second of this file.
Step 3. We will now figure out where the bad portion of the file is -- recall, it was from 1:22 (that's 82 seconds) to 1:47 (that's 107 seconds). Let's get to it, and show some more Perl-muscle.
Code:
$ perl -e "print 16017*82"
1313394
$ perl -e "print 16017*107"
1713819
Step 4. Now we'll slice it with the split tool. We'll slice it by 1313394 bytes each, as that is where the dirty portion of the mp3 files begins.
Code:
$ split -d -b 1313394 foo.mp3
As I have no doubt you immediately opened up split's man page to check what the -d -b arguments do, I have no reason to tell you what they are.
But nah, I'll tell you anyway, just because I love you so much. The -b argument lets you specify what size you want the splits to be, we followed that by 1313395. The -d argument will make the splits use numeric suffixes instead of alphabetic ones -- as you can imagine, numeric suffixes are easier to manage and use with other tools should the need arise. Anyway, here's an output of ls -l:
Code:
$ ls -l
total 11804
-rwxrwxrwx 1 kh kh 6022715 2010-05-04 23:55 foo.mp3
-rw-r--r-- 1 kh kh 1313394 2010-05-07 01:09 x00
-rw-r--r-- 1 kh kh 1313394 2010-05-07 01:09 x01
-rw-r--r-- 1 kh kh 1313394 2010-05-07 01:09 x02
-rw-r--r-- 1 kh kh 1313394 2010-05-07 01:09 x03
-rw-r--r-- 1 kh kh 769139 2010-05-07 01:09 x04
Step 5. We'll rename the very first part (x00) to part1.mp3, and remove the rest.
Code:
$ mv x00 part1.mp3
$ rm x*
Step 6. We'll now split foo.mp3 once more, but we'll make each split 1713819 bytes long -- recall, this is where the dirty portion ends.
Code:
$ split -d -b 1713819 foo.mp3
Observe that there are fewers amounts of split, because we're splitting the same file by larger sum sizes.
Step 7. We now will delete the first portion -- x00, which is the everything up until where the dirty part ends:
Step 8. Finally, we merge the first part (i.e. part1.mp3) with the rest of the newly created splits (except x00, which we just sent to hell):
Code:
$ cat part1.mp3 x* > for_mitchell.mp3
Step 9. Uh huh. You tiger. Well, what are you waiting for? Try it out!
Code:
$ mplayer for_mitchell.mp3
Mmmhmm. That's what I'm talkin' 'bout.
Step 10. Now go collect your sex.