|
1 | 1 | import collections
|
| 2 | +import itertools |
2 | 3 | import math
|
3 | 4 | import os
|
4 | 5 | import unittest
|
@@ -1243,16 +1244,39 @@ def test_invalid_file(self):
|
1243 | 1244 | with self.assertRaises(RuntimeError):
|
1244 | 1245 | io.read_video('foo.mp4')
|
1245 | 1246 |
|
1246 |
| - def test_audio_present(self): |
1247 |
| - """Test if audio frames are returned with video_reader backend.""" |
1248 |
| - set_video_backend('video_reader') |
| 1247 | + def test_audio_present_pts(self): |
| 1248 | + """Test if audio frames are returned with pts unit.""" |
| 1249 | + backends = ['video_reader', 'pyav'] |
| 1250 | + start_offsets = [0, 1000] |
| 1251 | + end_offsets = [3000, None] |
| 1252 | + for test_video, _ in test_videos.items(): |
| 1253 | + full_path = os.path.join(VIDEO_DIR, test_video) |
| 1254 | + container = av.open(full_path) |
| 1255 | + if container.streams.audio: |
| 1256 | + for backend, start_offset, end_offset in itertools.product( |
| 1257 | + backends, start_offsets, end_offsets): |
| 1258 | + set_video_backend(backend) |
| 1259 | + _, audio, _ = io.read_video( |
| 1260 | + full_path, start_offset, end_offset, pts_unit='pts') |
| 1261 | + self.assertGreaterEqual(audio.shape[0], 1) |
| 1262 | + self.assertGreaterEqual(audio.shape[1], 1) |
| 1263 | + |
| 1264 | + def test_audio_present_sec(self): |
| 1265 | + """Test if audio frames are returned with sec unit.""" |
| 1266 | + backends = ['video_reader', 'pyav'] |
| 1267 | + start_offsets = [0, 0.1] |
| 1268 | + end_offsets = [0.3, None] |
1249 | 1269 | for test_video, _ in test_videos.items():
|
1250 | 1270 | full_path = os.path.join(VIDEO_DIR, test_video)
|
1251 | 1271 | container = av.open(full_path)
|
1252 | 1272 | if container.streams.audio:
|
1253 |
| - _, audio, _ = io.read_video(full_path) |
1254 |
| - self.assertGreaterEqual(audio.shape[0], 1) |
1255 |
| - self.assertGreaterEqual(audio.shape[1], 1) |
| 1273 | + for backend, start_offset, end_offset in itertools.product( |
| 1274 | + backends, start_offsets, end_offsets): |
| 1275 | + set_video_backend(backend) |
| 1276 | + _, audio, _ = io.read_video( |
| 1277 | + full_path, start_offset, end_offset, pts_unit='sec') |
| 1278 | + self.assertGreaterEqual(audio.shape[0], 1) |
| 1279 | + self.assertGreaterEqual(audio.shape[1], 1) |
1256 | 1280 |
|
1257 | 1281 |
|
1258 | 1282 | if __name__ == "__main__":
|
|
0 commit comments