Skip to content

Commit

Permalink
fix: upscale and division by zero issue (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
murat-mehmet authored Dec 15, 2023
1 parent e60f7b7 commit d4963b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ object AutoVideoCompression {
val actualWidth = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)!!.toInt()
val bitrate = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE)!!.toInt()
val scale = if (actualWidth > actualHeight) maxSize / actualWidth else maxSize / actualHeight
val resultWidth = Math.round(actualWidth * scale / 2) * 2
val resultHeight = Math.round(actualHeight * scale / 2) * 2
val resultWidth = Math.round(actualWidth * Math.min(scale, 1f) / 2) * 2
val resultHeight = Math.round(actualHeight * Math.min(scale, 1f) / 2) * 2
val videoBitRate = makeVideoBitrate(
actualHeight, actualWidth,
bitrate,
Expand Down
6 changes: 3 additions & 3 deletions ios/Video/VideoMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class VideoCompressor {
let minValue:Float=min(Float(originalHeight)/Float(height),Float(originalWidth)/Float(width))
var remeasuredBitrate:Int = Int(Float(originalBitrate) / minValue)
remeasuredBitrate = Int(Float(remeasuredBitrate)*compressFactor)
let minBitrate:Int = self.getVideoBitrateWithFactor(f: minCompressFactor) / (1280 * 720 / (width * height))
let minBitrate:Int = Int(Float(self.getVideoBitrateWithFactor(f: minCompressFactor)) / (1280 * 720 / Float(width * height)))
if (originalBitrate < minBitrate) {
return remeasuredBitrate;
}
Expand Down Expand Up @@ -186,8 +186,8 @@ class VideoCompressor {

let bitrate=Float(abs(track.estimatedDataRate));
let scale:Float = actualWidth > actualHeight ? (Float(maxSize) / actualWidth) : (Float(maxSize) / actualHeight);
let resultWidth:Float = round(actualWidth * scale / 2) * 2;
let resultHeight:Float = round(actualHeight * scale / 2) * 2;
let resultWidth:Float = round(actualWidth * min(scale, 1) / 2) * 2;
let resultHeight:Float = round(actualHeight * min(scale, 1) / 2) * 2;

let videoBitRate:Int = self.makeVideoBitrate(
originalHeight: Int(actualHeight), originalWidth: Int(actualWidth),
Expand Down

0 comments on commit d4963b5

Please sign in to comment.