Debian Codegraph @

tests/test_videoformat.py

raw
1 from av import VideoFormat
2
3 from .common import TestCase
4
5
6 class TestVideoFormats(TestCase):
7 def test_invalid_pixel_format(self):
8 with self.assertRaises(ValueError) as cm:
9 VideoFormat("__unknown_pix_fmt", 640, 480)
10 assert str(cm.exception) == "not a pixel format: '__unknown_pix_fmt'"
11
12 def test_rgb24_inspection(self) -> None:
13 fmt = VideoFormat("rgb24", 640, 480)
14 assert fmt.name == "rgb24"
15 assert len(fmt.components) == 3
16 assert not fmt.is_planar
17 assert not fmt.has_palette
18 assert fmt.is_rgb
19 assert fmt.chroma_width() == 640
20 assert fmt.chroma_height() == 480
21 assert fmt.chroma_width(1024) == 1024
22 assert fmt.chroma_height(1024) == 1024
23 for i in range(3):
24 comp = fmt.components[i]
25 assert comp.plane == 0
26 assert comp.bits == 8
27 assert not comp.is_luma
28 assert not comp.is_chroma
29 assert not comp.is_alpha
30 assert comp.width == 640
31 assert comp.height == 480
32
33 def test_yuv420p_inspection(self) -> None:
34 fmt = VideoFormat("yuv420p", 640, 480)
35 assert fmt.name == "yuv420p"
36 assert len(fmt.components) == 3
37 self._test_yuv420(fmt)
38
39 def _test_yuv420(self, fmt: VideoFormat) -> None:
40 assert fmt.is_planar
41 assert not fmt.has_palette
42 assert not fmt.is_rgb
43 assert fmt.chroma_width() == 320
44 assert fmt.chroma_height() == 240
45 assert fmt.chroma_width(1024) == 512
46 assert fmt.chroma_height(1024) == 512
47 for i, comp in enumerate(fmt.components):
48 comp = fmt.components[i]
49 assert comp.plane == i
50 assert comp.bits == 8
51 assert not fmt.components[0].is_chroma
52 assert fmt.components[1].is_chroma
53 assert fmt.components[2].is_chroma
54 assert fmt.components[0].is_luma
55 assert not fmt.components[1].is_luma
56 assert not fmt.components[2].is_luma
57 assert not fmt.components[0].is_alpha
58 assert not fmt.components[1].is_alpha
59 assert not fmt.components[2].is_alpha
60 assert fmt.components[0].width == 640
61 assert fmt.components[1].width == 320
62 assert fmt.components[2].width == 320
63
64 def test_yuva420p_inspection(self) -> None:
65 fmt = VideoFormat("yuva420p", 640, 480)
66 assert len(fmt.components) == 4
67 self._test_yuv420(fmt)
68 assert not fmt.components[3].is_chroma
69 assert fmt.components[3].width == 640
70
71 def test_gray16be_inspection(self) -> None:
72 fmt = VideoFormat("gray16be", 640, 480)
73 assert fmt.name == "gray16be"
74 assert len(fmt.components) == 1
75 assert not fmt.is_planar
76 assert not fmt.has_palette
77 assert not fmt.is_rgb
78 assert fmt.chroma_width() == 640
79 assert fmt.chroma_height() == 480
80 assert fmt.chroma_width(1024) == 1024
81 assert fmt.chroma_height(1024) == 1024
82 comp = fmt.components[0]
83 assert comp.plane == 0
84 assert comp.bits == 16
85 assert comp.is_luma
86 assert not comp.is_chroma
87 assert comp.width == 640
88 assert comp.height == 480
89 assert not comp.is_alpha
90
91 def test_pal8_inspection(self) -> None:
92 fmt = VideoFormat("pal8", 640, 480)
93 assert len(fmt.components) == 1
94 assert fmt.has_palette