multimodalart HF Staff commited on
Commit
97142dd
·
verified ·
1 Parent(s): 1f48523

Restore probe

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -313,6 +313,21 @@ def conditioner():
313
  return Client(CONDITIONER_SPACE)
314
 
315
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  def collect(image_paths, audio_path, video_path) -> list[tuple[str, str]]:
317
  """The `(kind, path)` references of a request, **in the order the model reads them**.
318
 
 
313
  return Client(CONDITIONER_SPACE)
314
 
315
 
316
+ def probe(path: str) -> tuple[float | None, float | None]:
317
+ """`(video seconds, audio seconds)` of a media file, either being `None` when the stream is absent."""
318
+ import av
319
+
320
+ def seconds(stream, container):
321
+ if stream.duration is not None and stream.time_base is not None:
322
+ return float(stream.duration * stream.time_base)
323
+ return None if container.duration is None else container.duration / av.time_base
324
+
325
+ with av.open(path) as container:
326
+ video = seconds(container.streams.video[0], container) if container.streams.video else None
327
+ audio = seconds(container.streams.audio[0], container) if container.streams.audio else None
328
+ return video, audio
329
+
330
+
331
  def collect(image_paths, audio_path, video_path) -> list[tuple[str, str]]:
332
  """The `(kind, path)` references of a request, **in the order the model reads them**.
333