zhicao/dreamzero main
PYTHON
Verdict: BENIGN
Local reference
Suspicious dependency
Inferred
| 1 |
import json |
|
| 2 |
import subprocess |
Imports Python's subprocess module |
| 3 |
|
|
| 4 |
import av |
|
| 5 |
import cv2 |
Imports a Python raster imaging library |
| 6 |
import numpy as np |
Imports the NumPy array library |
| 7 |
import torchvision |
|
| 8 |
|
|
| 9 |
# Import decord with graceful fallback |
|
| 10 |
try: |
|
| 11 |
import decord |
|
| 12 |
|
|
| 13 |
DECORD_AVAILABLE = True |
|
| 14 |
except ImportError: |
|
| 15 |
DECORD_AVAILABLE = False |
|
| 16 |
|
|
| 17 |
try: |
|
| 18 |
import torchcodec |
|
| 19 |
|
|
| 20 |
TORCHCODEC_AVAILABLE = True |
|
| 21 |
exce… |
|
| 36:6 |
… "json", |
|
| 37 |
video_path, |
|
| 38 |
] |
|
| 39 |
|
|
| 40 |
try: |
|
| 41 |
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8") |
|
| 42 |
probe_data = json.loads(output) |
|
| 43 |
stream = probe_data["streams"][0] |
|
| 44 |
|
|
| 45 |
# Parse frame rate (comes as fraction like "15/1") |
|
| 46 |
if "/" in… |
|
| 66:5 |
… raise ValueError(f"Failed to get video info for {video_path}: {e}") |
|
| 67 |
|
|
| 68 |
|
|
| 69 |
def _extract_frames_ffmpeg(video_path: str, frame_indices: list[int]) -> np.ndarray: |
Module built on the numeric Python stack |
| 70 |
"""Extract specific frames using ffmpeg.""" |
|
| 71 |
frames = [] |
|
| 72 |
|
|
| 73 |
for idx in frame_indices: |
|
| 74 |
# Use ffmpeg to extract a specific frame |
|
| 75 |
cmd = [ |
|
| 76 |
"ffm… |
|
| 128:8 |
… # Default fallback frame |
|
| 129 |
frames.append(np.zeros((480, 640, 3), dtype=np.uint8)) |
Module built on the numeric Python stack |
| 130 |
|
|
| 131 |
return np.array(frames) |
|
| 132 |
|
|
| 133 |
|
|
| 134 |
def _extract_frames_at_timestamps_ffmpeg(video_path: str, timestamps: list[float]) -> np.ndarray: |
|
| 135 |
"""Extract fram… |
|
| 244:45 |
…) |
|
| 245 |
) |
|
| 246 |
|
|
| 247 |
# Generate timestamps |
|
| 248 |
timestamps = np.arange(actual_frames) / fps |
Module built on the numeric Python stack |
| 249 |
|
|
| 250 |
return frames, timestamps |
|
| 251 |
|
|
| 252 |
except subprocess.CalledProcessError as e: |
|
| 253 |
raise ValueErro… |
|
Micro-behaviors
| 66:5 |
… raise ValueError(f"Failed to get video info for {video_path}: {e}") |
|
| 67 |
|
|
| 68 |
|
|
| 69 |
def _extract_frames_ffmpeg(video_path: str, frame_indices: list[int]) -> np.ndarray: |
|
| 70 |
"""Extract specific frames using ffmpeg.""" |
|
| 71 |
frames = [] |
|
| 72 |
|
|
| 73 |
for idx in frame_indices: |
|
| 74 |
# Use ffmpeg to extract a specific frame |
|
| 75 |
cmd = [ |
|
| 76 |
"ffm… |
|
| 1 |
import json |
|
| 2 |
import subprocess |
|
| 3 |
|
|
| 4 |
import av |
|
| 5 |
import cv2 |
|
| 6 |
import numpy as np |
|
| 7 |
import torchvision |
|
| 8 |
|
|
| 9 |
# Import decord with graceful fallback |
|
| 10 |
try: |
|
| 11 |
import decord |
|
| 12 |
|
|
| 13 |
DECORD_AVAILABLE = True |
|
| 14 |
except ImportError: |
|
| 15 |
DECORD_AVAILABLE = False |
|
| 16 |
|
|
| 17 |
try: |
|
| 18 |
import torchcodec |
|
| 19 |
|
|
| 20 |
TORCHCODEC_AVAILABLE = True |
|
| 21 |
exce… |
|
| 128:8 |
… # Default fallback frame |
|
| 129 |
frames.append(np.zeros((480, 640, 3), dtype=np.uint8)) |
|
| 130 |
|
|
| 131 |
return np.array(frames) |
|
| 132 |
|
|
| 133 |
|
|
| 134 |
def _extract_frames_at_timestamps_ffmpeg(video_path: str, timestamps: list[float]) -> np.ndarray: |
|
| 135 |
"""Extract fram… |
|
| 244:45 |
…) |
|
| 245 |
) |
|
| 246 |
|
|
| 247 |
# Generate timestamps |
|
| 248 |
timestamps = np.arange(actual_frames) / fps |
|
| 249 |
|
|
| 250 |
return frames, timestamps |
|
| 251 |
|
|
| 252 |
except subprocess.CalledProcessError as e: |
|
| 253 |
raise ValueErro… |
|
| 347:22 |
…tamps to valid range to avoid RuntimeError |
|
| 348 |
timestamps = np.clip(timestamps, min_pts, max_pts) |
|
| 349 |
|
|
| 350 |
# Correct float precision issues in timestamps |
|
| 351 |
# E.g. for 5fps video: [1.0, 1.20… |
|
| 1 |
import json |
|
| 2 |
import subprocess |
|
| 3 |
|
|
| 4 |
import av |
|
| 5 |
import cv2 |
|
| 6 |
import numpy as np |
|
| 7 |
import torchvision |
|
| 8 |
|
|
| 9 |
# Import decord with graceful fallback |
|
| 10 |
try: |
|
| 11 |
import decord |
|
| 12 |
|
|
| 13 |
DECORD_AVAILABLE = True |
|
| 14 |
except ImportError: |
|
| 15 |
DECORD_AVAILABLE = False |
|
| 16 |
|
|
| 17 |
try: |
|
| 18 |
import torchcodec |
|
| 19 |
|
|
| 20 |
TORCHCODEC_AVAILABLE = True |
|
| 21 |
exce… |
|
| 36:6 |
… "json", |
|
| 37 |
video_path, |
|
| 38 |
] |
|
| 39 |
|
|
| 40 |
try: |
|
| 41 |
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8") |
|
| 42 |
probe_data = json.loads(output) |
|
| 43 |
stream = probe_data["streams"][0] |
|
| 44 |
|
|
| 45 |
# Parse frame rate (comes as fraction like "15/1") |
|
| 46 |
if "/" in… |
|
| 277:7 |
…if video_backend == "opencv": |
|
| 278 |
frames = [] |
|
| 279 |
cap = cv2.VideoCapture(video_path, **video_backend_kwargs) |
|
| 280 |
for idx in indices: |
|
| 281 |
cap.set(cv2.CAP_PROP_POS_FRAMES, idx) |
|
| 282 |
ret, frame = cap.read() |
|
| 283 |
if not ret: |
|
| 284 |
raise ValueError(f"Unable to read frame at index {idx}… |
|
| 36:6 |
… "json", |
|
| 37 |
video_path, |
|
| 38 |
] |
|
| 39 |
|
|
| 40 |
try: |
|
| 41 |
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8") |
|
| 42 |
probe_data = json.loads(output) |
|
| 43 |
stream = probe_data["streams"][0] |
|
| 44 |
|
|
| 45 |
# Parse frame rate (comes as fraction like "15/1") |
|
| 46 |
if "/" in… |
|
| 1 |
import json |
|
| 2 |
import subprocess |
|
| 3 |
|
|
| 4 |
import av |
|
| 5 |
import cv2 |
|
| 6 |
import numpy as np |
|
| 7 |
import torchvision |
|
| 8 |
|
|
| 9 |
# Import decord with graceful fallback |
|
| 10 |
try: |
|
| 11 |
import decord |
|
| 12 |
|
|
| 13 |
DECORD_AVAILABLE = True |
|
| 14 |
except ImportError: |
|
| 15 |
DECORD_AVAILABLE = False |
|
| 16 |
|
|
| 17 |
try: |
|
| 18 |
import torchcodec |
|
| 19 |
|
|
| 20 |
TORCHCODEC_AVAILABLE = True |
|
| 21 |
exce… |
|
| 326:62 |
… num_ffmpeg_threads=0 |
|
| 327 |
) |
|
| 328 |
|
|
| 329 |
# https://docs.pytorch.org/torchcodec/stable/generated/torchcodec.decoders… |
|
Metadata
| 1 |
import json |
|
| 2 |
import subprocess |
|
| 3 |
|
|
| 4 |
import av |
|
| 5 |
import cv2 |
|
| 6 |
import numpy as np |
|
| 7 |
import torchvision |
|
| 8 |
|
|
| 9 |
# Import decord with graceful fallback |
|
| 10 |
try: |
|
| 11 |
import decord |
|
| 12 |
|
|
| 13 |
DECORD_AVAILABLE = True |
|
| 14 |
except ImportError: |
|
| 15 |
DECORD_AVAILABLE = False |
|
| 16 |
|
|
| 17 |
try: |
|
| 18 |
import torchcodec |
|
| 19 |
|
|
| 20 |
TORCHCODEC_AVAILABLE = True |
|
| 21 |
exce… |
|
| 300:54 |
…s. |
|
| 301 |
|
|
| 302 |
Args: |
|
| 303 |
video_path (str): Path to the video file. |
|
| 304 |
timestamps (list[int] | np.ndarray): Timestamps to retrieve frames for, in … |
|
| 50:28 |
…eam["r_frame_rate"]) |
|
| 51 |
|
|
| 52 |
# Get frame count and duration |
|
| 53 |
nb_frames = int(stream.get("nb_frames", 0)) |
|
| 54 |
duration = float(stream.ge… |
|
| 66:5 |
… raise ValueError(f"Failed to get video info for {video_path}: {e}") |
|
| 67 |
|
|
| 68 |
|
|
| 69 |
def _extract_frames_ffmpeg(video_path: str, frame_indices: list[int]) -> np.ndarray: |
|
| 70 |
"""Extract specific frames using ffmpeg.""" |
|
| 71 |
frames = [] |
|
| 72 |
|
|
| 73 |
for idx in frame_indices: |
|
| 74 |
# Use ffmpeg to extract a specific frame |
|
| 75 |
cmd = [ |
|
| 76 |
"ffm… |
|
| 340:25 |
…tion range from first and last frames |
|
| 341 |
# This is a robust way to get valid timestamp range without depending on specific metadata attributes |
|
Identity
| SHA-256 |
719dbfbc8d7ab6f965bf431393d54fae3f8014905db2f84258e7149138cd101d |
| Filename |
video_utils.py |
| Package |
zhicao/dreamzero |
| Version |
main |
| PURL |
pkg:huggingface/zhicao/dreamzero@main |
Timeline
| First seen |
13 Aug 2026 21:18 UTC |
| First analyzed |
29 Aug 2026 16:30 UTC |
| Last analyzed |
29 Aug 2026 16:30 UTC |
| Last updated |
29 Aug 2026 16:30 UTC |
Labeling
| Label |
unknown |
| Label source |
forager |
| Traits version |
1e4c6 |