即时将WebM转换为MP4 [英] Convert WebM as MP4 on the fly

查看:130
本文介绍了即时将WebM转换为MP4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将远程WebM文件即时转换为MP4.这应该在不向磁盘写入任何内容的情况下发生.此外,能够尽快流式传输结果将是很棒的.

I am trying to convert a remote WebM file on the fly to MP4. This should happen without writing anything to disk. Furthermore it would be great to be able to stream out results as soon as possible.

这是我的flask函数,没有实际的转换,因此您可以了解流式传输.

This is my flask function without the actual conversion, so you get a idea of the streaming.

@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

推荐答案

您不会获得预期的结果. MP4使用索引"(称为moov框),该索引用于解析原始/分块的基本流(在mdat框中).由于此索引包含每个帧的持续时间和大小,因此只有在处理完最后一帧后该索引才可用.因此,即使您将数据发送给客户端,客户端也无法在收到全部内容之前播放视频.

You are not going to get the results you expect. MP4 uses an "index" (called the moov box) that is used to parse the raw/chunked elementary streams (in the mdat box). Because this index contains the duration and size of each frame, the index is not available until the last frame is processed. So, even if you send the data to the client, the client can’t play the video until the entire thing is received.

这篇关于即时将WebM转换为MP4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆