将 webm 块作为独立视频播放 [英] Playing webm chunks as standalone video

查看:25
本文介绍了将 webm 块作为独立视频播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一些代码,可以让 MediaRecorder API 捕获音频和视频,然后使用 ondataavailable 函数通过 websockets 将相应的 webm 文件 blob 发送到服务器.然后服务器通过 websockets 将这些 blob 发送到客户端,客户端使用媒体源扩展 API 将视频放在一个缓冲区中.

I've built some code that will get the MediaRecorder API to capture audio and video, and then use the ondataavailable function to send the corresponding webm file blobs up to a server via websockets. The server then sends those blobs to a client via websockets which puts the video together in a buffer using the Media Source Extension API.

这很有效,但如果我想在中途开始一个流,我不能只发送最新的 blob,因为 blob 本身是无法播放的.此外,如果我乱序发送 blob,浏览器通常会抱怨音频编码不匹配.

This works well, except that if I want to start a stream partway through, I can't just send the latest blob because the blob by itself is unplayable. Also, if I send the blobs out of order the browsers usually complain that the audio encoding doesn't match up.

我对视频容器、编解码器等的了解并不多,但我的问题是,我如何将这些 blob 作为独立视频播放?我可以以某种方式使用代码将第一个 blob(可单独播放)中的信息添加到其他 blob 上吗?能够在中途播放流的好方法是什么?我会转码,但似乎需要很长时间,因为我想设置实时(或接近)流式传输.

I really don't know as much about video containers, codecs etc as I should to pull this off, but my question is, how can I play those blobs as standalone videos? Can I somehow use code to add the information which is in the first blob (playable on its own) onto the other blobs? What would be a good approach to being able to get the stream playing partway through? I would transcode but it seems to take too long since I want to set up real-time (or close to) streaming.

谢谢!

推荐答案

只有从 MediaRecorder API 收到的第一个 blob 包含一个标头.因此,您需要简单地提取它并将其添加到您的其他 blob 中,以便能够将它们作为独立的 WebM 视频播放.我建议您使用十六进制编辑器等工具验证它是否有效.您可以在服务器上自动执行此过程.

Only the first blob received from the MediaRecorder API contains a header. So you will need to simply extract it and prepend it to your other blobs to be able to play them as standalone WebM videos. I recommend you to verify whether it works by using tools like hex editor. And you can automate this process on your server.

这篇关于将 webm 块作为独立视频播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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