Thanks for reporting your issue. Please make sure these boxes are checked before submitting your issue - thank you!

- [X] I looked for a similar issue and couldn't find any.
- [X] I tried with the latest version of GPAC. Installers available at http://gpac.io/downloads/gpac-nightly-builds/
- [X] I give enough information for contributors to reproduce my issue (meaningful title, github labels, platform and compiler, command-line ...). I can share files anonymously with this dropbox: https://www.mediafire.com/filedrop/filedrop_hosted.php?drop=eec9e058a9486fe4e99c33021481d9e1826ca9dbc242a6cfaab0fe95da5e5d95

Detailed guidelines: http://gpac.io/2013/07/16/how-to-file-a-bug-properly/

I tried to use FLAC via HLS and was running into some issues. Trying to DASH a .flac file directly flat out doesn't work right, GPAC creates multiple periods from the single input.

At first it seemed like making a .mp4 file out of the .flac first would work, but then I ran into stuttering / skipping (depending on the player used) no matter which fragment or segment settings I used, even without a video stream to muddy up the fragment / segment lengths. Then I noticed the glitches always occurred at the same exact timestamps, and even with single file / single fragment output.

I went back and checked the "original" remuxed FLAC .mp4 used as the input for DASH, and lo and behold, it has stuttering, and you can see it in the decoder output when you try to play it back with GPAC player:

```
Q:\OLK>mp4box -add One_Last_Kiss.flac -new OLK_FLAC_96_24_ao.mp4
Track Importing FLAC - SampleRate 48000 Num Channels 2
[MP4Mux] PID audio ID 1 Sample 3277 with DTS 13421312 less than previous sample DTS 13421312, adjusting prev sample duration
Saving OLK_FLAC_96_24_ao.mp4: 0.500 secs Interleaving

Q:\OLK>gpac -gui OLK_FLAC_96_24_ao.mp4
[iso file] Found stts entry with sample_delta=0 - forbidden ! Fixing to 1
[flac] invalid residual
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 3432448: Invalid data found when processing input
[flac] invalid sync code
[flac] invalid frame header
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 3436544: Invalid data found when processing input
[flac] invalid residual
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 5875968: Invalid data found when processing input
[flac] invalid sync code
[flac] invalid frame header
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 5880064: Invalid data found when processing input
[flac] invalid residual
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 7649536: Invalid data found when processing input
[flac] invalid sync code
[flac] invalid frame header
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 7653632: Invalid data found when processing input
[flac] invalid residual
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 11229440: Invalid data found when processing input
[flac] invalid channel mode: 12
[flac] invalid frame header
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 11233536: Invalid data found when processing input
[flac] invalid residual
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 11660032: Invalid data found when processing input
[flac] switching bps mid-stream is not supported
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 11664128: Invalid data found when processing input
No filter chain found for PID play.svg in filter SVGLoad:Progressive to any loaded filters - NOT CONNECTED
```

Every `[flac]` or `[FFDec]` message in the console corresponds to an audible glitch. I tried `-flat` to see if it might be an interleaving issue, but it didn't make a difference. Something about the way GPAC is muxing the file is causing the FLAC decoder (both here in GPAC and elsewhere) to detect channel mode and bps switches that don't exist in the source .flac file at all.

For comparison, even though ffmpeg complains that FLAC in mp4 is experimental, it seems to work just fine.

```
Q:\OLK>ffmpeg -i One_Last_Kiss.flac -c copy -hide_banner One_Last_Kiss.mp4
Input #0, flac, from 'One_Last_Kiss.flac':
  Duration: 00:04:18.43, start: 0.000000, bitrate: 2727 kb/s
  Stream #0:0: Audio: flac, 96000 Hz, stereo, s32 (24 bit)
[mp4 @ 0000027caeee83c0] track 0: codec frame size is not set
[mp4 @ 0000027caeee83c0] flac in MP4 support is experimental, add '-strict -2' if you want to use it.
Could not write header for output file #0 (incorrect codec parameters ?): Experimental feature
Error initializing output stream 0:0 --
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
    Last message repeated 1 times

Q:\OLK>ffmpeg -i One_Last_Kiss.flac -c copy -strict -2 -hide_banner One_Last_Kiss.mp4
Input #0, flac, from 'One_Last_Kiss.flac':
  Duration: 00:04:18.43, start: 0.000000, bitrate: 2727 kb/s
  Stream #0:0: Audio: flac, 96000 Hz, stereo, s32 (24 bit)
[mp4 @ 000001fc816190c0] track 0: codec frame size is not set
Output #0, mp4, to 'One_Last_Kiss.mp4':
  Metadata:
    encoder         : Lavf59.24.100
  Stream #0:0: Audio: flac (fLaC / 0x43614C66), 96000 Hz, stereo, s32 (24 bit)
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
size=   86062kB time=00:04:18.43 bitrate=2728.1kbits/s speed=88.2x
video:0kB audio:86036kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.029658%

Q:\OLK>gpac -gui One_Last_Kiss.mp4

Q:\OLK>
```

ffmpeg's file plays through to the end without a single glitch or console message, nor does it cause issues when sent through GPAC dasher.

Using ffmpeg to remux either mp4 back to .flac produces a file with an identical Audio MD5 to the original.
FLAC files not being muxed properly
This is a GitHub Issue
repo:gpac
owner:gpac
Title : FLAC files not being muxed properly
Issue date:

--- start body ---
Thanks for reporting your issue. Please make sure these boxes are checked before submitting your issue - thank you!

- [X] I looked for a similar issue and couldn't find any.
- [X] I tried with the latest version of GPAC. Installers available at http://gpac.io/downloads/gpac-nightly-builds/
- [X] I give enough information for contributors to reproduce my issue (meaningful title, github labels, platform and compiler, command-line ...). I can share files anonymously with this dropbox: https://www.mediafire.com/filedrop/filedrop_hosted.php?drop=eec9e058a9486fe4e99c33021481d9e1826ca9dbc242a6cfaab0fe95da5e5d95

Detailed guidelines: http://gpac.io/2013/07/16/how-to-file-a-bug-properly/

I tried to use FLAC via HLS and was running into some issues. Trying to DASH a .flac file directly flat out doesn't work right, GPAC creates multiple periods from the single input.

At first it seemed like making a .mp4 file out of the .flac first would work, but then I ran into stuttering / skipping (depending on the player used) no matter which fragment or segment settings I used, even without a video stream to muddy up the fragment / segment lengths. Then I noticed the glitches always occurred at the same exact timestamps, and even with single file / single fragment output.

I went back and checked the "original" remuxed FLAC .mp4 used as the input for DASH, and lo and behold, it has stuttering, and you can see it in the decoder output when you try to play it back with GPAC player:

```
Q:\OLK>mp4box -add One_Last_Kiss.flac -new OLK_FLAC_96_24_ao.mp4
Track Importing FLAC - SampleRate 48000 Num Channels 2
[MP4Mux] PID audio ID 1 Sample 3277 with DTS 13421312 less than previous sample DTS 13421312, adjusting prev sample duration
Saving OLK_FLAC_96_24_ao.mp4: 0.500 secs Interleaving

Q:\OLK>gpac -gui OLK_FLAC_96_24_ao.mp4
[iso file] Found stts entry with sample_delta=0 - forbidden ! Fixing to 1
[flac] invalid residual
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 3432448: Invalid data found when processing input
[flac] invalid sync code
[flac] invalid frame header
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 3436544: Invalid data found when processing input
[flac] invalid residual
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 5875968: Invalid data found when processing input
[flac] invalid sync code
[flac] invalid frame header
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 5880064: Invalid data found when processing input
[flac] invalid residual
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 7649536: Invalid data found when processing input
[flac] invalid sync code
[flac] invalid frame header
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 7653632: Invalid data found when processing input
[flac] invalid residual
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 11229440: Invalid data found when processing input
[flac] invalid channel mode: 12
[flac] invalid frame header
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 11233536: Invalid data found when processing input
[flac] invalid residual
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 11660032: Invalid data found when processing input
[flac] switching bps mid-stream is not supported
[flac] decode_frame() failed
[FFDec] PID OLK_FLAC_96_24_ao.mp4 failed to decode frame PTS 11664128: Invalid data found when processing input
No filter chain found for PID play.svg in filter SVGLoad:Progressive to any loaded filters - NOT CONNECTED
```

Every `[flac]` or `[FFDec]` message in the console corresponds to an audible glitch. I tried `-flat` to see if it might be an interleaving issue, but it didn't make a difference. Something about the way GPAC is muxing the file is causing the FLAC decoder (both here in GPAC and elsewhere) to detect channel mode and bps switches that don't exist in the source .flac file at all.

For comparison, even though ffmpeg complains that FLAC in mp4 is experimental, it seems to work just fine.

```
Q:\OLK>ffmpeg -i One_Last_Kiss.flac -c copy -hide_banner One_Last_Kiss.mp4
Input #0, flac, from 'One_Last_Kiss.flac':
  Duration: 00:04:18.43, start: 0.000000, bitrate: 2727 kb/s
  Stream #0:0: Audio: flac, 96000 Hz, stereo, s32 (24 bit)
[mp4 @ 0000027caeee83c0] track 0: codec frame size is not set
[mp4 @ 0000027caeee83c0] flac in MP4 support is experimental, add '-strict -2' if you want to use it.
Could not write header for output file #0 (incorrect codec parameters ?): Experimental feature
Error initializing output stream 0:0 --
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
    Last message repeated 1 times

Q:\OLK>ffmpeg -i One_Last_Kiss.flac -c copy -strict -2 -hide_banner One_Last_Kiss.mp4
Input #0, flac, from 'One_Last_Kiss.flac':
  Duration: 00:04:18.43, start: 0.000000, bitrate: 2727 kb/s
  Stream #0:0: Audio: flac, 96000 Hz, stereo, s32 (24 bit)
[mp4 @ 000001fc816190c0] track 0: codec frame size is not set
Output #0, mp4, to 'One_Last_Kiss.mp4':
  Metadata:
    encoder         : Lavf59.24.100
  Stream #0:0: Audio: flac (fLaC / 0x43614C66), 96000 Hz, stereo, s32 (24 bit)
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
size=   86062kB time=00:04:18.43 bitrate=2728.1kbits/s speed=88.2x
video:0kB audio:86036kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.029658%

Q:\OLK>gpac -gui One_Last_Kiss.mp4

Q:\OLK>
```

ffmpeg's file plays through to the end without a single glitch or console message, nor does it cause issues when sent through GPAC dasher.

Using ffmpeg to remux either mp4 back to .flac produces a file with an identical Audio MD5 to the original.
--- end body ---
