I am trying to create 100% even duration of video(h264) and audio(aac) segments. This is a known challenge with AAC codec 1024 sample length. We have this an even magic integer `seconds=8, rate=48000, dashscale=48000, segdur=384000` to be used. Video segment's duration is easy to match an integer duration.

**MP4box always writes one extra MDAT.TRAF payload element <ins>to the last audio segment</ins>**, it does not matter how many seconds I encode from the input.mp4 file. A bug in a segment splitter's audio sample loop counter? 

I am trying to write 100% exact 1..n segments, encoding input timelimit is matched to a multiplier of 8 seconds.

Input file:
[00_llama_1080p_25fps.mp4](https://m.dtv.fi/dash/00_llama_1080p_25fps.mp4)

Statistics of the segments and few arguments, **Please note must use** ` -movflags empty_moov` flag so MP4Box is able to write an even duration of audio segments, removing a flag will make mp4box more easily write uneven audio segments, even the first segment may not match our 8s target.

```
ffmpeg : -t XX                 encode XX seconds from the input file
         negative_cts_offsets  enable negative MOOF/TRAF/TRUN.cts timestamp
         empty_moov            write initial moov(mp4box writes an even audio durations)
         +cgop -sc_threshold   use closed gop, disable scenecut
mp4box : segments 8sec duration (384000/48000)
         --tfdt64              use tfdt 64bit ver=1 box
         -subsegs-per-sidx 0   use one SIDX box
         --noroll=yes          disable roll sample grouping
video  : SIDX.duration=102400, SIDX.scale=12800   -> 8sec
         mdat.traf=200*512 duration=102400/12800  -> 8sec
audio  : SIDX.duration=384000, SIDX.scale=48000   -> 8sec
         mdat.traf=375*1024 duration=384000/48000 -> 8sec
         - all but last one has 375 samples matching 8s target.
audio  : SIDX.duration=385024, SIDX.scale=48000   -> 8,0213sec
(last)   mdat.traf=376*1024 duration=385024/48000 -> 8,0213sec
         - one extra sample element 385024-1024=384000.
```

Encoding and dash commands:
```
ffmpeg -hide_banner -nostats -i "./00_llama_1080p_25fps.mp4" -threads 4 -preset fast \
  -c:v libx264 -profile:v main -level 4.0 -s:v 640x360 -b:v 512k -pix_fmt yuv420p \
  -refs 3 -bf 3 -g 50 -keyint_min 25 -b_strategy 1 -flags +cgop -sc_threshold 0 \
  -movflags "empty_moov+negative_cts_offsets+faststart" \
  -an -t 32 -y "temp-v1.mp4"

ffmpeg -hide_banner -nostats -i "./00_llama_1080p_25fps.mp4" -threads 4 \
  -c:a aac -strict experimental -b:a 128k  \
  -af "aresample=48000" -ar 48000 -ac 2 \
  -movflags "empty_moov+negative_cts_offsets+faststart" \
  -vn -t 32 -y "temp-a1.mp4"

MP4Box -dash 384000 -frag 384000 -dash-scale 48000 -closest -mem-frags -rap \
  -profile "dashavc264:live" -profile-ext "urn:hbbtv:dash:profile:isoff-live:2012" \
  -min-buffer 4000 -bs-switching no \
  -sample-groups-traf -single-traf --tfdt64 --tfdt_traf --noroll=yes -subsegs-per-sidx 0 \
  -segment-name "$RepresentationID$/$Number$$Init=i$" -out "manifest.mpd" \
  "temp-v1.mp4#trackID=1:id=v1:period=p0" \
  "temp-a1.mp4#trackID=1:id=a1:period=p0"

```

(mp4box, ffmpeg compiled from the latest git sources)
Write even duration of video and audio(aac), last audio segment always has one extra mdat.traf payload element
This is a GitHub Issue
repo:gpac
owner:gpac
Title : Write even duration of video and audio(aac), last audio segment always has one extra mdat.traf payload element
Issue date:

--- start body ---
I am trying to create 100% even duration of video(h264) and audio(aac) segments. This is a known challenge with AAC codec 1024 sample length. We have this an even magic integer `seconds=8, rate=48000, dashscale=48000, segdur=384000` to be used. Video segment's duration is easy to match an integer duration.

**MP4box always writes one extra MDAT.TRAF payload element <ins>to the last audio segment</ins>**, it does not matter how many seconds I encode from the input.mp4 file. A bug in a segment splitter's audio sample loop counter? 

I am trying to write 100% exact 1..n segments, encoding input timelimit is matched to a multiplier of 8 seconds.

Input file:
[00_llama_1080p_25fps.mp4](https://m.dtv.fi/dash/00_llama_1080p_25fps.mp4)

Statistics of the segments and few arguments, **Please note must use** ` -movflags empty_moov` flag so MP4Box is able to write an even duration of audio segments, removing a flag will make mp4box more easily write uneven audio segments, even the first segment may not match our 8s target.

```
ffmpeg : -t XX                 encode XX seconds from the input file
         negative_cts_offsets  enable negative MOOF/TRAF/TRUN.cts timestamp
         empty_moov            write initial moov(mp4box writes an even audio durations)
         +cgop -sc_threshold   use closed gop, disable scenecut
mp4box : segments 8sec duration (384000/48000)
         --tfdt64              use tfdt 64bit ver=1 box
         -subsegs-per-sidx 0   use one SIDX box
         --noroll=yes          disable roll sample grouping
video  : SIDX.duration=102400, SIDX.scale=12800   -> 8sec
         mdat.traf=200*512 duration=102400/12800  -> 8sec
audio  : SIDX.duration=384000, SIDX.scale=48000   -> 8sec
         mdat.traf=375*1024 duration=384000/48000 -> 8sec
         - all but last one has 375 samples matching 8s target.
audio  : SIDX.duration=385024, SIDX.scale=48000   -> 8,0213sec
(last)   mdat.traf=376*1024 duration=385024/48000 -> 8,0213sec
         - one extra sample element 385024-1024=384000.
```

Encoding and dash commands:
```
ffmpeg -hide_banner -nostats -i "./00_llama_1080p_25fps.mp4" -threads 4 -preset fast \
  -c:v libx264 -profile:v main -level 4.0 -s:v 640x360 -b:v 512k -pix_fmt yuv420p \
  -refs 3 -bf 3 -g 50 -keyint_min 25 -b_strategy 1 -flags +cgop -sc_threshold 0 \
  -movflags "empty_moov+negative_cts_offsets+faststart" \
  -an -t 32 -y "temp-v1.mp4"

ffmpeg -hide_banner -nostats -i "./00_llama_1080p_25fps.mp4" -threads 4 \
  -c:a aac -strict experimental -b:a 128k  \
  -af "aresample=48000" -ar 48000 -ac 2 \
  -movflags "empty_moov+negative_cts_offsets+faststart" \
  -vn -t 32 -y "temp-a1.mp4"

MP4Box -dash 384000 -frag 384000 -dash-scale 48000 -closest -mem-frags -rap \
  -profile "dashavc264:live" -profile-ext "urn:hbbtv:dash:profile:isoff-live:2012" \
  -min-buffer 4000 -bs-switching no \
  -sample-groups-traf -single-traf --tfdt64 --tfdt_traf --noroll=yes -subsegs-per-sidx 0 \
  -segment-name "$RepresentationID$/$Number$$Init=i$" -out "manifest.mpd" \
  "temp-v1.mp4#trackID=1:id=v1:period=p0" \
  "temp-a1.mp4#trackID=1:id=a1:period=p0"

```

(mp4box, ffmpeg compiled from the latest git sources)
--- end body ---
