File: test_chapters.py

package info (click to toggle)
python-av 16.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,684 kB
  • sloc: python: 7,607; sh: 182; ansic: 174; makefile: 135
file content (58 lines) | stat: -rw-r--r-- 1,484 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from fractions import Fraction

import av

from .common import fate_suite


def test_chapters() -> None:
    expected = [
        {
            "id": 1,
            "start": 0,
            "end": 5000,
            "time_base": Fraction(1, 1000),
            "metadata": {"title": "start"},
        },
        {
            "id": 2,
            "start": 5000,
            "end": 10500,
            "time_base": Fraction(1, 1000),
            "metadata": {"title": "Five Seconds"},
        },
        {
            "id": 3,
            "start": 10500,
            "end": 15000,
            "time_base": Fraction(1, 1000),
            "metadata": {"title": "Ten point 5 seconds"},
        },
        {
            "id": 4,
            "start": 15000,
            "end": 19849,
            "time_base": Fraction(1, 1000),
            "metadata": {"title": "15 sec - over soon"},
        },
    ]
    path = fate_suite("vorbis/vorbis_chapter_extension_demo.ogg")
    with av.open(path) as container:
        assert container.chapters() == expected


def test_set_chapters() -> None:
    chapters: list[av.container.Chapter] = [
        {
            "id": 1,
            "start": 0,
            "end": 5000,
            "time_base": Fraction(1, 1000),
            "metadata": {"title": "start"},
        }
    ]

    path = fate_suite("h264/interlaced_crop.mp4")
    with av.open(path) as container:
        container.set_chapters(chapters)
        assert container.chapters() == chapters