Spaces:
Paused
Paused
fixed aspect ratio bug
Browse files- perception_roi_server.py +22 -2
perception_roi_server.py
CHANGED
|
@@ -215,6 +215,22 @@ def _ensure_even(v: int, min_v: int = 64) -> int:
|
|
| 215 |
return v - (v % 2)
|
| 216 |
|
| 217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
def _compute_target_params(w: int, h: int, fps: float, bandwidth_kbps: int, target_fps: int, target_w: int, target_h: int, scale: float):
|
| 219 |
fps = max(1.0, float(fps or 1.0))
|
| 220 |
budget = max(100, int(bandwidth_kbps or 1500))
|
|
@@ -222,8 +238,12 @@ def _compute_target_params(w: int, h: int, fps: float, bandwidth_kbps: int, targ
|
|
| 222 |
base_kbps_orig = base_kbps_720p30 * (float(w) * float(h) * fps) / (1280.0 * 720.0 * 30.0)
|
| 223 |
if not math.isfinite(base_kbps_orig) or base_kbps_orig <= 0:
|
| 224 |
base_kbps_orig = base_kbps_720p30
|
| 225 |
-
if target_w
|
| 226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
else:
|
| 228 |
scale = float(scale or 1.0)
|
| 229 |
if scale < 0.1:
|
|
|
|
| 215 |
return v - (v % 2)
|
| 216 |
|
| 217 |
|
| 218 |
+
def _fit_aspect(w: int, h: int, target_w: int, target_h: int) -> Optional[List[int]]:
|
| 219 |
+
if w <= 0 or h <= 0:
|
| 220 |
+
return None
|
| 221 |
+
if target_w and target_h:
|
| 222 |
+
scale = min(float(target_w) / float(w), float(target_h) / float(h))
|
| 223 |
+
elif target_w:
|
| 224 |
+
scale = float(target_w) / float(w)
|
| 225 |
+
elif target_h:
|
| 226 |
+
scale = float(target_h) / float(h)
|
| 227 |
+
else:
|
| 228 |
+
return None
|
| 229 |
+
if not math.isfinite(scale) or scale <= 0:
|
| 230 |
+
return None
|
| 231 |
+
return [int(w * scale), int(h * scale)]
|
| 232 |
+
|
| 233 |
+
|
| 234 |
def _compute_target_params(w: int, h: int, fps: float, bandwidth_kbps: int, target_fps: int, target_w: int, target_h: int, scale: float):
|
| 235 |
fps = max(1.0, float(fps or 1.0))
|
| 236 |
budget = max(100, int(bandwidth_kbps or 1500))
|
|
|
|
| 238 |
base_kbps_orig = base_kbps_720p30 * (float(w) * float(h) * fps) / (1280.0 * 720.0 * 30.0)
|
| 239 |
if not math.isfinite(base_kbps_orig) or base_kbps_orig <= 0:
|
| 240 |
base_kbps_orig = base_kbps_720p30
|
| 241 |
+
if target_w or target_h:
|
| 242 |
+
fitted = _fit_aspect(w, h, int(target_w or 0), int(target_h or 0))
|
| 243 |
+
if fitted:
|
| 244 |
+
tw, th = fitted
|
| 245 |
+
else:
|
| 246 |
+
tw, th = int(target_w or w), int(target_h or h)
|
| 247 |
else:
|
| 248 |
scale = float(scale or 1.0)
|
| 249 |
if scale < 0.1:
|