Search code examples
pythonmp3aacavconv

Proper params to convert mp3 to aac using avconv


I am writing a little python script that converts mp3 files to aac. I am doing so by using avconv and I am wondering if I am doing it right. Currently my command looks like this:

avconv -i input.mp3 -ab 80k output.aac

This brings me to my first question: I am using -ab 80k as this works with my test-files. On some files I can go higher and use 100k. But I'd prefer to have that always on the highest settings. Is there a way to say that?

The other question: I am using it in a python script. Currently I call it as a subprocess. What I'd prefer is not to do so, as this forces me to write a file to disc and then load it again when everything is done. Is there a way to only do it in memory? I am returning the file afterwards using web.py and don't need or want it on my disc? So would be cool not having to use temporary files at all.

Thanks for any tipps and tricks :)


Solution

  • I don't have the -ab option but if it is equivalent to -ar (specify the sample rate), I should point out that your ears won't be able to tell the difference between 80k and anything higher.
    On the subject of temporary files, have you considered using /tmp or a specific tmpfs file system created for the purpose.

    Edit: In response to comment about tempfiles, yes you still use them but create them in /tmp or a tmpfs file system that you have created for the job. It should get cleared on reboot but I would expect you to delete the file once you have passed it on anyway.
    The other point about lossless aac I may come back to you later.

    Edit 2: As I suspected the aac format is described as the logical successor to mp3 and I strongly suspect, you or someone else may know different, that as mp3 is what is termed as lossy, compressed i.e. bits ( no pun intended) missing, your desire to convert losslessly is doomed, in so much as the source is already lossy.
    Of course, being no expert in the matter, I stand to be corrected.

    Edit 3: your comment about too many frames leads me to believe that you are conflating the two avconv options -ar and -b
    The -b is used for video and specifies the output bit rate for video and audio. The way you are using it, I suspect that it is attempting to apply the same bit rate to audio and video but there is a limit on the audio stream.
    You would have to use -b:v to tell avconv to set the video bit rate and leave the audio rate alone.
    I suggest that you lose the -ab option and use -ar instead as that is audio only.