Incorrect duration of mp4 file under VLC

I'm trying to stream from a user desired camera to a file (99% of the cases are mp4). So far so good, I've basically copied the example from ffmpeg. It does work, but the video has wrong start time under VLC. Under Windows Media Player it's fine. I have checked the segments duration of the trak box and seems that would be the problem. I can copy my code but it's the same as in the example. How can that be fixed? I've searched many different formulas and nothing seems to help.

enter image description here