Monday, June 2, 2008

Clip, cut, split mp3 files using dd

I accidentally discovered a wonderful use of the dd command on ubuntu.

clip mp3 files.

It looks like mp3 format does not have any header or footer. So copying some contiguous bytes from somewhere in the file seems to create another valid mp3 file. WOW!

I have a large mp3 ("041-oru maalai.mp3") file(song) but I feel a part of it sounds good as a ring tone for my mobile phone. I want to skip the initial music and start from the lyrics. And also cut the song and make it smaller.

The below command does it.
dd if="041-oru maalai.mp3" of="041-oru maalai_small.mp3" count=6000 skip=900

count says how many blocks to copy.
skip says how many blocks to skip form the beginning of the file.
see man page for block sizes.

now "041-oru maalai_small.mp3" is what I need.

Given this, you can do a lot of stuff.
Possibilities are limited only by your imagination.
for example, you can clip a few file and cat them to form a single music file... WOW!