|
4 | 4 | import math |
5 | 5 | import os |
6 | 6 | from fractions import Fraction |
| 7 | +from typing import cast |
7 | 8 |
|
8 | 9 | import numpy as np |
9 | 10 | import pytest |
@@ -268,6 +269,30 @@ def test_subtitle_muxing(self) -> None: |
268 | 269 |
|
269 | 270 |
|
270 | 271 | class TestEncodeStreamSemantics(TestCase): |
| 272 | + def test_reconfigure_stream_after_mux(self) -> None: |
| 273 | + output_bytes = io.BytesIO() |
| 274 | + with av.open(output_bytes, "w", format="mp4") as output: |
| 275 | + first = cast(VideoStream, output.add_stream("ffv1", rate=30)) |
| 276 | + second = cast(VideoStream, output.add_stream("ffv1", rate=30)) |
| 277 | + |
| 278 | + first.format = av.VideoFormat("bgr0", width=16, height=16) |
| 279 | + frame = VideoFrame(16, 16, "bgr0") |
| 280 | + frame.pts = 0 |
| 281 | + frame.time_base = Fraction(1, 30) |
| 282 | + output.mux(first.encode(frame)) |
| 283 | + |
| 284 | + # Muxing the first packet writes the header and opens every stream. |
| 285 | + # Changing the second encoder now used to corrupt FFV1 state and crash. |
| 286 | + assert second.codec_context.is_open |
| 287 | + with pytest.raises(RuntimeError, match="Cannot change format"): |
| 288 | + second.format = av.VideoFormat("bgr0", width=16, height=16) |
| 289 | + with pytest.raises(RuntimeError, match="Cannot change width"): |
| 290 | + second.width = 16 |
| 291 | + with pytest.raises(RuntimeError, match="Cannot change height"): |
| 292 | + second.height = 16 |
| 293 | + with pytest.raises(RuntimeError, match="Cannot change pix_fmt"): |
| 294 | + second.pix_fmt = "bgr0" |
| 295 | + |
271 | 296 | def test_stream_index(self) -> None: |
272 | 297 | with av.open(self.sandboxed("output.mov"), "w") as output: |
273 | 298 | vstream = output.add_stream("mpeg4", 24) |
|
0 commit comments