|
1 | 1 | import functools |
| 2 | +import io |
2 | 3 | import os |
3 | 4 | import pathlib |
4 | 5 | from fractions import Fraction |
@@ -52,6 +53,34 @@ def make_h264_test_video(path: str) -> None: |
52 | 53 |
|
53 | 54 |
|
54 | 55 | class TestDecode(TestCase): |
| 56 | + def test_decode_stream_without_codec_context(self) -> None: |
| 57 | + buffer = io.BytesIO() |
| 58 | + with av.open(buffer, "w", format="mp4") as output: |
| 59 | + stream = output.add_mux_stream("h264", width=16, height=16) |
| 60 | + packet = av.Packet(b"invalid") |
| 61 | + packet.stream = stream |
| 62 | + packet.pts = packet.dts = 0 |
| 63 | + packet.time_base = Fraction(1, 1000) |
| 64 | + output.mux(packet) |
| 65 | + |
| 66 | + # Keep the MP4 video stream while making its codec unknown to FFmpeg. |
| 67 | + data = buffer.getvalue().replace(b"avc1", b"zzzz") |
| 68 | + with av.open(io.BytesIO(data)) as container: |
| 69 | + stream = container.streams.video[0] |
| 70 | + assert stream.codec_context is None |
| 71 | + with pytest.raises(av.DecoderNotFoundError): |
| 72 | + list(container.decode(stream)) |
| 73 | + |
| 74 | + def test_mux_stream_without_codec_context(self) -> None: |
| 75 | + with av.open(io.BytesIO(), "w", format="mp4") as output: |
| 76 | + stream = output.add_mux_stream("h264", width=16, height=16) |
| 77 | + assert stream.codec_context is None |
| 78 | + with pytest.raises(av.EncoderNotFoundError): |
| 79 | + stream.encode(None) |
| 80 | + |
| 81 | + # A bitstream filter only needs to update codecpar for a mux stream. |
| 82 | + av.BitStreamFilterContext("h264_mp4toannexb", "h264", out_stream=stream) |
| 83 | + |
55 | 84 | def test_decoded_video_frame_count(self) -> None: |
56 | 85 | container = av.open(fate_suite("h264/interlaced_crop.mp4")) |
57 | 86 | video_stream = next(s for s in container.streams if s.type == "video") |
|
0 commit comments