aburzio-nv commited on
Commit
9f2affb
·
verified ·
1 Parent(s): bc5a7ef

Allow 30 FPS sampling and replace source-frame cap with bounded decoding time

Browse files
README.md CHANGED
@@ -34,7 +34,8 @@ Live inference accepts JPEG, PNG or WebP images and supported video files,
34
  up to 300 images or sampled video frames, at most
35
  16 megapixels per frame. Uploads are limited to 100 MB per file at the
36
  HTTP upload boundary and 256 MiB total per submitted collection. Videos
37
- are limited to 900 decoded frames and sampled at 0.5–10 FPS.
 
38
 
39
  Uploads, previews and reconstruction downloads use temporary server storage.
40
  Gradio cache cleanup is configured to remove files older than one hour,
 
34
  up to 300 images or sampled video frames, at most
35
  16 megapixels per frame. Uploads are limited to 100 MB per file at the
36
  HTTP upload boundary and 256 MiB total per submitted collection. Videos
37
+ are sampled at 0.5–30 FPS, with no limit on the original video frame count.
38
+ Video decoding has a 30-second timeout.
39
 
40
  Uploads, previews and reconstruction downloads use temporary server storage.
41
  Gradio cache cleanup is configured to remove files older than one hour,
src/dvlt/scripts/gradio_demo.py CHANGED
@@ -349,8 +349,8 @@ def _load_files_to_frames(
349
  files: list[str], video_fps: float = 2.0, *, max_frames: Optional[int] = None
350
  ) -> list[Image.Image]:
351
  """Expand a list of upload paths (images and/or videos) into PIL frames."""
352
- if not 0.5 <= video_fps <= 10:
353
- raise ValueError("Video sampling FPS must be between 0.5 and 10.")
354
  if max_frames is not None:
355
  if len(files) > max_frames:
356
  raise ValueError(f"Upload at most {max_frames} files.")
@@ -369,7 +369,7 @@ def _load_files_to_frames(
369
  video_target_fps=video_fps,
370
  max_frames=max_frames - len(frames),
371
  max_pixels=16_000_000,
372
- max_video_frames=900,
373
  image_formats=("JPEG", "PNG", "WEBP"),
374
  )
375
  frames.extend(fs)
@@ -641,7 +641,7 @@ def build_app(
641
  if hosted:
642
  gr.Markdown(
643
  f"Upload up to {HOSTED_MAX_FRAMES} images or sampled video frames (16 megapixels per frame; "
644
- "100 MB per file, 256 MiB total; videos limited to 900 decoded frames). "
645
  "Uploads and results use temporary server storage and are scheduled for deletion "
646
  "after one hour. Download results before they expire. "
647
  "Hugging Face may retain operational logs separately. "
@@ -692,13 +692,13 @@ def build_app(
692
  model_status = gr.Markdown(_model_status(default_label), visible=True)
693
  video_fps_slider = gr.Slider(
694
  minimum=0.5,
695
- maximum=10,
696
  value=2,
697
  step=0.5,
698
  label="Video sampling FPS",
699
  info=(
700
  "Frames extracted per second, independent of the recording FPS. "
701
- f"{HOSTED_MAX_FRAMES}-frame limit; the separate 900 decoded-frame limit also applies."
702
  if hosted else "Changing this resamples uploaded videos."
703
  ),
704
  )
 
349
  files: list[str], video_fps: float = 2.0, *, max_frames: Optional[int] = None
350
  ) -> list[Image.Image]:
351
  """Expand a list of upload paths (images and/or videos) into PIL frames."""
352
+ if not 0.5 <= video_fps <= 30:
353
+ raise ValueError("Video sampling FPS must be between 0.5 and 30.")
354
  if max_frames is not None:
355
  if len(files) > max_frames:
356
  raise ValueError(f"Upload at most {max_frames} files.")
 
369
  video_target_fps=video_fps,
370
  max_frames=max_frames - len(frames),
371
  max_pixels=16_000_000,
372
+ decode_timeout_seconds=30,
373
  image_formats=("JPEG", "PNG", "WEBP"),
374
  )
375
  frames.extend(fs)
 
641
  if hosted:
642
  gr.Markdown(
643
  f"Upload up to {HOSTED_MAX_FRAMES} images or sampled video frames (16 megapixels per frame; "
644
+ "100 MB per file, 256 MiB total). "
645
  "Uploads and results use temporary server storage and are scheduled for deletion "
646
  "after one hour. Download results before they expire. "
647
  "Hugging Face may retain operational logs separately. "
 
692
  model_status = gr.Markdown(_model_status(default_label), visible=True)
693
  video_fps_slider = gr.Slider(
694
  minimum=0.5,
695
+ maximum=30,
696
  value=2,
697
  step=0.5,
698
  label="Video sampling FPS",
699
  info=(
700
  "Frames extracted per second, independent of the recording FPS. "
701
+ f"Up to {HOSTED_MAX_FRAMES} sampled frames for reconstruction."
702
  if hosted else "Changing this resamples uploaded videos."
703
  ),
704
  )
src/dvlt/util/preprocess.py CHANGED
@@ -8,6 +8,7 @@ the Gradio demo and ad-hoc Python usage after ``pip install -e .``.
8
  """
9
 
10
  import math
 
11
  from pathlib import Path
12
  from typing import Optional
13
 
@@ -38,12 +39,14 @@ def _frames_from_video(
38
  max_frames: Optional[int] = None,
39
  max_pixels: Optional[int] = None,
40
  max_video_frames: Optional[int] = None,
 
41
  ) -> list[Image.Image]:
42
  """Decode a video and return frames downsampled to ~target_fps.
43
 
44
  Falls back to ``video_fps`` when the container does not expose frame rate.
45
  Pass ``target_fps=None`` to keep every frame (stride = 1).
46
  """
 
47
  cap = cv2.VideoCapture(path)
48
  if not cap.isOpened():
49
  cap.release()
@@ -64,6 +67,8 @@ def _frames_from_video(
64
  if max_pixels is not None and width * height > max_pixels:
65
  raise ValueError(f"Video frames must contain at most {max_pixels:,} pixels.")
66
  while True:
 
 
67
  ok, frame_bgr = cap.read()
68
  if not ok:
69
  break
@@ -101,6 +106,7 @@ def load_sequence(
101
  max_frames: Optional[int] = None,
102
  max_pixels: Optional[int] = None,
103
  max_video_frames: Optional[int] = None,
 
104
  image_formats: Optional[tuple[str, ...]] = None,
105
  ) -> tuple[str, list[Image.Image]]:
106
  """Resolve a single path into a (sequence_name, frames) pair.
@@ -142,6 +148,7 @@ def load_sequence(
142
  max_frames=max_frames,
143
  max_pixels=max_pixels,
144
  max_video_frames=max_video_frames,
 
145
  )
146
  if ext in IMAGE_EXTS:
147
  return path.stem, [read_frame(path)]
 
8
  """
9
 
10
  import math
11
+ import time
12
  from pathlib import Path
13
  from typing import Optional
14
 
 
39
  max_frames: Optional[int] = None,
40
  max_pixels: Optional[int] = None,
41
  max_video_frames: Optional[int] = None,
42
+ decode_timeout_seconds: Optional[float] = None,
43
  ) -> list[Image.Image]:
44
  """Decode a video and return frames downsampled to ~target_fps.
45
 
46
  Falls back to ``video_fps`` when the container does not expose frame rate.
47
  Pass ``target_fps=None`` to keep every frame (stride = 1).
48
  """
49
+ deadline = time.monotonic() + decode_timeout_seconds if decode_timeout_seconds is not None else None
50
  cap = cv2.VideoCapture(path)
51
  if not cap.isOpened():
52
  cap.release()
 
67
  if max_pixels is not None and width * height > max_pixels:
68
  raise ValueError(f"Video frames must contain at most {max_pixels:,} pixels.")
69
  while True:
70
+ if deadline is not None and time.monotonic() >= deadline:
71
+ raise ValueError("Video decoding timed out. Trim the video or export a smaller version.")
72
  ok, frame_bgr = cap.read()
73
  if not ok:
74
  break
 
106
  max_frames: Optional[int] = None,
107
  max_pixels: Optional[int] = None,
108
  max_video_frames: Optional[int] = None,
109
+ decode_timeout_seconds: Optional[float] = None,
110
  image_formats: Optional[tuple[str, ...]] = None,
111
  ) -> tuple[str, list[Image.Image]]:
112
  """Resolve a single path into a (sequence_name, frames) pair.
 
148
  max_frames=max_frames,
149
  max_pixels=max_pixels,
150
  max_video_frames=max_video_frames,
151
+ decode_timeout_seconds=decode_timeout_seconds,
152
  )
153
  if ext in IMAGE_EXTS:
154
  return path.stem, [read_frame(path)]