通过 Java servlet 将多个 FLV 文件作为单个文件进行流式传输
我正在尝试实现一个在 Tomcat 上运行的 Java servlet,能够将多个 FLV 文件流式传输到具有 JWPlayer 的客户端浏览器。问题是我必须一次流式传输多个文件,有时从第一个剪辑的中间开始流式传输,并且我需要 JWPlayer 认为文件持续时间是所有剪辑组合的持续时间。
如果我将所有剪辑合并到一个 FLV 文件中,注入元数据(使用 yamdi),然后对其进行流式传输,我的 servlet 将运行良好。但这可能非常耗时。我尝试向播放器发送我首先从中间流式传输的文件的元信息,然后继续从中间流式传输它,但这似乎不起作用。我尝试摆弄元数据中的持续时间参数,但无济于事。
我认为这是因为当我从剪辑中间开始流式传输时我跳过了标签。在 servlet 发送字节流之前,人类是否可以在处理字节流时构造标签?
I am trying to implement a Java servlet that runs on Tomcat, capable of streaming multiple FLV files to client browsers having JWPlayer. The catch is I have to stream multiple files one at a time and sometimes start streaming from the middle of the first clip and I need JWPlayer to think that the file duration is the duration of all the clips combined.
My servlet would work well if I merged all of the clips to one single FLV file, injected the metadata (using yamdi) and then streamed it. But this can be pretty time consuming. I've tried sending the player the meta information for the file that I stream from the middle first and then go ahead and stream it from the middle but this doesn't seem to work. I've tried fiddling with the duration parameter in the metadata to no avail.
I think that this is because I'm skipping tags when i start to stream from the middle of the clip. Would it be humanly possible to construct tags while processing the byte stream before the servlet sends it out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了初始 FLV 标头和各个帧描述之外,您不需要元数据。只要您的 FLV 帧正确且自动地启动和停止,您所做的事情对我来说似乎是很有可能的。 (我已经考虑过做类似的事情,已经编写了 FLV 解析器。) 确保不要发送 Length 标头。 ;) 有两件事可能会让这一切变得更容易完成:
1-要切换视频,请移至另一组片段文件
假设您要从头开始发送每个原始文件的示例:
(或者,您可以映射一些索引并使用它们从文件中间读取帧。去过那里,做到了。)
You don't need the meta data, other than the initial FLV header and individual frame descriptions. As long as your FLV frames are correctly and atomically started and stopped, what you are doing seems very possible to me. (I had considered doing something similar, having already written an FLV parser.) Be sure not to send a Length header. ;) Two things might make all of this much easier to accomplish:
1- to switch videos, move to another group of segment files
Example that assumes you want to send each original file from the start:
(Alternatively you could map some indexes and use them to read frames from the middle of a file. Been there, done that.)