将WebM转换为MP4即时

问题描述 投票:3回答:1

我正在尝试将远程WebM文件即时转换为MP4。这应该发生而不写任何东西到磁盘。此外,能够尽快流出结果会很棒。

这是我没有实际转换的烧瓶功能,因此您可以了解流式传输。

@app.route("/stream/mp4")
def as_mp4():
    url = "http://video.webmfiles.org/big-buck-bunny_trailer.webm"
    r = requests.get(url, stream=True)

    def stream():
        # convert it here
        for chunk in r.iter_content(chunk_size=1024):
            yield chunk
        # end for
    # end def
    return Response(stream(), mimetype="video/mp4")
# end def
python mp4 webm
1个回答
1
投票

你不会得到你期望的结果。 MP4使用“索引”(称为moov框),用于解析原始/分块的基本流(在mdat框中)。由于此索引包含每个帧的持续时间和大小,因此在处理完最后一帧之前索引不可用。因此,即使您将数据发送到客户端,客户端也无法播放视频,直到收到整个视频。

© www.soinside.com 2019 - 2024. All rights reserved.