Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: ac3->LAME mp3 clipping in Handbrake (Read 7554 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

ac3->LAME mp3 clipping in Handbrake

I was hoping some of the LAME experts might have some ideas as to some clipping problems with ac3->LAME mp3 transcoded audio that have been noticed in Handbrake for Windows 0.9.3 and now 0.9.4.

Handbrake provides an audio option for LAME when converting to the Matroska media container (MKV) format.  When using the LAME option anytime the mp3 audio clips, there can be very noticeable distortion, popping or crackling.

Here is a one minute sample of the mp3 file generated by Handbrake 0.9.4 with the LAME Stereo 192K options.

The AAC audio option that Handbrake provides does not audibly distort or crackle with the same examples. 

The problem seems to be with the 5.1->2.0 processing that is done on the LAME mp3 encoding in Handbrake.  Using the original AC3 audio of the above link I was able to use Foobar's ac3 component and 5.1->Stereo DSP processing to create a popping/crackling free LAME mp3.

This is the link to the thread on the Handbrake forum about the problem with some more details and Handbrake encoding logs:

http://forum.handbrake.fr/viewtopic.php?f=11&t=11287

Are any LAME coders/experts aware of this problem?  Is it possible someone could work with the Handbrake team to develop a better DSP for the ac3->LAME mp3 conversion?

ac3->LAME mp3 clipping in Handbrake

Reply #1
well, at least they were civil to you. I understand HB is an open-source project done in people's spare time, but the mods over in their forum don't have the best rep for kindness, and from my reading of their forums tend to punitively lock down threads, sometimes just for baiting people into an annoyed response. But they're busy guys and make a nice product in their free time. But seeing their forum only increases my respect for Peter and foobar2000.

I can't answer your question as to the problem. But here's what I know:
* conversion from 5.1 to stereo will sometimes result in an audio stream with major clipping, whether AAC or mp3 audio. I usually encode using FAAC, b/c I've gone the mp4-container route and have a windows machine (note that while mp3 audio is legal in MPEG-4 video, this is not supported by the Apple universe nor by most other sources). So I use foobar2000 to calculate replaygain and peak values, and then use mp3gain/aacgain to lower the volume if necessary to avoid major clipping.
* when encoding to Matroska container with mp3 audio, you can similarly extract the mp3 audio stream and use foobar2000 or mp3gain or whatever to calcluate peak value and adjust the volume level accordingly. then add it back into the video stream with aviMux or some similar program.
* I'm not sure what version of Lame is used by Handbrake at present. when I extract the stream from a matroskta file, it doesn't come with any Lame-tag info. Unfortunately mp3 encoding is only available in CBR and I have no idea what actual Lame settings are being used. Hopefully the devs (or someone else with coding skills) can write code to integrate Lame VBR presets into Handbrake's audio.

I'm curious whether:
* Handbrake is doing anything different with raw (decoded) 5.1 audio before encoding it to mp3 vs. AAC
* you still hear crackling in the mp3 audio stream after you've lowered the volume using foobar2000 or mp3gain as described above. it's possible this is simply a function of mp3 playback vs. AAC playback within a video stream.

Hope this is somewhat helpful.
God kills a kitten every time you encode with CBR 320

ac3->LAME mp3 clipping in Handbrake

Reply #2
I would be curious to know if applying mp3gain to the mp3 file fixes the problem, or if the clipping occurs before encoding to mp3.

ac3->LAME mp3 clipping in Handbrake

Reply #3
given the sorts of peak values that I can get in an audio track from a handbrake-encoded video, I think it does a straight mathematical transcode without filtering it through a wav-ish decode. I've gotten peak values as high as 2.0, for both AAC and mp3 audio streams.
that's why I was also curious about applying mp3 gain taking care of the problem, or not.
God kills a kitten every time you encode with CBR 320

ac3->LAME mp3 clipping in Handbrake

Reply #4
Confirmed that it's pre-encode - applying a -3 dB constant gain in mp3gain does not change the clipping (and visually confirmed in Cool Edit that the decoded waveform is clean, not clipped, and is not hitting full scale).
"Not sure what the question is, but the answer is probably no."

ac3->LAME mp3 clipping in Handbrake

Reply #5
On a hunch, I tried cranking the DRC up to 4, et voila - no more clipping in the MP3 audio (and the overall level was reduced, as expected).

Still doesn't explain why there's overload somewhere in the pre-encode chain with MP3 encoding but not AAC, especially when both formats hit 0 dBFS several times when decoded (I'm using the first 1:20 from "Robin Williams: Live on Broadway", and the MP3 clipping occurs very noticeably on his voice when he's shouting to the audience).
"Not sure what the question is, but the answer is probably no."