Saturday, March 9, 2013

[solved] incorrect duration converting wav's to mp3's

problem

Suppose one creates a screencast with a 3:15 duration. Afterwards, let's say we break the soundtrack off into a WAV file; it's easy to tweak sound levels and so on in the raw WAV format. But once completing our tweaks, perhaps we want to convert the WAV to a space-saving MP3. In this case, imagine we don't want a high quality variable bit rate (VBR) MP3, but are interested in, for example, a 192k continuous bitrate.

but the duration is incorrect

We do our conversion, say with:
$ ffmpeg -i smite.wav -ab 192k -vol 300 smite.mp3

Now we run a test of the MP3 file in some player, perhaps Audacious. Our soundtrack sounds excellent, but its duration, which we know from our original file is 3:15, appears in Audacious and other players as 28:15. We're unable to use the slider to move around in the timeline, because the file's timeline is inaccurate. Incorrect duration stamps in media files are a problem.

the reason

Ffmpeg and avconv use the bitrate setting as part of their duration calculations. Both ffmpeg and avconv will calculate the duration correctly if we don't specify a bitrate. Unfortunately, if we don't specify the bitrate, ffmpeg and avconv will use their native bitrates, which both happen to be the low quality of 128Kb. So how do we achieve the 192K bitrate we desire in the example above and still obtain a correct duration stamp on the resulting MP3?

solution



Install lame. For example to achieve the 192Kb, with a correct time stamp, and with the conversion volume setting we desire, we could use:
$ lame --scale 1.2 -b 192 smite.wav
I can change the bitrate to whatever I want, even into a VBR, and the resulting duration stamp is accurate. With respect to the volume, if I wanted to double it, the scale I would select would be "2", and so on. Finally, the output file name, in this case smite.mp3, will be created automatically using the input WAV file's name. Alternatively, one can force an output name. Now, when we re-render our audio back to our video, they will be properly synced, since the timestamps are correct.

video note

When converting the video of a screencast, the only way I've found to get the proper duration is to be sure to use the switch:
-target ntsc-dvd

No comments: