开发者

Streaming multiple FLV files over a Java servlet as a single file

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 o开发者_开发问答f 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?


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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜