Skip to content

Config

ImageSamplerConfig

Bases: SamplerConfig

Configuration options for the image sampler.

Source code in video_sampler/config.py
124
125
126
127
128
129
class ImageSamplerConfig(SamplerConfig):
    """
    Configuration options for the image sampler.
    """

    frame_time_regex: str = Field(default="")

SamplerConfig

Bases: BaseModel

Configuration options for the video sampler.

Parameters:

Name Type Description Default
min_frame_interval_sec float

The minimum time interval between sampled frames in seconds. Defaults to 1.

required
keyframes_only bool

Flag indicating whether to sample only keyframes. Defaults to True.

required
queue_wait float

The time to wait between checking the frame queue in seconds. Defaults to 0.1.

required
start_time_s int

The starting time for sampling in seconds. Defaults to 0.

required
end_time_s int

The ending time for sampling in seconds. None for no end. Defaults to None.

required
precise_seek bool

Flag indicating whether to use precise seeking. Defaults to False. Precise seeking is slower but more accurate.

required
debug bool

Flag indicating whether to enable debug mode. Defaults to False.

required
print_stats bool

Flag indicating whether to print sampling statistics. Defaults to False.

required
buffer_config dict[str, Any]

Configuration options for the frame buffer. Defaults to {"type": "entropy", "size": 15, "debug": True}.

required
gate_config dict[str, Any]

Configuration options for the frame gate. Defaults to {"type": "pass"}.

required
extractor_config dict[str, Any]

Configuration options for the extractor (keyword, audio). Defaults to None.

required
summary_config dict[str, Any]

Configuration options for the summary generator. Defaults to None.

required

Methods: str() -> str: Returns a string representation of the configuration.

Source code in video_sampler/config.py
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
class SamplerConfig(BaseModel):
    """
    Configuration options for the video sampler.

    Args:
        min_frame_interval_sec (float, optional): The minimum time interval
            between sampled frames in seconds. Defaults to 1.
        keyframes_only (bool, optional): Flag indicating whether to
            sample only keyframes. Defaults to True.
        queue_wait (float, optional): The time to wait between checking
            the frame queue in seconds. Defaults to 0.1.
        start_time_s (int, optional): The starting time for sampling in seconds.
            Defaults to 0.
        end_time_s (int, optional): The ending time for sampling in seconds.
            None for no end. Defaults to None.
        precise_seek (bool, optional): Flag indicating whether to use precise
            seeking. Defaults to False. Precise seeking is slower but more
            accurate.
        debug (bool, optional): Flag indicating whether to enable debug mode.
            Defaults to False.
        print_stats (bool, optional): Flag indicating whether to print
            sampling statistics. Defaults to False.
        buffer_config (dict[str, Any], optional): Configuration options for
                the frame buffer. Defaults to {"type": "entropy", "size": 15,
                "debug": True}.
        gate_config (dict[str, Any], optional): Configuration options for
                the frame gate. Defaults to {"type": "pass"}.
        extractor_config (dict[str, Any], optional): Configuration options for
                the extractor (keyword, audio). Defaults to None.
        summary_config (dict[str, Any], optional): Configuration options for
                the summary generator. Defaults to None.
    Methods:
        __str__() -> str:
            Returns a string representation of the configuration.

    """

    min_frame_interval_sec: float = Field(default=1, ge=0)
    keyframes_only: bool = Field(default=True)
    queue_wait: float = Field(default=0.1, ge=1e-3)
    start_time_s: int = Field(
        default=0, ge=0, description="The starting time for sampling in seconds."
    )
    end_time_s: int | None = Field(
        default=None,
        ge=1,
        description="The ending time for sampling in seconds. None for no end.",
    )
    precise_seek: bool = Field(default=False, description="Use precise seeking.")
    debug: bool = Field(default=False)
    print_stats: bool = Field(default=False)
    buffer_config: dict[str, Any] = Field(
        default_factory=lambda: {
            "type": "hash",
            "hash_size": 8,
            "size": 15,
            "debug": True,
        }
    )
    gate_config: dict[str, Any] = Field(
        default_factory=lambda: {
            "type": "pass",
        }
    )
    extractor_config: dict[str, Any] = Field(default_factory=dict)
    summary_config: dict[str, Any] = Field(default_factory=dict)
    n_workers: int = Field(default=1)

    save_format: SaveFormatConfig = Field(default_factory=SaveFormatConfig)

    def __str__(self) -> str:
        return str(self.model_dump())

    @classmethod
    def from_yaml(cls, file_path: str) -> "SamplerConfig":
        with open(file_path) as file:
            data = yaml.safe_load(file)
        return cls(**data)

    @model_validator(mode="after")
    def validate_start_end_times(cls, values: "SamplerConfig"):
        if values.end_time_s is not None and values.start_time_s >= values.end_time_s:
            raise ValueError("start_time_s must be strictly less than the end_time_s")
        return values

SaveFormatConfig

Bases: BaseModel

Configuration options for the save format.

Parameters:

Name Type Description Default
encode_time_b64 bool

Encode time as base64 string. Avoids . in the filename. Defaults to False.

required
avoid_dot bool

Avoid . in the filename by replacing it with _. Defaults to False.

required
include_filename bool

Include filename in the output path. Defaults to False.

required
Source code in video_sampler/config.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class SaveFormatConfig(BaseModel):
    """
    Configuration options for the save format.

    Args:
        encode_time_b64 (bool, optional): Encode time as base64 string. Avoids `.`
            in the filename. Defaults to False.
        avoid_dot (bool, optional): Avoid `.` in the filename by replacing
            it with `_`. Defaults to False.
        include_filename (bool, optional): Include filename in the output
            path. Defaults to False.
    """

    encode_time_b64: bool = Field(default=False)
    avoid_dot: bool = Field(default=False)
    include_filename: bool = Field(default=False)

    @model_validator(mode="after")
    def validate_save_format(cls, values: "SaveFormatConfig"):
        if values.encode_time_b64 and values.avoid_dot:
            import warnings

            warnings.warn(
                "encode_time_b64 and avoid_dot are both True, "
                "avoid_dot will be ignored",
                UserWarning,
                stacklevel=2,
            )
        return values