This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Creating MJPEG-stream/video with servlet, is this even possible? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Creating MJPEG-stream/video with servlet, is this even possible?" Watch "Creating MJPEG-stream/video with servlet, is this even possible?" New topic
Author

Creating MJPEG-stream/video with servlet, is this even possible?

Nems Vedek
Greenhorn

Joined: Sep 26, 2005
Posts: 9
Hello all,

I've created a servlet that fetches single images outside the servlet container/web server based on the parameters I give it and it works like this



The thing I was wondering could it be possible to create a somekind of a continuous stream by modifying the MIME content type and outputting all the images in the ...



... directory?

If not, any ideas how to create a stream/video from n+1 jpeg-images?

Thanks.
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
It's quite possible and will work. What kind of clients do you expect? If just a regular browser, then mozila based browsers will be the best. I use a similar technology for a chat program:
http://7bee.j2ee.us/chathouse/readme.htm
For content type look here: http://www.ltsw.se/knbase/internet/multipart.htp


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
Nems Vedek
Greenhorn

Joined: Sep 26, 2005
Posts: 9
Originally posted by dema rogatkin:
It's quite possible and will work. What kind of clients do you expect? If just a regular browser, then mozila based browsers will be the best. I use a similar technology for a chat program:
http://7bee.j2ee.us/chathouse/readme.htm



Thanks for the reply. Yes, I'm using browser as a client. Checked out your URL but every link gives me 404 on that page (?)
[ January 23, 2006: Message edited by: Nems Vedek ]
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
Sorry it was awhile, so some links may not work anymore. Generally do search on multipart/x-mixed-replace content type. It allows <b>server push</b> model, so for mozila browsers you can just continuously send jpegs and one will be replaced by another.
Nems Vedek
Greenhorn

Joined: Sep 26, 2005
Posts: 9
Originally posted by dema rogatkin:
It allows <b>server push</b> model, so for mozila browsers you can just continuously send jpegs and one will be replaced by another.


Yeah, been reading about the "server push"-technology and it seems it is just the thing I need.

But then I found out a page that said "IE doesn't support server push and NN6 has severe bugs in this area."

Aarggh. Sadly IE is still the most popular browser and I really would like to have an feature that worked with IE also.
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
Actually IE supports it nicely. However it won't work for you since new pages just appended.
Nems Vedek
Greenhorn

Joined: Sep 26, 2005
Posts: 9
Originally posted by dema rogatkin:
Actually IE supports it nicely. However it won't work for you since new pages just appended.


Hmm, do you know is there a way to send n+1 images without appending new pages?

The servlet I wrote works just fine. Although for some reason I must hit refresh/F5 with firefox in order to get it started. With Opera it works just fine. Any idea what's wrong?

Here's some code:

dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
Where did you get implementation of MultipartResponse? Many of them are floating around. I do not need to refresh first page for FF. Regarding IE, check HTTP spec, I remember there were some refresh headers, so maybe you can enforce IE to start from begining every part adding such headers in a part headers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating MJPEG-stream/video with servlet, is this even possible?
 
Similar Threads
Passing multiple images to Browser
How to make sense of my binary data
Record count
Get File from Server as Byte Array
how to show html page