|
6 | 6 | from unittest import SkipTest |
7 | 7 |
|
8 | 8 | import numpy |
| 9 | +import pytest |
9 | 10 |
|
10 | 11 | import av |
11 | 12 |
|
@@ -63,6 +64,45 @@ def test_data_packet_bytes(self): |
63 | 64 |
|
64 | 65 |
|
65 | 66 | class TestProperties: |
| 67 | + def test_rescale_ts(self) -> None: |
| 68 | + packet = av.Packet() |
| 69 | + packet.time_base = fractions.Fraction(1, 1000) |
| 70 | + packet.pts = 1000 |
| 71 | + packet.dts = 900 |
| 72 | + packet.duration = 40 |
| 73 | + |
| 74 | + packet.rescale_ts(av.AVRational(1, 100)) |
| 75 | + |
| 76 | + assert packet.time_base == fractions.Fraction(1, 100) |
| 77 | + assert packet.pts == 100 |
| 78 | + assert packet.dts == 90 |
| 79 | + assert packet.duration == 4 |
| 80 | + |
| 81 | + def test_rescale_ts_without_source_time_base(self) -> None: |
| 82 | + packet = av.Packet() |
| 83 | + packet.pts = 1000 |
| 84 | + packet.dts = 900 |
| 85 | + packet.duration = 40 |
| 86 | + |
| 87 | + packet.rescale_ts(av.AVRational(1, 100)) |
| 88 | + |
| 89 | + assert packet.time_base == fractions.Fraction(1, 100) |
| 90 | + assert packet.pts == 1000 |
| 91 | + assert packet.dts == 900 |
| 92 | + assert packet.duration == 40 |
| 93 | + |
| 94 | + def test_rescale_ts_rejects_zero_time_base(self) -> None: |
| 95 | + packet = av.Packet() |
| 96 | + |
| 97 | + with pytest.raises(ValueError, match="Cannot rebase to zero time"): |
| 98 | + packet.rescale_ts(av.AVRational(0, 1)) |
| 99 | + |
| 100 | + def test_rescale_ts_requires_avrational(self) -> None: |
| 101 | + packet = av.Packet() |
| 102 | + |
| 103 | + with pytest.raises(TypeError, match="time_base must be an AVRational"): |
| 104 | + packet.rescale_ts(fractions.Fraction(1, 100)) # type: ignore[arg-type] |
| 105 | + |
66 | 106 | def test_is_keyframe(self) -> None: |
67 | 107 | with av.open(fate_suite("h264/interlaced_crop.mp4")) as container: |
68 | 108 | stream = container.streams.video[0] |
|
0 commit comments