Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions dataloader/hevc_feature_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _parse_fraction(frac: Optional[str]) -> float:
a = float(a.strip()); b = float(b.strip())
return 0.0 if b == 0 else a / b
return float(frac)
except Exception:
except (ValueError, TypeError, AttributeError):
return 0.0


Expand Down Expand Up @@ -188,10 +188,10 @@ def _get(d, *keys):
continue
try:
packets_pts.append(int(v))
except Exception:
except (ValueError, TypeError):
try:
packets_pts.append(int(float(v)))
except Exception:
except (ValueError, TypeError):
pass
if not packets_pts:
packets_pts = list(range(len(packets_list)))
Expand All @@ -208,7 +208,7 @@ def _get(d, *keys):
nbf = _get(viddict, "nb_frames", "@nb_frames")
try:
self.nb_frames = int(nbf)
except Exception:
except (ValueError, TypeError):
self.nb_frames = len(packets_list) if packets_list else 0

self.width = int(_get(viddict, "width", "@width"))
Expand Down Expand Up @@ -271,7 +271,7 @@ def close(self):
self._proc = None
if hasattr(self, 'DEVNULL') and self.DEVNULL:
try: self.DEVNULL.close()
except Exception: pass
except OSError: pass
self.DEVNULL = None

def _terminate(self, timeout=1.0):
Expand Down Expand Up @@ -386,11 +386,11 @@ def _is_i_like(self, frame_type: int, ref_off_L0: np.ndarray, ref_off_L1: np.nda
_itypes_env = os.environ.get('UMT_HEVC_I_TYPES', '0')
try:
_itypes = {int(x) for x in _itypes_env.replace(' ', '').split(',') if x != ''}
except Exception:
except ValueError:
_itypes = {0}
if int(frame_type) in _itypes:
return True
except Exception:
except (ValueError, TypeError):
pass
if STRICT_I:
# In strict mode, do NOT use the fallback; rely only on frame_type flag.
Expand Down Expand Up @@ -494,7 +494,7 @@ def _readFrame(self):
# More explicit labels: common mapping 0=IDR, 1=CRA(IRAP), 2=P, 3=B
_ft_map = {0: "IDR", 1: "CRA", 2: "P", 3: "B"}
ft_str = _ft_map.get(_ft, str(_ft))
except Exception:
except (ValueError, TypeError):
ft_str = "NA"

# optional I cache key (Y-only) to help upper layers deduplicate compute
Expand All @@ -512,7 +512,7 @@ def _readFrame(self):
else:
_y_small = cv2.resize(cv2.cvtColor(rgb, cv2.COLOR_BGR2YUV)[:,:,0], (8, 8), interpolation=cv2.INTER_AREA)
_frame_hash = hashlib.md5(_y_small.tobytes()).hexdigest()
except Exception:
except (cv2.error, ValueError, TypeError):
_frame_hash = None

self._lastmeta = {
Expand Down Expand Up @@ -711,7 +711,7 @@ def read_first_gop_tensors(self, gop_size=12, need_i_rgb=True, mv_level='L0',
try:
_mvmax = float(max(np.abs(mv_x_L0).max(), np.abs(mv_y_L0).max()))
_refmax = int(np.max(ref_off_L0))
except Exception:
except (ValueError, TypeError):
_mvmax, _refmax = -1.0, -1
_ft_id = meta.get('frame_type')
_ft_str = meta.get('frame_type_str')
Expand Down
43 changes: 7 additions & 36 deletions dataloader/hevc_feature_decoder_mv.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,35 +94,6 @@ def _split_yuv420_planes(buf: bytes, H: int, W: int, layout: str):
raise ValueError(layout)


# ---------------- YUV plane parsers ----------------
def _split_yuv420_planes(buf: bytes, H: int, W: int, layout: str):
"""Return Y (H,W), U (H/2,W/2), V (H/2,W/2) for layout in {i420,yv12,nv12,nv21}."""
nY = H*W
nUV = (H//2)*(W//2)
arr = np.frombuffer(buf, dtype=np.uint8)
if layout in ("i420","yv12"):
Y = arr[:nY].reshape(H, W)
UV = arr[nY:]
# planar U and V (each nUV)
U_planar, V_planar = (UV[:nUV], UV[nUV:]) if layout=="i420" else (UV[nUV:], UV[:nUV])
U = U_planar.reshape(H//2, W//2)
V = V_planar.reshape(H//2, W//2)
return Y, U, V
elif layout in ("nv12","nv21"):
Y = arr[:nY].reshape(H, W)
UVint = arr[nY:].reshape(H//2, W) # interleaved per row: UVUV or VUVU
U = np.empty((H//2, W//2), dtype=np.uint8)
V = np.empty((H//2, W//2), dtype=np.uint8)
if layout == "nv12": # UVUV...
U[:] = UVint[:, 0::2]
V[:] = UVint[:, 1::2]
else: # nv21: VUVU...
V[:] = UVint[:, 0::2]
U[:] = UVint[:, 1::2]
return Y, U, V
else:
raise ValueError(layout)

# ---------------- manual YUV->BGR with matrix/range ----------------
def _upsample_uv(U, V, H, W):
# nearest-neighbor 2x upsample
Expand Down Expand Up @@ -210,7 +181,7 @@ def _auto_pick_color(yuv_buf: bytes, H: int, W: int):
best_mse = mse
best = (lay, mat, rng)
picked_bgr = bgr
except Exception:
except (ValueError, IndexError):
continue
if best is None:
# 回退
Expand Down Expand Up @@ -255,9 +226,9 @@ def __init__(self, video, parallel=1, hevc_bin=None):
def close(self):
if self.proc and self.proc.poll() is None:
try: self.proc.stdin.close()
except Exception: pass
except OSError: pass
try: self.proc.stdout.close()
except Exception: pass
except OSError: pass
self.proc.terminate()
self.proc = None

Expand Down Expand Up @@ -442,7 +413,7 @@ def _parse_fraction(frac: Optional[str]) -> float:
a = float(a.strip()); b = float(b.strip())
return 0.0 if b == 0 else a / b
return float(frac)
except Exception:
except (ValueError, TypeError, AttributeError):
return 0.0


Expand Down Expand Up @@ -485,10 +456,10 @@ def _get(d, *keys):
continue
try:
packets_pts.append(int(v))
except Exception:
except (ValueError, TypeError):
try:
packets_pts.append(int(float(v)))
except Exception:
except (ValueError, TypeError):
pass
if not packets_pts:
packets_pts = list(range(len(packets_list)))
Expand All @@ -505,7 +476,7 @@ def _get(d, *keys):
nbf = _get(viddict, "nb_frames", "@nb_frames")
try:
self.nb_frames = int(nbf)
except Exception:
except (ValueError, TypeError):
self.nb_frames = len(packets_list) if packets_list else 0

self.width = int(_get(viddict, "width", "@width"))
Expand Down