通过 Java servlet 将多个 FLV 文件作为单个文件进行流式传输

发布于 2024-10-31 13:47:02 字数 380 浏览 2 评论 0原文

我正在尝试实现一个在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稀香 2024-11-07 13:47:02

除了初始 FLV 标头和各个帧描述之外,您不需要元数据。只要您的 FLV 帧正确且自动地启动和停止,您所做的事情对我来说似乎是很有可能的。 (我已经考虑过做类似的事情,已经编写了 FLV 解析器。) 确保不要发送 Length 标头。 ;) 有两件事可能会让这一切变得更容易完成:

  1. 确保您以较小的关键帧间隔对视频进行编码。您将无法以比此更精细的分辨率在剪辑之间跳转。任何低于 1 秒的值都可能会出现问题,视频速率要高得多。
  2. 将所有视频文件预先解析成片段。当调用 Servlet 时,
    1. 发送 FLV 标头
    2. 读取整个段文件并将其写入客户端
      1-要切换视频,请移至另一组片段文件

假设您要从头开始发送每个原始文件的示例:

send(FLV_HEADER)
i = 0
while(send file 1 condition == true)
   send(file-1-segment i++)
i = 0
while(send file 2 condition == true)
   send(file-2-segment i++)

(或者,您可以映射一些索引并使用它们从文件中间读取帧。去过那里,做到了。)

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. ensure you've encoded your video with smallish key frame interval. You won't be able to jump between clips at any finer of a resolution than this. Anything less that 1s is probably going to be problematic, much higher video rates.
  2. pre-parse all your video files into segments. When the servlet is called,
    1. send the FLV header
    2. read and write whole segment files to the client
      1- to switch videos, move to another group of segment files

Example that assumes you want to send each original file from the start:

send(FLV_HEADER)
i = 0
while(send file 1 condition == true)
   send(file-1-segment i++)
i = 0
while(send file 2 condition == true)
   send(file-2-segment i++)

(Alternatively you could map some indexes and use them to read frames from the middle of a file. Been there, done that.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文