title: Streaming from Icecast to Facebook Live with ffmpeg on Ubuntu 16.04
body: <p>I have a webradio streamed by Liquidsoap+Icecast on a DigitalOcean droplet (Ubuntu 16.04), and I want to combine this audio stream with a simple jpeg image with ffmpeg, transform it to a video stream and send it to Facebook live.</p>
  
  <p>Facebook Live specifications :</p>
  
  <blockquote>
    <p>Video Format :</p>
    
    <p>We accept video in maximum 720p (1280 x 720) resolution, at 30 frames
    per second. (or 1 key frame every 2 seconds). You must send an I-frame
    (keyframe) at least once every two seconds throughout the stream..
    Recommended max bit rate is 4000 Kbps. Titles must be less than 255
    characters otherwise the stream will fail. The Live API accepts H264
    encoded video and AAC encoded audio only. </p>
    
    <p>Video Length :</p>
    
    <p>240 minute maximum length, with the exception of continuous live (see
    above). 240 minute maximum length for preview streams (either through
    Live dialog or publisher tools). After 240 minutes, a new stream key
    must be generated. </p>
    
    <p>Advanced Settings :</p>
    
    <p>Pixel Aspect Ratio: Square. Frame Types: Progressive Scan. Audio
    Sample Rate: 44.1 KHz. Audio Bitrate: 128 Kbps stereo. Bitrate
    Encoding: CBR.</p>
  </blockquote>
  
  <p>And the ffmpeg command I tried :</p>
  
  <pre><code>ffmpeg -loop 1 -i radio-background.jpg -thread_queue_size 20480 -i http://localhost:8000/radio -framerate 30 -r 30 -acodec aac -strict -2 -c:v libx264 -strict experimental -b:a 128k -pix_fmt yuvj444p -x264-params keyint=60 -b:v 256k -minrate 128k -maxrate 512k -bufsize 768k -f flv 'rtmp://rtmp-api.facebook.com:80/rtmp/&lt;fb-streaming-key&gt;'
  </code></pre>
  
  <p>This is actually working, as Facebook receives the live video and allows me to publish it. But I can't figured out why there is a lag almost every 2 or 3 seconds. I asked different people to watch the test video, and everyone gets the same problem : every 2 or 3 seconds the playing "freezes" for half a second and seems to load the video, I even can see the loading icon spinning on the screen.</p>
  
  <p>I tried different combinations of values for the following options : -thread_queue_size / -b:v / -minrate / -maxrate / -bufsize. Nothing seems to produce any change. </p>
  
  <p>Video streaming is new for me, I'm not really confortable with the options listed before, so I think I'm missing something here... </p>
  
  <p>Also, note that the icecast audio stream perfectly works, and according to DigitalOcean graphs, the server is not overloaded. So I think my ffmpeg command is wrong.</p>
  
  <p>What ffmpeg parameters would be working for that case?</p>