Skip to content

title

Classes:

SplitHelper

Methods:

split_audio staticmethod

split_audio(
    title: Title, splits: list[int], i: int = 0
) -> tuple[AudioNode | None, ...]
Source code
372
373
374
375
376
@staticmethod
def split_audio(title: Title, splits: list[int], i: int = 0) -> tuple[vs.AudioNode | None, ...]:
    reta = SplitHelper._cut_split(title, splits, title.audios[i], SplitHelper._cut_fz_a)
    assert len(reta) == len(splits) + 1
    return reta

split_chapters staticmethod

split_chapters(title: Title, splits: list[int]) -> list[list[int]]
Source code
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
@staticmethod
def split_chapters(title: Title, splits: list[int]) -> list[list[int]]:
    out = list[list[int]]()

    rebase = title.chapters[0]  # normally 0
    chaps = list[int]()

    for i, a in enumerate(title.chapters):
        chaps.append(a - rebase)

        if (i + 1) in splits:
            rebase = a

            out.append(chaps)
            chaps = [0]

    if len(chaps) >= 1:
        out.append(chaps)

    assert len(out) == len(splits) + 1

    return out

split_range_ac3 staticmethod

split_range_ac3(
    title: Title, f: int, t: int, audio_i: int, outfile: str
) -> float
Source code
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
@staticmethod
def split_range_ac3(title: Title, f: int, t: int, audio_i: int, outfile: str) -> float:
    nd = vs.core.dvdsrc2.RawAc3(str(title._core.iso_path), title._vts, audio_i, title._dvdsrc_ranges)

    start, end = (get_prop(nd, f"Stuff_{x}_PTS", int) for x in ("Start", "End"))

    debug_print(f"Stuff_Start_PTS pts {start} Stuff_End_PTS {end}")

    raw_start = title._absolute_time[title.chapters[f - 1]] * PCR_CLOCK
    raw_end = (title._absolute_time[title.chapters[t]] + title._duration_times[title.chapters[t]]) * PCR_CLOCK

    start_pts = raw_start + start
    end_pts = start_pts + (raw_end - raw_start)

    audio_offset_pts = 0.0

    with open(outfile, "wb") as outf:
        debug_print(f"start_pts  {start_pts} end_pts {end_pts}")

        start = int(start_pts / AC3_FRAME_LENGTH)

        debug_print("first ", start, len(nd))

        for i, frame in enumerate(nd.frames(close=True)):
            pkt_start_pts = i * AC3_FRAME_LENGTH
            pkt_end_pts = (i + 1) * AC3_FRAME_LENGTH

            assert pkt_end_pts > start_pts

            if pkt_start_pts < start_pts:
                audio_offset_pts = start_pts - pkt_start_pts

            outf.write(bytes(frame[0]))

            if pkt_end_pts > end_pts:
                break

    debug_print("wrote", (i - (start_pts // AC3_FRAME_LENGTH)))
    debug_print("offset is", (audio_offset_pts) / 90, "ms")

    return audio_offset_pts / PCR_CLOCK

split_video staticmethod

split_video(title: Title, splits: list[int]) -> tuple[VideoNode | None, ...]
Source code
366
367
368
369
370
@staticmethod
def split_video(title: Title, splits: list[int]) -> tuple[vs.VideoNode | None, ...]:
    reta = SplitHelper._cut_split(title, splits, title.video, SplitHelper._cut_fz_v)
    assert len(reta) == len(splits) + 1
    return reta

SplitTitle dataclass

SplitTitle(
    video: VideoNode | None,
    audios: list[AudioNode | None],
    chapters: list[int],
    _title: Title,
    _split_chpts: tuple[int, int],
)

Methods:

Attributes:

audios instance-attribute

audios: list[AudioNode | None]

chapters instance-attribute

chapters: list[int]

video instance-attribute

video: VideoNode | None

ac3

ac3(outfile: str, audio_i: int = 0) -> float
Source code
29
30
def ac3(self, outfile: str, audio_i: int = 0) -> float:
    return SplitHelper.split_range_ac3(self._title, *self._split_chpts, audio_i, outfile)

Title dataclass

Title(
    video: VideoNode,
    chapters: list[int],
    cell_changes: list[int],
    _core: IsoFileCore,
    _title: int,
    _vts: int,
    _vobidcellids_to_take: list[tuple[int, int]],
    _dvdsrc_ranges: list[int],
    _absolute_time: list[float],
    _duration_times: list[float],
    _audios: list[str],
    _patched_end_chapter: int | None,
)

Methods:

Attributes:

audio property

audio: AudioNode

cell_changes instance-attribute

cell_changes: list[int]

chapters instance-attribute

chapters: list[int]

video instance-attribute

video: VideoNode

dump_ac3

dump_ac3(a: str, audio_i: int = 0, only_calc_delay: bool = False) -> float
Source code
253
254
255
256
257
258
259
260
261
262
263
264
265
266
def dump_ac3(self, a: str, audio_i: int = 0, only_calc_delay: bool = False) -> float:
    self._assert_dvdsrc2(self.dump_ac3)

    if not self._audios[audio_i].startswith("ac3"):
        raise CustomValueError(f"Audio at {audio_i} is not ac3", self.dump_ac3)

    nd = vs.core.dvdsrc2.RawAc3(str(self._core.iso_path), self._vts, audio_i, self._dvdsrc_ranges)

    if not only_calc_delay:
        with open(a, "wb") as wrt:
            for f in nd.frames():
                wrt.write(bytes(f[0]))

    return float(get_prop(nd, "Stuff_Start_PTS", int)) / PCR_CLOCK

preview

preview(split: SplitTitle | Sequence[SplitTitle] | None = None) -> None
Source code
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
def preview(self, split: SplitTitle | Sequence[SplitTitle] | None = None) -> None:
    set_output(self.video, f"title v{self._title}")

    if split is not None:
        split = to_arr(split)

        for i, s in enumerate(split):
            if s.video:
                set_output(s.video, f"split {i}")

        for i, s in enumerate(split):
            if len(s.audios) >= 1:
                for j, audio in enumerate(s.audios):
                    if audio:
                        set_output(audio, f"split {i} - {j}")

split_at

split_at(
    splits: list[int], audio: int | list[int] | None = None
) -> tuple[SplitTitle, ...]
Source code
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
def split_at(self, splits: list[int], audio: int | list[int] | None = None) -> tuple[SplitTitle, ...]:
    # Check if chapters are still valid, user is allowed to manipulated them
    last_chpt = -1
    for a in self.chapters:
        if a < 0:
            raise CustomValueError(f"Negative chapter point {a}", self.split_at)
        if a <= last_chpt:
            raise CustomValueError(f"Chapter must be monotonly increasing {a} before {last_chpt}", self.split_at)
        if a > len(self.video):
            raise CustomValueError("Chapter must not be higher than video length", self.split_at)
        last_chpt = a
    output_cnt = SplitHelper._sanitize_splits(self, splits)
    video = SplitHelper.split_video(self, splits)
    chapters = SplitHelper.split_chapters(self, splits)

    audios: list[list[vs.AudioNode | None]]

    if audio is not None and (audio := to_arr(audio)):
        audio_per_output_cnt = len(audio)

        auds = [SplitHelper.split_audio(self, splits, a) for a in audio]

        audios = [[auds[j][i] for j in range(audio_per_output_cnt)] for i in range(output_cnt)]
    else:
        audios = [[]] * output_cnt

    fromy = 1
    from_to_s = list[tuple[int, int]]()

    for j in splits:
        from_to_s.append((fromy, j - 1))
        fromy = j

    from_to_s.append((fromy, len(self.chapters) - 1))

    return tuple(SplitTitle(v, a, c, self, f) for v, a, c, f in zip(video, audios, chapters, from_to_s))

split_range

split_range(
    start: int, end: int, audio: list[int] | int | None = None
) -> SplitTitle
Source code
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
def split_range(self, start: int, end: int, audio: list[int] | int | None = None) -> SplitTitle:
    if start < 0:
        start = len(self.chapters) + start

    if end < 0:
        end = len(self.chapters) + end

    if start == 1 and end == len(self.chapters) - 1:
        return self.split_at([], audio)[0]

    if start == 1:
        return self.split_at([end + 1], audio)[0]

    if end == len(self.chapters) - 1:
        return self.split_at([start], audio)[1]

    return self.split_at([start, end + 1], audio)[1]

split_ranges

split_ranges(
    split: list[tuple[int, int]], audio: list[int] | int | None = None
) -> tuple[SplitTitle, ...]
Source code
210
211
212
213
def split_ranges(
    self, split: list[tuple[int, int]], audio: list[int] | int | None = None
) -> tuple[SplitTitle, ...]:
    return tuple(self.split_range(start, end, audio) for start, end in split)

TitleAudios

TitleAudios(title: Title)

Bases: vs_object, list[AudioNode]

Attributes:

Source code
68
69
70
71
def __init__(self, title: Title) -> None:
    self.title = title

    self.cache = dict[int, vs.AudioNode | None](dict.fromkeys(range(len(self.title._audios))))

cache instance-attribute

cache = dict[int, AudioNode | None](fromkeys(range(len(_audios))))

title instance-attribute

title = title