File size: 998 Bytes
10bc78d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Add a video to the dataset: fingerprint it and store it under an id."""

import os

import storage
from fingerprint import extract_fingerprint, video_duration_seconds
from idgen import new_video_id


def ingest_video(source_path: str, title: str | None = None, samples_per_second: float = 1.0, video_id: str | None = None) -> dict:
    """Ingest a video. Pass video_id to append a new patch to an existing
    entry instead of creating a new one."""
    if not os.path.isfile(source_path):
        raise FileNotFoundError(source_path)

    fingerprint = extract_fingerprint(source_path, samples_per_second=samples_per_second)
    duration = video_duration_seconds(source_path)
    title = title or os.path.basename(source_path)
    video_id = video_id or new_video_id()

    meta = storage.add_video_patch(
        video_id=video_id,
        title=title,
        source_path=os.path.abspath(source_path),
        duration_seconds=duration,
        fingerprint=fingerprint,
    )
    return meta