Skip to content

add_mux_stream does not work properly with matroska. #2198

@caffeinism

Description

@caffeinism

Hello. Thank you for the update. I tried to use the add_mux_stream method from yesterday’s update, but I’m getting an error when muxing a Matroska (.mkv) container. Below is the test code.

import av
import numpy as np
from fractions import Fraction

tb = Fraction(1, 24)
cc = av.CodecContext.create("libx264", "w")
cc.width = 1920
cc.height = 1080
cc.time_base = tb
cc.framerate = 1 / tb
cc.pix_fmt = "yuv420p"
cc.bit_rate = 6 * 1024 * 1024
frame = av.VideoFrame.from_ndarray(np.zeros((1080, 1920, 3), dtype=np.uint8))
with av.open("test.mkv", "w") as c:
    s = c.add_mux_stream("libx264", rate=24, width=640, height=640) # Since the shape can change, it doesn't matter...
    for i in range(24):
        frame.pts = i
        frame.time_base = tb
        for p in cc.encode(frame):
            p.stream = s
            c.mux(p)
    for p in cc.encode(None):
        p.stream = s
        c.mux(p)

If you change add_mux_stream to add_stream or convert the MKV file to MP4, this code will work without any issues.

When muxing MP4 files, an error occurs if the width and height are missing, so I tried to include as much information as possible, but nothing seemed to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions