2010-12-09, 02:43
Hi guys. I work on boxee and have been debugging this issue (sync problems with DTS in mkv) for a bit and wanted to share some of the things i found.
First off, i have yet to find a tool that encodes the proper timing data for dts in MKV. The cluster/block timing in matroska is consistently inaccurate. What i have seen in every clip is the timing progressively creeps forward until eventually it hits a 'pinch', where there is too much audio data in too short a period of time. This is where the sync issues come in.
Additionally, the patches you guys are working with to try and fix up ffmpeg are not getting you the right duration value for DTS frames. This is because ffmpeg is calculating the duration using the stream time scale, which is reduced too far to get the proper acccuracy. I.e. usually the frame size is 512 and the sample rate is 48000 and the frame duration should be 512 / 48000 = .010667, but instead it gets rounded out to .010000.
To fix this for the boxee box, where we were seeing this same issue, i ended up doing two things:
1) I ignore pts/dts for DTS streams in mkv. I just assume it is always wrong. We have some edge cases that require a timestamp for sync after seek, that's the only exception
2) I pull the stream frame size and sample rate in DVDDemuxFFmpeg.cpp and recalculate the duration with double accuracy.
So the audio clock moves based on packet durations now and not packet timestamps when using DTS in mkv. With this setup i seem to be able to play all DTS/DTS-HD in mkv without a hitch.
I can't provide a patch due to code drift but i'd be happy to help you guys out with as much detail as you'd like. Will check back here or you can mail me - dan at boxee dot tv
Cheers,
-Dan
First off, i have yet to find a tool that encodes the proper timing data for dts in MKV. The cluster/block timing in matroska is consistently inaccurate. What i have seen in every clip is the timing progressively creeps forward until eventually it hits a 'pinch', where there is too much audio data in too short a period of time. This is where the sync issues come in.
Additionally, the patches you guys are working with to try and fix up ffmpeg are not getting you the right duration value for DTS frames. This is because ffmpeg is calculating the duration using the stream time scale, which is reduced too far to get the proper acccuracy. I.e. usually the frame size is 512 and the sample rate is 48000 and the frame duration should be 512 / 48000 = .010667, but instead it gets rounded out to .010000.
To fix this for the boxee box, where we were seeing this same issue, i ended up doing two things:
1) I ignore pts/dts for DTS streams in mkv. I just assume it is always wrong. We have some edge cases that require a timestamp for sync after seek, that's the only exception
2) I pull the stream frame size and sample rate in DVDDemuxFFmpeg.cpp and recalculate the duration with double accuracy.
So the audio clock moves based on packet durations now and not packet timestamps when using DTS in mkv. With this setup i seem to be able to play all DTS/DTS-HD in mkv without a hitch.
I can't provide a patch due to code drift but i'd be happy to help you guys out with as much detail as you'd like. Will check back here or you can mail me - dan at boxee dot tv
Cheers,
-Dan