forked from PyAV-Org/PyAV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_codec.py
More file actions
106 lines (83 loc) · 3.18 KB
/
Copy pathtest_codec.py
File metadata and controls
106 lines (83 loc) · 3.18 KB
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
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
import unittest
from av import AudioFormat, Codec, VideoFormat, codecs_available
from av.codec.codec import UnknownCodecError
from .common import TestCase
# some older ffmpeg versions have no native opus encoder
try:
opus_c = Codec('opus', 'w')
opus_encoder_missing = False
except UnknownCodecError:
opus_encoder_missing = True
class TestCodecs(TestCase):
def test_codec_bogus(self):
with self.assertRaises(UnknownCodecError):
Codec('bogus123')
with self.assertRaises(UnknownCodecError):
Codec('bogus123', 'w')
def test_codec_mpeg4_decoder(self):
c = Codec('mpeg4')
self.assertEqual(c.name, 'mpeg4')
self.assertEqual(c.long_name, 'MPEG-4 part 2')
self.assertEqual(c.type, 'video')
self.assertIn(c.id, (12, 13))
self.assertTrue(c.is_decoder)
self.assertFalse(c.is_encoder)
# audio
self.assertIsNone(c.audio_formats)
self.assertIsNone(c.audio_rates)
# video
formats = c.video_formats
self.assertTrue(formats)
self.assertIsInstance(formats[0], VideoFormat)
self.assertTrue(any(f.name == 'yuv420p' for f in formats))
self.assertIsNone(c.frame_rates)
def test_codec_mpeg4_encoder(self):
c = Codec('mpeg4', 'w')
self.assertEqual(c.name, 'mpeg4')
self.assertEqual(c.long_name, 'MPEG-4 part 2')
self.assertEqual(c.type, 'video')
self.assertIn(c.id, (12, 13))
self.assertTrue(c.is_encoder)
self.assertFalse(c.is_decoder)
# audio
self.assertIsNone(c.audio_formats)
self.assertIsNone(c.audio_rates)
# video
formats = c.video_formats
self.assertTrue(formats)
self.assertIsInstance(formats[0], VideoFormat)
self.assertTrue(any(f.name == 'yuv420p' for f in formats))
self.assertIsNone(c.frame_rates)
def test_codec_opus_decoder(self):
c = Codec('opus')
self.assertEqual(c.name, 'opus')
self.assertEqual(c.long_name, 'Opus')
self.assertEqual(c.type, 'audio')
self.assertTrue(c.is_decoder)
self.assertFalse(c.is_encoder)
# audio
self.assertIsNone(c.audio_formats)
self.assertIsNone(c.audio_rates)
# video
self.assertIsNone(c.video_formats)
self.assertIsNone(c.frame_rates)
@unittest.skipIf(opus_encoder_missing, 'Opus encoder is not available')
def test_codec_opus_encoder(self):
c = Codec('opus', 'w')
self.assertIn(c.name, ('opus', 'libopus'))
self.assertIn(c.long_name, ('Opus', 'libopus Opus'))
self.assertEqual(c.type, 'audio')
self.assertTrue(c.is_encoder)
self.assertFalse(c.is_decoder)
# audio
formats = c.audio_formats
self.assertTrue(formats)
self.assertIsInstance(formats[0], AudioFormat)
self.assertTrue(any(f.name in ['flt', 'fltp'] for f in formats))
self.assertIsNotNone(c.audio_rates)
self.assertIn(48000, c.audio_rates)
# video
self.assertIsNone(c.video_formats)
self.assertIsNone(c.frame_rates)
def test_codecs_available(self):
self.assertTrue(codecs_available)