diff --git a/av/container/output.pyx b/av/container/output.pyx index 1227c4340..8fad652d4 100644 --- a/av/container/output.pyx +++ b/av/container/output.pyx @@ -144,14 +144,15 @@ cdef class OutputContainer(Container): :param template: Copy codec from another :class:`~av.stream.Stream` instance. :param \\**kwargs: Set attributes for the stream. :rtype: The new :class:`~av.stream.Stream`. - """ + cdef const lib.AVCodec *codec + cdef Codec codec_obj - if not template.codec_context: - raise ValueError("template has no codec context") - - cdef Codec codec_obj = Codec(template.codec_context.codec.name, "w") - cdef const lib.AVCodec *codec = codec_obj.ptr + if template.type == "subtitle": + codec_obj = template.codec_context.codec + else: + codec_obj = Codec(template.codec_context.codec.name, "w") + codec = codec_obj.ptr # Assert that this format supports the requested codec. if not lib.avformat_query_codec(self.ptr.oformat, codec.id, lib.FF_COMPLIANCE_NORMAL): @@ -182,13 +183,6 @@ cdef class OutputContainer(Container): cdef Stream py_stream = wrap_stream(self, stream, py_codec_context) self.streams.add_stream(py_stream) - if template.type == "video": - py_stream.time_base = kwargs.pop("time_base", 1 / template.average_rate) - elif template.type == "audio": - py_stream.time_base = kwargs.pop("time_base", 1 / template.rate) - else: - py_stream.time_base = kwargs.pop("time_base", Fraction(0, 1)) - for k, v in kwargs.items(): setattr(py_stream, k, v) diff --git a/tests/test_encode.py b/tests/test_encode.py index e472106eb..c107aa044 100644 --- a/tests/test_encode.py +++ b/tests/test_encode.py @@ -240,7 +240,9 @@ def test_subtitle_muxing(self) -> None: output.close() output_bytes.seek(0) - # assert output_bytes.getvalue() == b"" + assert output_bytes.getvalue().startswith( + b"\x00\x00\x00\x1cftypisom\x00\x00\x02\x00isomiso2mp41\x00\x00\x00\x08free" + ) class TestEncodeStreamSemantics(TestCase):