croneter / PlexKodiConnect

Plex integration in Kodi done right
GNU General Public License v2.0
1.19k stars 78 forks source link

Background Sync Causes Stuttering during playback #1471

Open sufd4 opened 3 years ago

sufd4 commented 3 years ago

Describe the bug

During video playback, I will occasionally get a lot of stuttering in the video playback. This only occurs when background sync is enabled. When it happens, the plex server has just refreshed some items and a sync must've been triggered and various errors can be seen in the long at that time.

Matrix with latest stable PKC, no other non-default add-ons. Very large plex library. Running on a Shield TV 2019 Pro. Issue occurs even with a clean boot and only loading up Kodi. Kodi reports plenty of free ram.

To Reproduce

Steps to reproduce the behavior:

  1. Watch a video
  2. At some point when Plex scans several items and updates some metadata, the stuttering happens.
  3. this can be 1 hour into watching something or sooner. So any full sync should be completed far before then. I've let it complete in full as well (with playstate showing) and that has no impact. Plex Server has auto updating disabled and was not doing a full library update during the stuttering, just a few folders updated when 1 new file added.

Expected behavior

This not to happen or background sync to not trigger during playback

Logs

kodi1.log - non-debug - Line 443 2021-05-04 17:43 - sync and errors begin. Much smaller update was triggered on the Plex side for this one compared to the next log file. It was just a couple folders it seems

2021-05-04 17:45:36.548 T:7308  WARNING <general>: ActiveAE - large audio sync error: -22967.995318
2021-05-04 17:45:36.597 T:7298    ERROR <general>: CMediaCodecVideoBuffer::ReleaseOutputBuffer error in render(1)

kodi1.log

Kodi2.log - Debug file - Line 1492 is where you can see the sync happening at 2021-05-02 21:47:07.145

croneter commented 3 years ago

Stuttering occurs in both logs?

sufd4 commented 3 years ago

Yes it does. The first log it happened an hour into a movie.

croneter commented 3 years ago

And during the second log?

sufd4 commented 3 years ago

Second log it was at the line I specified. I believe it was about 20 minutes into watching something. The Plex server did update some files and then the stuttering happened.

croneter commented 3 years ago

OK, so this is what I think happens, thanks again for the logs! The PMS scans your library and seems to automatically update some of your episodes. This is captured by PKC and more or less immediately the respective episode is updated:

PLEX.tvshows: UPDATE episode plex_id: XXXXXXX

PKC needs to tell Kodi that it did this update (PKC is smart enough to collect updates over a couple of seconds and does some small "batch processing"); Kodi then scans the database (log1):

VideoInfoScanner: Starting scan ..
VideoInfoScanner: Finished scan. Scanning for video info took 00:00

...
VideoInfoScanner: Starting scan ..
...
VideoInfoScanner: Finished scan. Scanning for video info took 01:30
...
VideoInfoScanner: Starting scan ..
...
OutputPicture - timeout waiting for buffer
...
VideoInfoScanner: Finished scan. Scanning for video info took 01:02

So for the most part, Kodi scanning the database works well. But then it suddenly doesn't happen instantly anymore (took 00:00) but takes mintues (took 01:30). That's when the stuttering seems to occur (OutputPicture - timeout waiting for buffer).

Proposed Solution:

From a PKC perspective, try to avoid these rather massive syncs (PLEX.tvshows: UPDATE episode plex_id:). I hope that it helps if you change the Scheduled tasks in the Plex Media Server-settings: try to let tasks run during the night so that the PMS won't update stuff in the background WHILE you're watching, e.g.: image

sufd4 commented 3 years ago

om a PKC perspective, try to avoid these rather massive syncs (PLEX.tvshows: UPDATE episode plex_id:). I hope that it helps if you change the Scheduled tasks in the Plex Media Server-settings: try to let tasks run during the night so that the PMS won't update stuff in the background WHILE you're watching, e.g.:

Thanks for looking further into this for me. So I've already turned off auto scanning when changes are detected and also larger scans only happen at night. Updates are now exclusively only for a specific episodes folder when it's added using Plex_AutoScan script. So it will call up the scan as follows

"C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Scanner.exe" --scan --refresh --section 27 --directory "G:\TV\SHOWNAME\Season 1\" to ensure it only scans the most minimal possible. It's 50/50 when this scan to add one episode will cause stuttering. So unfortunately with all these measures, the issue isn't solved.

sufd4 commented 3 years ago

Is there any other fix for this? I'd already done the proposed solution prior to making the logs in the original post and it didn't resolve the issue so I've left background sync disabled since. Thanks

croneter commented 3 years ago

Not that I know šŸ˜ž

sufd4 commented 3 years ago

Not that I know šŸ˜ž

Thanks for letting me know. I've posted on your ideas board a feature suggestion that would help mitigate the impact for me and possibly others. Hopefully you can consider it. https://github.com/croneter/PlexKodiConnect/discussions/1569

xenophobentx commented 2 years ago

Also experienced that stutter on my shield due to sync on matrix. Not a big issue but it happens for sure.

xenophobentx commented 2 years ago

Is there any other fix for this? I'd already done the proposed solution prior to making the logs in the original post and it didn't resolve the issue so I've left background sync disabled since. Thanks

Please check the following build of kodi it helped me a lot: https://forum.kodi.tv/showthread.php?tid=365127&page=25