title: adaptive compression with ffmpeg
body: <p>I'm currently developing an application which will enable visualizing images from different sources (mostly IP cameras) in browser (in a HTML5 video element). The UI will allow for matrix view so, normally 16 or more cameras will be displayed at the same time.
  From cameras I get MJPEG streams or JPEG images (which I "convert" to MJPEG streams). So, for a camera, I have an MJPEG stream which I set as input for ffmpeg. I instruct ffmpeg to convert this to MP4 &amp; H.264, and expose the output as a tcp stream, like this:</p>
  
  <p>ffmpeg -f mjpeg -i "<a href="http://localhost/video.mjpg" rel="nofollow">http://localhost/video.mjpg</a>" -f mp4 -vcodec libx264 "tcp://127.0.0.1:5001?listen"</p>
  
  <p>This works just fine on localhost, I get the stream displayed in the web page, at best quality.</p>
  
  <p>But this has to work in various network conditions. I played a bit with chrome throttling settings, and noticed that if the network speed is just a bit below the required speed (given by the current compression settings I use in ffmpeg), the things start to go wrong: from stream start being delayed (so, no longer a live stream), up to complete freeze of 'live' image in browser.</p>
  
  <p>What I need is an "adaptive" way to do the compression, in relation with current network speed.</p>
  
  <p>My questions are:</p>
  
  <ul>
  <li><p>is ffmpeg able to handle this, to adapt to network conditions - automatically reduce compression quality when speed is low; so the image in browser will be lower quality, but live (which is most important in my case)</p></li>
  <li><p>if not, is there a way to workaround this?</p></li>
  <li><p>is there a way to detect the network bottleneck? (and then restart ffmpeg with lower compression parameters; this is not a dynamic adaptive streaming, but better than nothing)</p></li>
  </ul>
  
  <p>Thank you in advance!</p>