enen92/screensaver.atv4

Videos don't play as smoothly in screensaver mode

Opened this issue · 23 comments

I've noticed on my Raspberry Pi 3 running OSMC that when these screensavers play (they are pre-downloaded) in screensaver mode they are often a little jittery. In other words I'm not seeing sustained 60fps. Yet the CPU usage is only around 20%. But if I go through video -> files and play the files manually they are totally smooth throughout. It's a pretty big visible difference.

I'm wondering if you know why this might be. I have made sure the limit UI updates option is disabled, in case that was relevant.

Not sure. You mean the little jitter when the first video starts or do you mean the video is always jittering? If the latest is happening, and without being entirely sure, it might be caused by the fact you are limiting the user interface fps when playing a video. At least, for the pi there is a setting to do it and by default it has a low value. The addon uses a videowindowdefined in a xml "skinning" file ( see https://github.com/enen92/screensaver.atv4/blob/master/resources/skins/default/720p/screensaver-atv4.xml#L15-L21 )

You could try to change the setting I mentioned just to check if it has any effect on the video jittering

Not just when the video starts. There will be periods where it looks great and periods when it's jittering, seemingly at random, but it's mostly jittery when played as a screensaver. When the files are played directly it's always totally smooth.

I did already disable that setting as I said in my previous message. It's <limitguiupdate>0</limitguiupdate>

Out of interest why is the window you're making hardcoded to 1280x720 in the code you linked? If that's scaling the 1920x1080 down to a smaller resolution could that be causing slowdown? Then again like I said CPU usage is only 20% or something...

It might be as well. Probably time to make it 1080p as it is the default resolution for Estuary now. Nothing like giving it a try :)

@tremby FYI I added a 1080i interface on the new version, that should be hitting the repository soon. Check if help with the video jittering.
However I used a raspberry pi 1 (model B) for development and testing and the videos were playing smoothly.
Cheers

Also please read this one: #13

I've tried the update out and it still isn't seeming as smooth. Next time a friend with an Iphone is at my place I'm going to try to take slow-motion captures, so I can confirm that it's not just in my head.

It's sometimes somewhat subtle and I need to look closely. Like in the fly towards the waterfall (Hawaii maybe?) which starts over the water, I watch the waves below and in screensaver mode they don't move quite smoothly while when playing the video directly it's buttery smooth.

Out of interest, why 1080i rather than 1080p?

Do you know if there's a way I can find out whether Kodi is changing the refresh rate of the display? After reading the other thread you pointed out I have a feeling it's doing that when I play the videos manually but not when the screensaver plays them. I don't think it ought to actually make a difference (since the videos are 30Hz and this divides evenly into 60Hz), but it's worth ruling out.

I realized after my previous message that of course I could just disable changing the refresh rate, and at the same time disable adjusting video speed to refresh rate and test again. I guess that wasn't the issue because the playback is still much smoother for me when playing the video directly than when the screensaver starts it.

The video where I see it most clearly is the LA beach bird's eye view one, since most of the content is moving in a straight line and quite quickly. There's a very clear and consistent difference every time I look at this video.

I have all post-processing my TV is capable of switched off, by the way, so no frame interpolation and such.

I think I found the issue. It looks like Kodi is doing too much work on the background, hence leading to the video freezing sometimes. Unfortunately (or fortunately since it was poorly written) it needs big changes on the way the screensaver is being instantiated. Right now the addon has a single python script atv.py that do all the screensaver work:

  1. Starts the window
  2. Instantiates a Monitor to check for events
  3. Sends a random input to kodi so the screensaver is deactivated
  4. Grabs the onScreensaverDeactivated event and triggers the playback

What happens is that when Kodi deactivates the screensaver it expects the original screensaver script to quit. That does not happen since we start a video loop.

So, to solve this I will implement properly the monitor part (which was written too long ago) and turn this addon into a script and screensaver. So basically users will be able to start the video loop also as if it was a regular addon.

The screensaver part will only be responsible for deactivating the screensaver and monitoring the events. When a screensaverDeactivated event is received by the screensaver it will send an asynchronous request to start the program addon and will die afterwards.

I will also make sure the main addon part will run as a WindowXML and not as a WindowXMLDialog. That way we will not have a window on top of the current Kodi skin window but a window that replaces the previous loaded one. I will also make sure I remove all the controls (images) that are presented before the video starts. This will lower resource usage and increase performance.

I will need your help to test the changes (I'll notify here on this issue) before pushing an update to the repository.

Can you check with the newer version (manual installation required and not yet submitted to the official repository)? Hopefully it's better now!

You can download the installable zip from the releases tab: https://github.com/enen92/screensaver.atv4/releases/tag/1.3.4

Tried it.

I get the SF background and the loading spinner briefly, then the screen goes black until a key is pressed, then I'm back to whatever screen I was on. Here's the relevant log output:

(Wait for screensaver)
15:15:54 657274.875000 T:1401943024 WARNING: CSkinInfo: failed to load skin settings
15:15:56 657277.375000 T:1956447152 WARNING: Previous line repeats 1 times. 
15:15:56 657277.375000 T:1956447152  NOTICE: DVDPlayer: Opening: /mnt/hoard/media/video/ambient/appletv4/comp_LA_A005_C009_v05_t9_6M.mov
15:15:56 657277.375000 T:1956447152 WARNING: CDVDMessageQueue(player)::Put MSGQ_NOT_INITIALIZED
15:15:56 657277.375000 T:1452274672  NOTICE: Creating InputStream
15:15:56 657277.375000 T:1452274672  NOTICE: Creating Demuxer
15:15:57 657277.625000 T:1452274672  NOTICE: Opening stream: 0 source: 256
15:15:57 657277.625000 T:1452274672  NOTICE: Creating video codec with codec id: 28
15:15:57 657277.625000 T:1452274672  NOTICE: Creating video thread
15:15:57 657277.625000 T:1452274672   ERROR: Get - failed to get stream
15:15:57 657277.625000 T:1362097136  NOTICE: running thread: video_thread
15:15:57 657277.625000 T:1452274672 WARNING: CDVDMessageQueue(audio)::Put MSGQ_NOT_INITIALIZED
15:15:57 657277.750000 T:1759826928  NOTICE: Kodi Hue: DEBUG playback started called on player
15:15:57 657277.812500 T:1362097136  NOTICE:  fps: 30.000000, pwidth: 1920, pheight: 1080, dwidth: 1920, dheight: 1080
15:15:57 657277.812500 T:1362097136  NOTICE: Display resolution ADJUST : 1920x1080 (1920x1080) @ 60.00 - Full Screen (16) (weight: 0.000)
(At this point I'm seeing black. Eventually I press a key)
15:16:27 657308.125000 T:1956447152  NOTICE: CDVDPlayer::CloseFile()
15:16:27 657308.125000 T:1956447152  NOTICE: DVDPlayer: waiting for threads to exit
15:16:27 657308.125000 T:1452274672  NOTICE: CDVDPlayer::OnExit()
15:16:27 657308.125000 T:1452274672  NOTICE: Closing stream player 2
15:16:27 657308.125000 T:1452274672  NOTICE: waiting for video thread to exit
15:16:27 657308.187500 T:1362097136  NOTICE: thread end: video_thread
15:16:27 657308.187500 T:1452274672  NOTICE: deleting video codec
15:16:27 657308.187500 T:1956447152  NOTICE: DVDPlayer: finished waiting
15:16:27 657308.187500 T:1956447152  NOTICE: CDVDPlayer::CloseFile()
15:16:27 657308.187500 T:1956447152  NOTICE: DVDPlayer: waiting for threads to exit
15:16:27 657308.187500 T:1956447152  NOTICE: DVDPlayer: finished waiting
15:16:27 657308.187500 T:1956447152  NOTICE: CDVDPlayer::CloseFile()
15:16:27 657308.187500 T:1956447152  NOTICE: DVDPlayer: waiting for threads to exit
15:16:27 657308.187500 T:1956447152  NOTICE: DVDPlayer: finished waiting
15:16:27 657308.375000 T:1759826928  NOTICE: Kodi Hue: DEBUG playback stopped called on player
(Now I'm back to the menu)

I get the same behaviour if I choose "preview" from the screensaver menu.

hum.. 15:15:56 657277.375000 T:1956447152 NOTICE: DVDPlayer: Opening: /mnt/hoard/media/video/ambient/appletv4/comp_LA_A005_C009_v05_t9_6M.mov

Kodi could not play the file so probably your media share was not accessible? Please also try to start the addon from the "video-> addons" tab

Kodi could not play the file so probably your media share was not accessible?

No, the video file's fine and accessible. I can play it via video -> files.

Please also try to start the addon from the "video-> addons" tab

I get the same behaviour.

16:22:01 661242.625000 T:1479537648 WARNING: CSkinInfo: failed to load skin settings
16:22:02 661243.187500 T:1956447152  NOTICE: DVDPlayer: Opening: /mnt/hoard/media/video/ambient/appletv4/comp_LA_A005_C009_v05_t9_6M.mov
16:22:02 661243.187500 T:1956447152 WARNING: CDVDMessageQueue(player)::Put MSGQ_NOT_INITIALIZED
16:22:02 661243.187500 T:1362097136  NOTICE: Creating InputStream
16:22:02 661243.187500 T:1362097136  NOTICE: Creating Demuxer
16:22:02 661243.437500 T:1362097136  NOTICE: Opening stream: 0 source: 256
16:22:02 661243.437500 T:1362097136  NOTICE: Creating video codec with codec id: 28
16:22:02 661243.437500 T:1362097136  NOTICE: Creating video thread
16:22:02 661243.437500 T:1362097136   ERROR: Get - failed to get stream
16:22:02 661243.437500 T:1345319920  NOTICE: running thread: video_thread
16:22:02 661243.437500 T:1362097136 WARNING: CDVDMessageQueue(audio)::Put MSGQ_NOT_INITIALIZED
16:22:02 661243.500000 T:1759826928  NOTICE: Kodi Hue: DEBUG playback started called on player
16:22:02 661243.562500 T:1345319920  NOTICE:  fps: 30.000000, pwidth: 1920, pheight: 1080, dwidth: 1920, dheight: 1080
16:22:02 661243.562500 T:1345319920  NOTICE: Display resolution ADJUST : 1920x1080 (1920x1080) @ 60.00 - Full Screen (16) (weight: 0.000)

Note that it knows the frame rate and resolution of the video. It's finding it just fine. It might even be playing it, I just can't see it. But the "failed to get stream" is definitely weird.

Here's the log output when playing the file from the files browser.

16:25:53 661474.562500 T:1956447152  NOTICE: DVDPlayer: Opening: /mnt/hoard/media/video/ambient/appletv4/comp_LA_A005_C009_v05_t9_6M.mov 
16:25:53 661474.562500 T:1956447152 WARNING: CDVDMessageQueue(player)::Put MSGQ_NOT_INITIALIZED 
16:25:53 661474.562500 T:1452274672  NOTICE: Creating InputStream 
16:25:53 661474.562500 T:1452274672  NOTICE: Creating Demuxer 
16:25:54 661474.812500 T:1452274672  NOTICE: Opening stream: 0 source: 256 
16:25:54 661474.812500 T:1452274672  NOTICE: Creating video codec with codec id: 28 
16:25:54 661474.812500 T:1452274672  NOTICE: Creating video thread 
16:25:54 661474.812500 T:1452274672   ERROR: Get - failed to get stream 
16:25:54 661474.812500 T:1524626416  NOTICE: running thread: video_thread 
16:25:54 661474.812500 T:1452274672 WARNING: CDVDMessageQueue(audio)::Put MSGQ_NOT_INITIALIZED 
16:25:54 661474.875000 T:1759826928  NOTICE: Kodi Hue: DEBUG playback started called on player 
16:25:54 661475.000000 T:1524626416  NOTICE:  fps: 30.000000, pwidth: 1920, pheight: 1080, dwidth: 1920, dheight: 1080 
16:25:54 661475.000000 T:1524626416  NOTICE: Display resolution ADJUST : 1920x1080 (1920x1080) @ 60.00 - Full Screen (16) (weight: 0.000) 

Notice that the same "failed to get stream" error is there, even though it's playing fine. I've no idea what this could mean.

Can you give it a try without the offline folder defined? Such as pointing it to a folder that has no videos so it uses the online ones? Just to check for stuttering on the video playback

17:38:16 665816.875000 T:1957090224   ERROR: Window Translator: Can't find window settingsprofile
17:38:47 665848.437500 T:1717244912   ERROR: Previous line repeats 1 times.
17:38:47 665848.437500 T:1717244912 WARNING: CSkinInfo: failed to load skin settings
17:38:49 665850.187500 T:1957090224 WARNING: Previous line repeats 1 times.
17:38:49 665850.187500 T:1957090224  NOTICE: DVDPlayer: Opening: http://a1.phobos.apple.com/us/r1000/000/Features/atv/AutumnResources/videos/comp_LA_A006_C008_t9_6M_HB_tag0.mov
17:38:49 665850.187500 T:1957090224 WARNING: CDVDMessageQueue(player)::Put MSGQ_NOT_INITIALIZED
17:38:49 665850.250000 T:1717244912  NOTICE: Creating InputStream
17:38:49 665850.500000 T:1717244912  NOTICE: Creating Demuxer
17:38:50 665851.062500 T:1717244912  NOTICE: Opening stream: 0 source: 256
17:38:50 665851.125000 T:1717244912  NOTICE: Creating video codec with codec id: 28
17:38:50 665851.125000 T:1717244912  NOTICE: Creating video thread
17:38:50 665851.125000 T:1717244912   ERROR: Get - failed to get stream
17:38:50 665851.125000 T:1355801584  NOTICE: running thread: video_thread
17:38:50 665851.125000 T:1717244912 WARNING: CDVDMessageQueue(audio)::Put MSGQ_NOT_INITIALIZED
17:38:50 665851.187500 T:1759974384 WARNING: Previous line repeats 1 times.
17:38:50 665851.187500 T:1759974384  NOTICE: Kodi Hue: DEBUG playback started called on player
17:38:50 665851.250000 T:1355801584  NOTICE:  fps: 30.000000, pwidth: 1920, pheight: 1080, dwidth: 1920, dheight: 1080
17:38:50 665851.250000 T:1355801584  NOTICE: Display resolution ADJUST : 1920x1080 (1920x1080) @ 60.00 - Full Screen (16) (weight: 0.000)

Still a black screen while "playing".

What kodi version are you running and which skin are you using? I think the videos are playing but somehow the videowindow is not being shown

It's Kodi 16.1, running the OSMC default skin.

Can you replace WindowXML to WindowXMLDialog in https://github.com/enen92/screensaver.atv4/blob/master/atv.py#L32 to see if there are any differences?

Might be also interesting to comment this line:

https://github.com/enen92/screensaver.atv4/blob/master/atv.py#L47

It might be some issue due to the id's I am using for the window

Please do the tests using the current version in master (1.3.6) as I changed the control id's to avoid issues with the skins. So:

-Try current master (as screensaver and video addon)
-If that does not work, comment the self.nobackground() call and try again
-If that does not work, change the WindowXML to WindowXMLDialog and try again

Hopefully we can then find the issue! Best case scenario, current master solves it :)

any news @tremby ?

Sorry for the delay, I was buried with work lately. I'll give this a go shortly.

In the following, I didn't just test each thing once, but multiple times with all results reproduced. I am now 100% sure that these differences in smoothness aren't just in my head. It really helps to view the LA videos, particularly the bird's-eye-view of the beach. The difference is much clearer in this one, and to a lesser extent in the spaghetti junction flyover. So I've set it to only show me LA videos, and only daytime.

  • Current master (2687e37): black screen when screensaver starts in preview mode, as described before (I briefly see the spinner and bridge, etc). I didn't investigate this one further.
  • With self.nobackground() commented: I see the screensaver. A definite improvement in smoothness over before. The first few seconds are usually janky, then it's mostly smooth but I see some periodic repeated or skipped frames every second or two. Screensaver runs both in preview and when idle.
  • With self.nobackground() not commented, and with WindowXMLDialog: I see the screensaver in preview mode and other than a bit of jankiness for the first few seconds (most of the time -- sometimes it starts smooth, as above) it seems completely smooth to me. I don't see the same periodic jank I do with the previous test. Looks great! However, after the 1 minute I have configured of idle before the screensaver should start, things don't work properly. I see the spinner briefly and the still of the Golden Gate Bridge briefly, and my Hue lights dim (it thinks I'm playing a video), but then I just see the menu I was looking at again. The lights remain dim until I press a key, whereupon the menu reacts to the keypress and my lights switch on again (it thinks the video has stopped playing). Is it playing beneath the UI perhaps?...
  • With both modifications: screensaver is visible in preview mode but is noticeably less smooth, I think just the same as before all your recent changes. Screensaver starts when idle, but is janky here too.