Division by zero crash in iOS when resolution is smaller than the specified output resolution
See original GitHub issueCalling compress on a source video of size 848x480 (as output by Ray-Ban Stories glasses) with a desired output of 1280x720 will yield a division by zero error in the makeVideoBitrate
function. Specifically this line:
var remeasuredBitrate:Int = originalBitrate / (min(originalHeight/height,originalWidth/width))
Since originalHeight
is an int, and height
is a larger int, the result will be 0 (cuz we’re doing integer division), so we’ll end up dividing originalBitrate
by 0 and creating a rift in time and space as we know it.
Actually, the entire function is doing some integer math that might have some issues, like:
let compressFactor:Float = 0.8
// a few lines later
remeasuredBitrate = remeasuredBitrate*Int(compressFactor)
Coercing compressFactor
into an int is essentially a floor function - the decimal gets rounded down to zero. So this will always guarantee that the remeasuredBitrate
is 0.
I’d be pleased to help advise how to fix this up, but as it’s not really documented what this function is supposed to do, it’s a bit tricky to tell what needs to happen solo. Happy to discuss more!
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5
Looks good! I’ll update shortly.
You can find a PR for the issue above. https://github.com/Shobbak/react-native-compressor/pull/73
It’s not exactly on topic but I’ll leave it here if someone finds this issue with the same problem as me.