Answers.Body: <p>For non-conventional layouts, the native AAC encoder writes a PCE section in the bitstream header as part of the AudioSpecificConfig. However, it does so only at the beginning, therefore subsequent files have AAC streams with this missing.</p>
  
  <p>Workaround is to change to a different packetization scheme for AAC in MPEG-TS.  </p>
  
  <p>Add <code>-hls_ts_options mpegts_flags=latm</code> when generating the HLS package.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-28T07:12:33.127Z
Answers.Text: this seemed to fix the issue, thanks.  (In my case I used `-mpegts_flags latm` directly).  Is there any unintended consequence that may surface from this ?  Having a read through ANSI/SCTE 193-2 2014 suggests that LATM is in fact the preferred encapsulation anyway.
Answers.UserDisplayName: hmedia1
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-28T07:37:15.597Z
Answers.Text: Not all HLS players may accept AAC-LATM.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-27T17:48:37.520Z
Answers.LastActivityDate: 2018-12-28T07:33:34.423Z
Answers.LastEditDate: 2018-12-28T07:33:34.423Z
Answers.UserDisplayName: Gyan
Body: <p>When i use hexadecagonal audio channel layout in an mpegts container, I can receive and play back the stream fine <strong>only if</strong> I configure the hls server to allow serving the very first segment, and then concatenating subsequent segments.  </p>
  
  <p>I.e. If I probe segment 1414:</p>
  
  <pre><code>[mpegts @ 0x7faf58001200] Could not find codec parameters for stream 1 (Audio: aac (LC) ([15][0][0][0] / 0x000F), 0 channels, fltp, 1464 kb/s): unspecified sample rate
  Consider increasing the value for the 'analyzeduration' and 'probesize' options
  
  Input #0, mpegts, from '<strong>1414.ts</strong>':
    Duration: 00:00:02.07, start: 2834.393367, bitrate: 9079 kb/s
    Program 1 
      Stream #0:0[0x100]: Audio: aac (LC) ([15][0][0][0] / 0x000F), <strong>0 channels, fltp, 1430 kb/s</strong>
      Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), <strong>0 channels, fltp, 1464 kb/s</strong>
      Stream #0:2[0x102]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
      Stream #0:3[0x103]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 60 fps, 60 tbr, 90k tbn, 120 tbc</code></pre>
  
  <p><strong>However</strong> if I probe the first segment:</p>
  
  <pre><code>Input #0, mpegts, from '0.ts':
    Duration: 00:00:02.02, start: 1.412033, bitrate: 11598 kb/s
    Program 1 
      Stream #0:0[0x100]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, <strong>16 channels, fltp, 1353 kb/s</strong>
      Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, <strong>16 channels, fltp, 744 kb/s</strong>
      Stream #0:2[0x102]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
      Stream #0:3[0x103]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 60 fps, 60 tbr, 90k tbn, 120 tbc</code></pre>
  
  <p>The playlist file is very simple and looks like this:</p>
  
  <pre><code>#EXTM3U
  #EXT-X-VERSION:3
  #EXT-X-MEDIA-SEQUENCE:0
  #EXT-X-TARGETDURATION:4
  
  #EXTINF:2.000,
  0.ts
  #EXTINF:2.000,
  1.ts
  #EXTINF:2.000,
  2.ts
  #EXTINF:2.000,
  3.ts
  #EXTINF:2.000,
  
  etc ...
  </code></pre>
  
  <p>With say an 8 channel layout, this does not happen.. every segment contains the correct headers.  But my preference is to keep 16 channels because my application at the receiving end uses 16 channel files, and this avoids the need to transcode when downloading.</p>
  
  <p>I am using FFmpeg to upload the mpegts stream.</p>
  
  <p>Any insight to the mechanics behind what's going on here, and what I can do to achieve the desired independence of segments ?</p>
  
Tags: <ffmpeg><audio><streaming><mpeg><hls>
Title: MPEGTS & HLS: Only second segment onwards is valid
UserDisplayName: hmedia1
ThreadText: # MPEGTS & HLS: Only second segment onwards is valid
  
  (Asked by: username_0 on 2018-12-27)
  
  When i use hexadecagonal audio channel layout in an mpegts container, I can receive and play back the stream fine **only if** I configure the hls server to allow serving the very first segment, and then concatenating subsequent segments.
  
  I.e. If I probe segment 1414:
  
  ```
  [mpegts @ 0x7faf58001200] Could not find codec parameters for stream 1 (Audio: aac (LC) ([15][0][0][0] / 0x000F), 0 channels, fltp, 1464 kb/s): unspecified sample rate
  Consider increasing the value for the 'analyzeduration' and 'probesize' options
  
  Input #0, mpegts, from '1414.ts':
    Duration: 00:00:02.07, start: 2834.393367, bitrate: 9079 kb/s
    Program 1 
      Stream #0:0[0x100]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 0 channels, fltp, 1430 kb/s
      Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 0 channels, fltp, 1464 kb/s
      Stream #0:2[0x102]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
      Stream #0:3[0x103]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 60 fps, 60 tbr, 90k tbn, 120 tbc
  ```
  
  **However** if I probe the first segment:
  
  ```
  Input #0, mpegts, from '0.ts':
    Duration: 00:00:02.02, start: 1.412033, bitrate: 11598 kb/s
    Program 1 
      Stream #0:0[0x100]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, 16 channels, fltp, 1353 kb/s
      Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, 16 channels, fltp, 744 kb/s
      Stream #0:2[0x102]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
      Stream #0:3[0x103]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 60 fps, 60 tbr, 90k tbn, 120 tbc
  ```
  
  The playlist file is very simple and looks like this:
  
  ```
  #EXTM3U
  #EXT-X-VERSION:3
  #EXT-X-MEDIA-SEQUENCE:0
  #EXT-X-TARGETDURATION:4
  
  #EXTINF:2.000,
  0.ts
  #EXTINF:2.000,
  1.ts
  #EXTINF:2.000,
  2.ts
  #EXTINF:2.000,
  3.ts
  #EXTINF:2.000,
  
  etc ...
  
  ```
  
  With say an 8 channel layout, this does not happen.. every segment contains the correct headers. But my preference is to keep 16 channels because my application at the receiving end uses 16 channel files, and this avoids the need to transcode when downloading.
  
  I am using FFmpeg to upload the mpegts stream.
  
  Any insight to the mechanics behind what's going on here, and what I can do to achieve the desired independence of segments ?
  
  **Tags:** ffmpeg, audio, streaming, mpeg, hls
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-12-27. Score: 2 | Accepted answer
  
  For non-conventional layouts, the native AAC encoder writes a PCE section in the bitstream header as part of the AudioSpecificConfig. However, it does so only at the beginning, therefore subsequent files have AAC streams with this missing.
  
  Workaround is to change to a different packetization scheme for AAC in MPEG-TS.
  
  Add `-hls_ts_options mpegts_flags=latm` when generating the HLS package.
  
  > **Comments:**
  > **username_0**: this seemed to fix the issue, thanks.  (In my case I used `-mpegts_flags latm` directly).  Is there any unintended consequence that may surface from this ?  Having a read through ANSI/SCTE 193-2 2014 suggests that LATM is in fact the preferred encapsulation anyway.  
  > **username_1**: Not all HLS players may accept AAC-LATM.  
  
  ---
  
  