streaminglighttpdmjpeg

reverse proxy motion jpeg camera stream using lighttpd


I have an rtsp camera stream I convert to a motion jpeg stream using ffmpeg-server.

ffmpeg-server provides the motion jpeg stream under http://localhost:8090/still.jpg and http://localhost:8090/live.mjpg

I want to proxy this stream using lighttpd so that it is availible at http://localhost:8080/live.mjpg (note the port change)

my lighttpd config has a proxy entry and I can get the still.jpg but not the live.mjpg.

$HTTP["url"] =~ "(^/still.jpg)" {   
  proxy.server = ( "" => ("" => ( "host" => "localhost", "port" => 8090 ))) 
}
$HTTP["url"] =~ "(^/live.mjpg)" {
    proxy.server = ( "" => ("" => ( "host" => "localhost", "port" => 8090 ))) 
}

I'm not sure, but what I think is happening is that lighttpd is recieving the request and forwarding it correctly, howeverm because the request to the backend never completes,the response is never forwarded to the client. Is there a way to asklighttpd to forward the response in small chunks as available?


Solution

  • Turns out you can use an option to stream the response data.

    server.stream-response-body = 2
    

    As mentioned by ocodo, setting 2 will block the backend if the client is not able to consume the stream fast enough. Probably it is better to use setting 1 in some usecases. For my usecase I prefer to have a reduced temporary file size, and accept the loss of some stream data if the client can't keep up. (ffmpeg will drop frames if it gets blocked)

    https://redmine.lighttpd.net/projects/lighttpd/wiki/Server_stream-response-bodyDetails