title: How to join discontinuous HLS video and audio?
body: <p>I am streaming long videos which seamlessly loop short video sequences. Thanks to HLS this is possible by having just one video sequence stored and concatenated in a media playlist and separated by #EXT-X-DISCONTINUITY tags</p>
  
  <p><strong>1080_video.m3u8</strong></p>
  
  <pre><code>#EXTM3U
  #EXT-X-VERSION:3
  #EXT-X-ALLOW-CACHE:YES
  #EXT-X-TARGETDURATION:10
  #EXT-X-MEDIA-SEQUENCE:0
  #EXT-X-PLAYLIST-TYPE:VOD
  #EXTINF:10.010000,
  0/1080p_0_000.ts
  #EXTINF:10.010000,
  0/1080p_0_001.ts
  #EXTINF:2.635967,
  0/1080p_0_002.ts
  #EXT-X-DISCONTINUITY
  #EXTINF:10.010000,
  0/1080p_0_000.ts
  #EXTINF:10.010000,
  0/1080p_0_001.ts
  #EXTINF:2.635967,
  0/1080p_0_002.ts
  #EXT-X-DISCONTINUITY 
  ... and so on
  </code></pre>
  
  <p>This works great. Now I´d like to introduce alternate audio renditions so that I can stream these video loops with various audio tracks. For this, I take each of the long audio files I prepared and split them into many small audio files according to the play length of the video segments. I also understood that if you have #EXT-X-DISCONTINUITY in your video playlist your audio playlist must also have them. </p>
  
  <p><strong>audio.m3u8</strong></p>
  
  <pre><code>#EXTM3U
  #EXT-X-VERSION:3
  #EXT-X-TARGETDURATION:10
  #EXT-X-MEDIA-SEQUENCE:0
  #EXTINF:10.005333,
  s000_00.ts
  #EXTINF:10.005333,
  s000_01.ts
  #EXTINF:2.688000,
  s000_02.ts
  #EXT-X-DISCONTINUITY
  #EXTINF:10.005333,
  s001_00.ts
  #EXTINF:10.005333,
  s001_01.ts
  #EXTINF:2.688000,
  s001_02.ts
  ... and so on
  </code></pre>
  
  <p>Video and audio come together in the master playlist.</p>
  
  <p><strong>master.m3u8</strong></p>
  
  <pre><code>#EXTM3U
  #EXT-X-VERSION:3
  #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",LANGUAGE="en",NAME="audio",URI="./audio/audio.m3u8"
  #EXT-X-STREAM-INF:BANDWIDTH=4500000,RESOLUTION=1920x1080,FRAME-RATE=29.970,NAME="1080p",AUDIO="aac"
  1080_video.m3u8
  #EXT-X-STREAM-INF:BANDWIDTH=2500000,RESOLUTION=1280x720,FRAME-RATE=29.970,NAME="720p",AUDIO="aac"
  720_video.m3u8
  #EXT-X-STREAM-INF:BANDWIDTH=1300000,RESOLUTION=852x480,FRAME-RATE=29.970,NAME="480p",AUDIO="aac"
  480_video.m3u8
  </code></pre>
  
  <p>This doesn´t work. It starts playing with video and audio but stalls on the first DISCONTINUITY tag. </p>
  
  <p>My questions:</p>
  
  <ol>
  <li>is what I want to achieve possible at all? taking any audio file and put it together with video by ensuring segment lengths and discontinuity is roughly aligned?</li>
  <li>roughly aligned because it is almost impossible to get more precise than what I have above. Segment lengths slightly differ by a few milliseconds. I know HLS players can deal with it but what if discontinuity comes into play? May this be the reason why it is not working for me? </li>
  </ol>