title: H264 WebRTC video streamed from ffmpeg through Janus is very choppy on playback
body: <p>Trying to stream video through following chain: h264/mp4 file on local instance storage (AWS)->ffmpeg->rtp->Janus on same instance->WebRTC playback (Chrome/mac). Resulting video is choppy even as none of the resources seem overloaded (CPU/memory/network bandwidth on any of the systems involved). I also use a Coturn TURN server, it is also not loaded at all and bandwidth is plentiful.</p>
  
  <p>Tried switching codecs and it didn't help apart from vp8 which while worked (kind of - choppiness was still there but very rare and acceptable), resulted in such a high CPU consumption that practically it's unacceptable.</p>
  
  <p><code>ffmpeg -re -stream_loop -1 -i ./short.mp4 -s 426x240 -c:v libx264 -profile:v baseline -b:v 1M -r 24 -g 60 -an -f rtp rtp://127.0.0.1:5004</code></p>
  
  <p>resulting SDP is:</p>
  
  <pre><code>o=- 0 0 IN IP4 127.0.0.1
  s=No Name
  c=IN IP4 127.0.0.1
  t=0 0
  a=tool:libavformat 58.20.100
  m=video 5004 RTP/AVP 96
  b=AS:1000
  a=rtpmap:96 H264/90000
  a=fmtp:96 packetization-mode=1
  </code></pre>
  
  <p>stream is set up with Janus API as</p>
  
  <pre><code>            "janus" : "message",
              "transaction" : 'Transaction',
          "body": {
                  "request" : "create",
                  "type" : "rtp",
                  "id" : newId,
                  "name": streamId+newId,
                  "audio": false,
                  "video": true,
                  "description" : streamId+newId,
                  "videoport" : 5000+newId*4,
                  "videopt" : 96,
                  "videortpmap": "H264/90000",
                  "secret" : "adminpwd"
              }
          }
  </code></pre>
  
  <p>Tried various options of bw, doesn't help at all. Changing -g (GOP size) to lower values can make choppiness shorter in duration but more frequent. At -g 3 or 4 it is acceptable but the bitrate for tolerable quality, predictably, becomes insane.</p>
  
  <p>Expected result: video plays without choppiness.</p>
  
  <p>My theory of it is it could be one of the following:</p>
  
  <ul>
  <li><p>Either ffmpeg provides data in a way buffer is too small so sometimes Janus needs to send a next packet while it's not ready yet, starving buffer and resulting in interruption - so maybe there is a way to make ffmpeg encode into some kind of a short (half-second or so? buffer to regulate flow). How?</p></li>
  <li><p>Or H264 works too poorly over UDP as it is and there is nothing i could do. Then i got to switch to TCP, but so far attempts to do this has been unsuccessful.</p></li>
  </ul>