开发者

How do I use nginx to reverse-proxy an IP camera's mjpeg stream?

I'm using nginx on OpenWRT to reverse-proxy a motion-jpeg feed from an IP camera, but I'm experiencing lag o开发者_如何转开发f up to 10-15 seconds, even at quite low frame sizes and rates. With the OpenWRT device removed from the path, the camera can be accessed with no lag at all.

Because of the length of the delay (and the fact that it grows with time), this looks like some kind of buffering/caching issue. I have already set proxy_buffering off, but is there something else I should be watching out for?

Thanks.


I installed mjpg-streamer on an Arduino Yun, and then in my routers settings setup port forwarding whitelisted to my webserver only.

Here is my Nginx config which lives in the sites-enabled directory.

server {
  listen      80;
  server_name cam.example.com;
  error_log /var/log/nginx/error.cam.log;
  access_log /var/log/nginx/access.cam.log;

  location    / {
    set $pp_d http://99.99.99.99:9999/stream_simple.html;
    if ( $args = 'action=stream' ) {
      set $pp_d http://99.99.99.99:9999/$is_args$args;
    }
    if ( $args = 'action=snapshot' ) {
      set $pp_d http://99.99.99.99:9999/$is_args$args;
    }

    proxy_pass $pp_d;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host:$server_port;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Port $server_port;
    proxy_set_header X-Request-Start $msec;
  }
}


I never got this working to my satisfaction with nginx. Depending on your specific needs, two solutions which may be adequate:

  • if you can tolerate the stream being on a different port, pass it through using the port forwarding feature of OpenWRT's built-in firewall.

  • use the reverse-proxy capabilities of tinyproxy. The default package has the reverse-proxy capabilities disabled by a flag, so you need to be comfortable checking out and building it yourself. This method is definitely more fiddly, but does also work.

I'd still be interested to hear of anyone who gets this working with nginx.


I have Nginx on Openwrt BB (wndr3800) reverse-proxying to a dlink 932LB1 ip cam, and it's working nicely. No significant lag, even before I disabled proxy_buffering. If I have a lot of stuff going over the network, the video can get choppy, but no more than it does with a straight-to-camera link from the browser (or from any of my ip cam apps). So... it is possible.

Nginx was the way to go for me. I tried tinyproxy & lighttpd for the reverse proxying, but each has missing features on OpenWrt. Both tinyproxy and lighttpd require custom compilation for the full reverse proxy features, and (AFAIK) lighttpd will not accept FQDNs in the proxy directive.

Here's what I have going:

  • Basic or digest auth on public facing Nginx provides site-wide access control.
  • I proxy my CGI scripts (shell, haserl, etc) to Openwrt's uhttpd.
  • Tightly controlled reverse-proxy to the camera mjpeg & jpeg API, no other camera functions are exposed to the public.
  • Camera basic-auth handled by Nginx (proxy_set_header), so no backend authorization code exposed to public.
  • Relatively small footprint (no perl, apache, ruby, etc).

I would include my nginx.conf here, except there's nothing unusual about it... just the bare bones proxy stuff. You might try tcpdump or wireshark to see what's cluttering your LAN, if traffic is indeed your culprit.

But it sounds like something about your router is the cause of the delay. Maybe the hardware just can't handle the cpu/traffic load, or there could be something else on your Openwrt setup that is hogging the highway. Is your video smooth and just delayed? Or are you seeing seriously choppy video? The lengthening delay you mention does sound like a buffer/cache thing... but I don't know what would be doing that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜