Skip to content

zimscraperlib.video.config

Classes:

Config

Config(**kwargs: Any)

Bases: dict[str, str | None]

Methods:

  • build_from

    build a Config easily via shortcut params

  • to_ffmpeg_args

    Convert the options dict to list of ffmpeg arguments

  • update_from

    Updates Config object based on shortcut params as given in build_from()

Attributes:

Source code in src/zimscraperlib/video/config.py
21
22
23
24
def __init__(self, **kwargs: Any):
    super().__init__(self, **type(self).defaults)
    self.update(self.options)
    self.update(kwargs)

VERSION class-attribute instance-attribute

VERSION = 1

audio_codec property writable

audio_codec

audio_sampling_rate property writable

audio_sampling_rate

buffersize property writable

buffersize

defaults class-attribute

defaults: dict[str, str | None] = {
    "-max_muxing_queue_size": "9999"
}

ext class-attribute instance-attribute

ext = 'dat'

mapping class-attribute

mapping: dict[str, str] = {
    "video_codec": "-codec:v",
    "audio_codec": "-codec:a",
    "max_video_bitrate": "-maxrate",
    "min_video_bitrate": "-minrate",
    "target_video_bitrate": "-b:v",
    "buffersize": "-bufsize",
    "audio_sampling_rate": "-ar",
    "target_audio_bitrate": "-b:a",
}

max_video_bitrate property writable

max_video_bitrate

mimetype class-attribute instance-attribute

mimetype = 'application/data'

min_video_bitrate property writable

min_video_bitrate

options class-attribute

options: dict[str, str | None] = {}

quantizer_scale_range property writable

quantizer_scale_range

target_audio_bitrate property writable

target_audio_bitrate

target_video_bitrate property writable

target_video_bitrate

video_codec property writable

video_codec

video_scale property writable

video_scale: str | None

build_from classmethod

build_from(**params: Any)

build a Config easily via shortcut params

video_codec: codec for output audio stream. more info https://ffmpeg.org/ffmpeg-codecs.html#Video-Encoders values: h264 | libvpx | libx264 | libx265 | xxx audio_codec: codec for output audio stream. more info https://ffmpeg.org/ffmpeg-codecs.html#Audio-Encoders values: aac | mp3 | flac | opus | libvorbis | xxx max_video_bitrate: maximum size per second for video stream values: 128k | 1m min_video_bitrate: minimum size per second for video stream values: 128k | 1m target_video_bitrate: tentative size per second for video stream values: 384k | 1m target_audio_bitrate: tentative size per second for audio stream values: 48k | 128k buffersize: decoder buffer size values: 1000k | 1m audio_sampling_rate: number of audio samples per second values: 44100 | 48000 quantizer_scale_range: tuple of min / max values of video quantizer scale (VBR) values: (21, 35) | (68, 97) | (x, y) video_scale: video frame scale. more info - https://trac.ffmpeg.org/wiki/Scaling values: 480:320 | 320:240 | width:height

Source code in src/zimscraperlib/video/config.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
@classmethod
def build_from(cls, **params: Any):
    """build a Config easily via shortcut params

    video_codec: codec for output audio stream. more info
    https://ffmpeg.org/ffmpeg-codecs.html#Video-Encoders
        values: h264 | libvpx | libx264 | libx265 | xxx
    audio_codec: codec for output audio stream. more info
    https://ffmpeg.org/ffmpeg-codecs.html#Audio-Encoders
        values: aac | mp3 | flac | opus | libvorbis | xxx
    max_video_bitrate: maximum size per second for video stream
        values: 128k | 1m
    min_video_bitrate: minimum size per second for video stream
        values: 128k | 1m
    target_video_bitrate: tentative size per second for video stream
        values: 384k | 1m
    target_audio_bitrate: tentative size per second for audio stream
        values: 48k | 128k
    buffersize: decoder buffer size
        values: 1000k | 1m
    audio_sampling_rate: number of audio samples per second
        values: 44100 | 48000
    quantizer_scale_range: tuple of min / max values of video quantizer scale (VBR)
        values: (21, 35) | (68, 97) | (x, y)
    video_scale: video frame scale. more info - https://trac.ffmpeg.org/wiki/Scaling
        values: 480:320 | 320:240 | width:height
    """
    config = cls()
    config.update_from(**params)
    return config

to_ffmpeg_args

to_ffmpeg_args() -> list[str]

Convert the options dict to list of ffmpeg arguments

Source code in src/zimscraperlib/video/config.py
32
33
34
35
36
37
38
39
40
41
42
43
def to_ffmpeg_args(self) -> list[str]:
    """Convert the options dict to list of ffmpeg arguments"""

    args: list[str] = []
    for k, v in self.items():
        if v:
            args += [k, v]
        else:
            args += [
                k
            ]  # put only k in cases it's not followed by a value (boolean flag)
    return args

update_from

update_from(**kwargs: Any)

Updates Config object based on shortcut params as given in build_from()

Source code in src/zimscraperlib/video/config.py
26
27
28
29
30
def update_from(self, **kwargs: Any):
    """Updates Config object based on shortcut params as given in build_from()"""

    for key, value in kwargs.items():
        setattr(self, key, value)