Friday, March 14, 2014

Splitting a long mp3 and tricks learned in the process

If you have a video, which contains a long audio that you want to split into multiple mp3 files using their time marker (created by you or found anywhere in a form of list), then you might want to proceed in the following way.

First, you have extract the audio in mp3 format by:
ffmpeg -i input_video_file -f mp3 out.mp3

Now the you have out.mp3 that has to be chopped up into pieces. For this, you need a package called mp3splt. Install that. Now you can chop it up manually if using the time markers. See manpage for details. But we are more interested in a more organised way. Generally, there are CUE files corresponding to audio CDs that can be found on the Internet. If you do not have a cue file, but you have the list of time markers and filename list (or song names) corresponding to them, then you can generate your cue sheet from the following website:
http://cuegenerator.net/

There, you need to insert the Tracklist (song name). Optionally, you can enter in  "songname - perfomer" format if you have the performer names also. It should look like:

songname1
songname2 - singer1
songnaem3 - singer2
songname4
songname5 - singer3


The Timings field has to be filled up in the suggested way (found in the "Help" link next to it). I followed the format: (for example)

Marker 01       00:00:00:00
Marker 02       00:04:12:00
Marker 03       00:09:56:00
.
.
.
Marker 22       01:12:56:00

Here, the time format aa:bb:cc:dd is given by hour:minute:second:milisecond. There are TABs after Marker and marker number, not spaces.

Creating strings following this certain formatting took a lot of time. I copied a list found in the about section of an youtube video in the following format:

time -- song_name -- optional_performer

I copied that into vim and these vim tricks came handy:

Creating visual blocks: Ctrl + v
Aligning text w.r.t. the character --:     :Align --

You need to have the plugin Align installed to use this command. It can be found here: http://www.vim.org/scripts/script.php?script_id=294

The installation instruction is given there. Just download the gz file. Then do vim file.gz. Then you are in vim file browser mode. do :so % and quit.

Insert a string str in front of every line in a visual block:

1. Select the visual block
2. Press I. It will take you to the beginning of the first string of the first line of the visual block.
3. Enter the string str.
4. Press Esc

Similarly, making any change in every line of a visual block involves similar steps.

~ When you have the strings organised in the desired way, copy them to the website to generate the cue file.

Once you enter the information, you can download the .cue file. Let's call it list.cue.

Now, we want to create a directory named inside which all the files will be stored with the following filenames:
-.mp3

I'm not interested in performers since that might increase the length of the filename.

So, we issue the following command in terminal:

mp3splt -c list.cue -o @b/@N-@t out.mp3

Here, -o sets the output format.
@b = Title of the album (director named @b will be created automatically)
@N = Track Number
@t = Song title

More formatting options are in man mp3splt.

No comments: