Kodi Community Forum

Full Version: External mka not respecting delay
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have the following two files in a folder:

My.Movie.mkv
My.Movie.mka

The mka has a delay specified. When I play the mkv inside Kodi it detects the mka and starts playing it but does not respect the delay.

I can set the language inside the mka and Kodi uses that but the delay seems to be ignored.

Is this expected to work? Is there any way to work around it?
That's currently not suppported, but god idea. I'll have a look at it.
(2017-12-01, 08:29)Ace Wrote: [ -> ]That's currently not suppported, but god idea. I'll have a look at it.
 Thanks. I did spend a little bit of time looking through the source to try to do it myself but I couldn't find exactly how delay even gets read from an mkv so I could try to follow the pattern for an mka. If you can give me some pointers about how to approach this I would be happy to try to implement it myself. Then again it might be one of those things that's simpler to do yourself and that's fine by me ;-P

I kinda expected it to be somewhere in DVDDemuxFFmpeg.cpp since that seems to be where language and other similar things come in but that looked to be a dead end.
BTW it looks like it does work if the delay is negative, presumably because in that case the beginning of the stream is actually truncated and not included in the container at all.
Found some time. It seems that the delay of a track is not a tag, the track gets manipulated directly, like you found out already. And for mkas it does not work at all. The only thing I can imagine is that you could add the delay to the filename and extract it from there (GetExternalStreamDetailsFromFilename) and set it upon streamopen in videoplayer.
(2017-12-08, 16:27)Ace Wrote: [ -> ]Found some time. It seems that the delay of a track is not a tag, the track gets manipulated directly, like you found out already. And for mkas it does not work at all. The only thing I can imagine is that you could add the delay to the filename and extract it from there (GetExternalStreamDetailsFromFilename) and set it upon streamopen in videoplayer.
 Yeah now that I realize that MKVToolNix's delay is actually just modifying the timecodes there is no way this is Kodi's fault - and indeed if I set a positive delay and play the MKA the delay is not present. So it seems this is a problem with MKVToolNix, I'll go down that road before I look at hacking it into the filename. Thanks.
(2017-12-08, 16:27)Ace Wrote: [ -> ]Found some time. It seems that the delay of a track is not a tag, the track gets manipulated directly, like you found out already. And for mkas it does not work at all. The only thing I can imagine is that you could add the delay to the filename and extract it from there (GetExternalStreamDetailsFromFilename) and set it upon streamopen in videoplayer.
 OK I've done some research into this and identified the problem. The root of the issue is the fact that timestamps in the audio/video stream are not treated as absolute by ffmpeg. ffmpeg normalizes the smallest timestamp to 00:00:00 and all other timestamps in all other streams are adjusted accordingly.

This means that:
1) Timestamps in separate containers will be normalized separately and not necessarily correlate how you expect
2) A container with only a single stream will always be normalized to start at 00:00:00

So a positive delayed audio track in its own container will always play back as though there was no delay. MPC-HC has the same behavior.

One possible solution would be for Kodi could examine the first audio frame and use the (absolute) timestamp to set the delay automatically. At this point I have no idea how to get that absolute timestamp (or if it's even possible), but I'll keep looking into it a bit. If there is any way to override ffmpeg's time normalization behavior then that might be another possible solution.

Certainly the easiest thing is to read it out of the filename, I think I'll set up a Kodi dev env and try to start with that.