Kodi TV: Matroska video file (mkv) with increasing audio/video sync lag issue (solved!)

Written by - 0 comments

Published on - Listed in Multimedia Kodi


In a recent article I described how to record films or series from TV using Tvheadend on Kodi/LibreELEC. As the episode we were about to miss was correctly recorded and saved as a Matroska video file (mkv), it was time to catch up. I felt like a hero to present the recording to my wife: "See - there is at least one benefit of having married a geek!". I said it too fast.

Audio and video are not in sync!

Once the recorded file was launched in Kodi and the episode started, it only took a couple of seconds to realize: There's an audio/video sync issue. The sound seemed to come before the corresponding image (the video stream seemed to lag behind). It even became worse with every additional second. The longer the video was playing, the bigger the lag between audio and video was.

However, whenever the video was paused and then played again, audio and video were in sync again - for a few seconds until the same happened. Impossible to watch the recorded episode like this!

Interestingly this only happened, when the recorded episode was played within Kodi. On the computer the video was perfect; no audio/video sync issues there.

The Display Refresh Rate

On my research why this happens, I came across an old Kodi forums thread (MKV playback out of sync) which mentions similar problems. The thread was not marked as resolved, but the given advise sounded like a good hint:

It's in Kodi. Settings>video>playback>adjust display refresh rate to match display.

The additional link to another forum thread (Adjust Display Refresh Rate vs Sync Playback to Display) showed an outstanding explanation of these settings by the user "noggin":

"Adjust Display Refresh Rate" will switch the output refresh rate when playing back a file to the best refresh rate that is supported by the display AND the hardware Kodi is running on (as reported by EDID) If you don't select this option then you output at a fixed display refresh rate, which is usually set in Settings->System->Video Output. This setting allows Kodi to change the frame rate of the video output fed to the display, to ensure the best refresh rate is selected.

So if you have a display that supports 50Hz and 60Hz content, 50Hz content will be output at 50Hz and 60Hz content at 60Hz, however 24Hz will be output at 60Hz with 3:2 (ignoring 1000/1001 refresh rates (*))
If you have a display that supports 24Hz, 50Hz and 60Hz content, then 24Hz will be output at 24H, 50Hz at 50Hz and 60Hz at 60Hz. This is great if you have a display and hardware that copes with everything flawlessly.

"Sync Playback to Display" is different. It alters the playback speed so that it matches the display refresh rate (which could be fixed or could be variable if you have also selected Adjust Display Refresh Rate)

Why is this useful?

Say you have a 50Hz display but 24p content. 24p content will look horrible if you play at 50Hz, but if you Sync Playback to Display it will play the 24Hz back at 25Hz which will look much nicer at 50Hz. (Even if you have a display that syncs to 60Hz and could watch 24p material with 3:2 - which is nicer - you may still chose to watch at 50Hz with speed up and 2:2 to avoid the 3:2 judder. I sometimes do.)

Also - if you have a Kodi platform that can't cope with 23.976Hz output, but it can cope with 24.000Hz, you would normally get a repeated frame every 40" or so to keep stuff in sync. However if you also select Sync Playback to Display then Kodi will slow speed up the 23.976Hz content to 24.000Hz - so no repeated frames (and thus no stutter) but you then have to sort the audio sync out (either by resampling or by dupe/dropping)

OK - a couple of hints pointing towards the Display Refresh Rate. 

Changing the Display Refresh Rate in Kodi 18

The mentioned setting (fixed display refresh rate) can be found in Settings -> System -> Display.

Kodi System Display Settings Refresh Rate
Kodi System Display Settings Refresh Rate

To my big surprise, the fixed refresh rate was set to 24 (Hz), which seems to be a default value. As my TV (Samsung UE55KU6400) can cope with a much higher refresh rate, I changed to the highest available value: 60 (Hz).

Kodi System Display Settings Refresh Rate
Kodi System Display Settings Refresh Rate

Right after this change, I continued to play the recorded episode and YIPPEE-KI-YAY it worked! The audio/video sync was perfect now!

Issue was fixed - the geek restored his power. But the question remained: Why did this happen only now? On this particular video file?

Surely this wasn't the first time we watched a video on Kodi. We watched all our family videos streamed by Kodi so why all of a sudden are these sync issues there? It was the first time I did a DVR (digital video recording), so that surely must have something to do with it.

The video frame rate unveils its secret

With mediainfo I verified a couple of the recent videos we've watched on Kodi and the video frame rates on all of these files were either 23.976 fps or 24.000 fps. And what about that particular video file I recorded using Tvheadend?

$ mediainfo Married\ at\ First\ Sight\ Australia-E42020-08-2820-30.mkv | grep "Frame rate"
Frame rate mode                          : Constant
Frame rate                               : 25.000 fps

25 fps! That's it!

As Kodi was set to have a fixed refresh rate of 24 Hz/fps, it was unable to cope with a video file of a higher fps rate! Therefore the video stream seemed to slow down with every further second, while the audio stream played correctly - hence the sync issue.


Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder