Handbrake “devide by zero” error

I experienced some strange problems while trying to encode some video from a DVD with handbrake. Both in Windows XP and OSX the program would crash while attempting to scan the disk, making me unable to even begin the encoding process. No other disk had ever given me this problem and I needed to get the content off to experiment with my video projects for Time Travel is Awesome. After doing a little digging, I found the answer on the handbrake forums. The user van did some serious work to fix the problem and if you are a bigger nerd than I am you can compile some new code from the fix he provides.

The diagnosis of the problem on the handbrake forums:

All these scan aborts are caused by a divide-by-zero in routine hb_fix_aspect(), line 141 of libhb/common.c. It’s being called at the very end of the scan (routine ScanFunc) after all titles have been scanned and the aspect ratio for each title is being updated based on what was discovered about title width, height & aspect ratio while constructing the preview images.

There are two separate problems leading to the aborts:

For program streams, if there’s a title where no previews can be constructed (for example title 3 in bdkennedy1’s crash), title->width, title->height & title->aspect will all be zero when hb_fix_aspect is eventually called on that title & all three of these are multiplicative terms in the denominator so we’ll get a divide by zero. I’m not sure what’s the right fix here but my inclination would be to remove a title from the job’s title list if HB can’t get any previews from it & that would solve the problem.

For transport streams, if the construction of preview 3 fails then title->aspect will be zero which will cause the divide by zero in hb_fix_aspect. I think the best fix here would be to make aspect closer to the way fps is chosen - take the aspect from every preview we get, not just the 3rd, then at the end use the most common AR as the title’s AR.

Finally, hb_fix_aspect should probably validate the terms in the denominator rather than dividing by zero. But I’m not sure what it should do if they’re invalid. (Just use the adjusted job width & height? Delete the title?)

I’ll code up the transport stream AR fix. I can do the other two things at the same time since they’re only a couple of lines each but would like some input from the other devs on what’s the “right” fix.

Link to the fix

Now for those who, like me, hear the word “compile” and start to get a headache there is a much simpler solution. Handbrake 9.1 does not have this problem. However, you are going to have to do a little searching if you are on anything but OSX as that is the only release that is still supported of 9.1. The sourcecode is also supplied so if you are of the more adventurous type give it a shot.

to “Handbrake “devide by zero” error”

  1. Pharmancy » Blog Archive » Handbrake "devide by zero" error Says:

    [...] would crash while attempting to scan the disk, making me unable to even begin the encoding process.read more | digg [...]

Leave a Reply