title: How to enable LHLS in FFMPEG 4.1?
body: <p>I am trying to create a low latency CMAF video stream using FFMPEG.
  To do so, I would like to enable the <code>lhls</code> option in FFMPEG in order to have the <code>#EXT-X-PREFETCH</code> tag written in the HLS manifest.</p>
  
  <h3>From the FFMPEG doc :</h3>
  
  <p><a href="https://www.ffmpeg.org/ffmpeg-all.html" rel="noreferrer">https://www.ffmpeg.org/ffmpeg-all.html</a></p>
  
  <blockquote>
    <p>Enable Low-latency HLS(LHLS). Adds #EXT-X-PREFETCH tag with current >segment’s URI. Apple doesn’t have an official spec for LHLS. Meanwhile >hls.js player folks are trying to standardize a open LHLS spec. The >draft spec is available in <a href="https://github.com/video-dev/hlsjs-" rel="noreferrer">https://github.com/video-dev/hlsjs-</a>>rfcs/blob/lhls-spec/proposals/0001-lhls.md This option will also try >to comply with the above open spec, till Apple’s spec officially >supports it. Applicable only when streaming and hls_playlist options >are enabled. This is an experimental feature.</p>
  </blockquote>
  
  <h3>I am using the following command with FFMPEG 4.1 :</h3>
  
  <pre class="lang-sh prettyprint-override"><code>ffmpeg -re -i ~/Documents/videos/BigBuckBunny.mp4 \
      -map 0 -map 0 -map 0 -c:a aac -c:v libx264 -tune zerolatency \
      -b:v:0 2000k -s:v:0 1280x720 -profile:v:0 high \
      -b:v:1 1500k -s:v:1 640x340  -profile:v:1 main \
      -b:v:2 500k -s:v:2 320x170  -profile:v:2 baseline \
      -bf 1 \
      -keyint_min 24 -g 24 -sc_threshold 0 -b_strategy 0 -ar:a:1 22050 -use_timeline 1 -use_template 1 \
      -window_size 5 -adaptation_sets "id=0,streams=v id=1,streams=a" \
      -hls_playlist 1 -seg_duration 1 -streaming 1  -strict experimental -lhls 1 -remove_at_exit 1 \
      -f dash manifest.mpd
  
  </code></pre>
  
  <p>The kind of HLS manifest I obtained for a specific resolution :</p>
  
  <pre><code>#EXTM3U
  #EXT-X-VERSION:6
  #EXT-X-TARGETDURATION:1
  #EXT-X-MEDIA-SEQUENCE:8
  #EXT-X-MAP:URI="init-stream0.mp4"
  #EXTINF:0.998458,
  #EXT-X-PROGRAM-DATE-TIME:2019-06-21T18:13:56.966+0900
  chunk-stream0-00008.mp4
  #EXTINF:0.998458,
  #EXT-X-PROGRAM-DATE-TIME:2019-06-21T18:13:57.964+0900
  chunk-stream0-00009.mp4
  #EXTINF:0.998458,
  #EXT-X-PROGRAM-DATE-TIME:2019-06-21T18:13:58.963+0900
  chunk-stream0-00010.mp4
  #EXTINF:0.998458,
  #EXT-X-PROGRAM-DATE-TIME:2019-06-21T18:13:59.961+0900
  chunk-stream0-00011.mp4
  #EXTINF:1.021678,
  #EXT-X-PROGRAM-DATE-TIME:2019-06-21T18:14:00.960+0900
  chunk-stream0-00012.mp4
  ...
  
  </code></pre>
  
  <p>As you can see the <code>#EXT-X-PREFETCH</code> tag <strong>is missing</strong>.</p>
  
  <p>Any help would be highly appreciated.</p>
  
  <h1>Edit</h1>
  
  <p>I also compiled FFmpeg from its master branch by doing the following :</p>
  
  <h3>nasm</h3>
  
  <pre><code>sudo apt-get install nasm mingw-w64
  </code></pre>
  
  <h3>Codecs</h3>
  
  <pre><code>sudo apt-get install libx265-dev libnuma-dev libx264-dev libvpx-dev libfdk-aac-dev libmp3lame-dev libopus-dev
  </code></pre>
  
  <h3>FFmpeg</h3>
  
  <pre><code>mkdir lhls
  cd lhls 
  git init 
  git clone https://github.com/FFmpeg/FFmpeg.git
  cd FFmpeg 
  git checkout master
  </code></pre>
  
  <h3>AOM (inside FFmpeg dir)</h3>
  
  <pre><code>git -C aom pull 2&gt; /dev/null || git clone --depth 1 https://aomedia.googlesource.com/aom &amp;&amp; \
  mkdir -p aom_build &amp;&amp; \
  cd aom_build &amp;&amp; \
  PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED=off -DENABLE_NASM=on ../aom &amp;&amp; \
  PATH="$HOME/bin:$PATH" make &amp;&amp; \
  make install
  cd..
  </code></pre>
  
  <h3>Compiling</h3>
  
  <pre><code>PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
    --prefix="$HOME/ffmpeg_build" \
    --pkg-config-flags="--static" \
    --extra-cflags="-I$HOME/ffmpeg_build/include" \
    --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
    --extra-libs="-lpthread -lm" \
    --bindir="$HOME/bin" \
    --enable-gpl \
    --enable-libaom \
    --enable-libass \
    --enable-libfdk-aac \
    --enable-libfreetype \
    --enable-libmp3lame \
    --enable-libopus \
    --enable-libvorbis \
    --enable-libvpx \
    --enable-libx264 \
    --enable-libx265 \
    --enable-nonfree &amp;&amp; \
  PATH="$HOME/bin:$PATH" make 
  </code></pre>
  
  <p>Unfortunately, the <code>#EXT-X-PREFETCH</code> is still missing in the HLS Manifest.</p>
  
  <p>I also tried nightly builds from <a href="https://ffmpeg.zeranoe.com/builds/" rel="noreferrer">https://ffmpeg.zeranoe.com/builds/</a> , same result.</p>
  
  <p>Any help would be highly appreciated.</p>
  
  <h2>EDIT 2  :resolved</h2>
  
  <p>Thanks to @aergistal and @Gyan , the <code>#EXT-X-PREFETCH</code> tag is now present in my HLS manifest.</p>
  
  <p>Here the FFMPEG command I am using: </p>
  
  <pre class="lang-sh prettyprint-override"><code>./ffmpeg -re -i ~/videos/BigBuckBunny.mp4 -loglevel debug \
    -map 0 -map 0 -map 0 -c:a aac -c:v libx264 -tune zerolatency \
    -b:v:0 2000k -s:v:0 1280x720 -profile:v:0 high -b:v:1 1500k -s:v:1 640x340  -profile:v:1 main -b:v:2 500k -s:v:2 320x170  -profile:v:2 baseline -bf 1 \
   -keyint_min 24 -g 24 -sc_threshold 0 -b_strategy 0 -ar:a:1 22050 -use_timeline 1 -use_template 1 -window_size 5 \
   -adaptation_sets "id=0,streams=v id=1,streams=a" -hls_playlist 1 -seg_duration 3 -streaming 1 \
   -strict experimental -lhls 1 -remove_at_exit 0 -master_m3u8_publish_rate 3 \
   -f dash -method PUT -http_persistent 1  https://example.com/manifest.mpd
  </code></pre>
  
  <p>Apparently the mime types are not passed to the server &amp; FFmpeg seems to ignore the <code>-headers</code> option. </p>