如何通过 servlet 提供内部 ip 摄像机 mjpeg 流?
我正在开发一个项目,其中有一个简单的 ip 摄像机,它有一个带有内部地址和 Web 服务器的 mjpg 流。我想通过我的 servlet 提供摄像机的馈送,以便摄像机不需要每次安装时进行端口转发。我的理想情况是用户只需输入 mjpg 位置的 URL(位于其网络上),servlet 将处理其余部分。
我对如何开始实现这一点非常无能为力,或者是否可能,因为我自己实际上没有创建 mjpg 流,我正在使用已经存在的流。有没有办法做到这一点而不向我的网络服务器发出大量请求?
我的另一个烦恼是我只能使用可以在 J2ME 中工作的库。
I'm working on a project where I have a simple ip camera that has an mjpg stream with an internal address and a web server. I would like to serve the camera's feed through my servlet so that the camera does not require port forwarding for each installation. My ideal situation would be that the user would only enter the URL for the mjpg's location (located on their network) and the servlet would handle the rest.
I'm pretty clueless on how to begin implementing this or if it's even possible as I'm not actually creating the mjpg stream myself, I'm using the one that already exists. Is there a way to do this without making an obscene amount of requests to my web server?
An additional thorn in my side is that I'm restricted to libraries that would work in J2ME.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 servlet 中,您可以简单地检查 HttpRequestObject 的 URL、方法和可能的接受标头,然后使用相应摄像机的 IP 地址创建 HttpURLConnection,建立连接。当您从相机收到响应时,从响应中复制适当的条目并将它们设置在 ServletResponse 对象中,然后获取相机响应输入流和客户端请求的输出流,并将字节从一个流复制到另一个流,并在完成后关闭所有内容。
如果您可以部署 Jersey(JAX-RS 参考实现)之类的东西,那就更容易了。
In a servlet, you can simply inspect the HttpRequestObject for the URL, method, and probably accept header, then create an HttpURLConnection with the ip address of the appropriate camera, make the connection. When you get a response back from the camera, copy the appropriate entries from the response and set them in the ServletResponse object, and then get the camera response input stream and the output stream for the client's request and copy the bytes from one stream to another, and close everything up when you're done.
If you can deploy something like Jersey, the JAX-RS reference implementation, this would be even easier.
好的。那么您基本上想通过单个 servlet 代理连接到的多个摄像机?
应该不会太难。您只需在 servlet 中打开与所请求 URL 的套接字连接。
假设您使用 HTTP,如果您有“http://myservlet/servlet?url=http://camera_url_here”的请求,您应该能够打开与相机 URL 的连接并写入收到的字节到 HttpServletResponse 的输出流。您可能希望将套接字连接固定在地图中,这样就不会不必要地两次连接到同一台摄像机。不要忘记在 HttpServletResponse 对象中复制/设置正确的 MIME 类型。
您是否看过http://www.videolan.org/vlc/streaming.html ?我很确定它已经可以做到这一点。
Ok. So you basically want to proxy several cameras to be connected to via a single servlet?
It shouldn't be too hard. You just need to open up a socket connection to the requested URL in your servlet.
Assuming you're using HTTP, if you had a request for "http://myservlet/servlet?url=http://camera_url_here", you should just be able to open up a connection to the camera URL and write the bytes received to the HttpServletResponse's Outputstream. You might want to stick your socket connections in a Map, so that you don't needlessly connect to the same camera twice. Don't forget to copy/set the correct MIME types in the HttpServletResponse object.
Have you looked at http://www.videolan.org/vlc/streaming.html ? I'm pretty sure it can already do this.