Kodi Community Forum

Full Version: Smoothvideo ("Sync playback to display" feature) now merged in the mainline branch
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6
Since smoothvideo has been merged into linuxport and the old thread contains replies about the former implementation (which relied on opengl vsync for timing) the discussion will continue here.

What is it for?
Lots of people experience jerkiness when playing video on a computer, this has to do with the way video frames are presented, smoothvideo tries to fix this by syncing the video to the refreshrate of the monitor.
It's like the reclock directshow filter, only much better.

How does it work?
Usually video is referenced to the system clock, but with a little magic a clock can be made with information from the videocard, this makes sure every frame is presented right after a vblank. Also because the clock can now be controlled, the speed can be changed a little so the fps of the video playing matches the refreshrate.

What about audio?
Audio has to stay in sync, this can either be done by resampling, skipping/duplicating packets, or adjusting the clock if it gets out of sync too far.

Resampling has the advantage that the speed of the video can be changed considerably, so 24 fps can be sped up to 25 fps to play at PAL speed.
The disadvantage of resampling is that it doesn't work with passthrough, and there is a slight loss of audio quality.

Skipping/duplicating audiopackets has no loss of audio quality, but the speed of the video can only be changed a little to avoid doing a skip/duplication too often, most of the time it's inaudible, but it can produce a very audible click.

Adjusting the clock has the best audioquality, but some extra video jitter can occur, also the speed of the video can't change much, as the audio will sync the clock more often the more the speed of the video is changed.

How do I turn it on?
Under Settings->Videos->Player there are several new options:
  • Sync playback to display
    Turn this on and the magic happens, a thread will start that makes a clock from the vertical blank.
  • A/V Sync method
    You can set this to Audio Clock, Video Clock(resample audio) or Video Clock(Drop/Dupe Audio)
    Resample audio does not work when passthrough is selected.
  • Resample quality
    Quality of the resampler, goes from low to really high, the default is medium which should be fine for anyone. The higher the quality of the resampler, the more cpu it will use. You can look at the resampler types at libsamplerate
  • Maximum Resample Amount (%)
    The maximum percentage the speed of the video can be changed to fit the refreshrate, the default is 5% to allow cinema to PAL speedup (24 to 25 fps, 4%), this is only available when resampling (a small speed change will still happen without resampling).

What about the adjust refreshrate option?
That's something different, it will automatically set the refreshrate which is best matched with the video that is playing, but it is a good combination with the vblank clock.

How do I know it's working?
Turn on debug logging, turn on Sync playback to display and start a video, then search the debug log for CVideoReferenceClock.

Mine looks like this (on ubuntu with the binary nvidia driver):

Quote:21:09:39 T:2874137488 M:1382379520 DEBUG: CVideoReferenceClock: Setting up GLX
21:09:39 T:2874137488 M:1379201024 DEBUG: CVideoReferenceClock: output of nvidia-settings -nt -q RefreshRate 2>&1: 59.89 Hz
21:09:39 T:2874137488 M:1379201024 DEBUG: CVideoReferenceClock: Detected refreshrate by nvidia-settings: 59.890000 hertz, rounding to 60 hertz
21:09:39 T:2865744784 M:1379323904 DEBUG: CVideoReferenceClock: Clock speed 100.100000%

Here I'm playing a 29.97 fps video on a monitor with a 60 hertz refreshrate, the speed of the clock is increased by 0.1% so the video wil play at exactly 30 fps.
The rounding of the refreshrate from 59.89 to 60 hertz does NOT matter. Why? because of the automatic change in clock speed.

Now press 'o' while playing to bring up the codec information, if the vblank clock is running it will show "VBlanks missed:" with a number next to it, that number shows how many updates the vblank clock has missed, this can either be because the update was too late or it missed a vblank completely and it's waiting for the next vblank.
This is not especially bad, because the render thread will update the clock instead. However if that number increases really fast it can mean the clock is not running at all or it's missing a lot of vblanks, in which case you might get some strange pitch effects when resampling and even jerky video.

If you get a like like this in the debug log:
Quote:CVideoReferenceClock: Setup failed, falling back to QueryPerformanceCounter

It means it couldn't set up the clock and it uses the systemclock instead, the lines containing CVideoReferenceClock above it will usually explain what went wrong.

Known issues
Some videos don't provide correct fps information, so they'll play jerky anyway.
Crashes in linux with the binary ati driver.
On windows the detected refreshrate might be wrong, to fix this you can turn on measurerefreshrate in Advancedsettings.xml.
I get very similar actions http://forum.xbmc.org/showpost.php?p=336...tcount=322

I can play something at a certain framerate, but after stopping it I get jerkiness on other vids at different framrates. I can restart XBMC and all is smooth again. This repeats.

this may have nothing to do with the Smoothbranch (even though its in the main branch now). It seems like XBMC gets thrown off. Almost like it needs an HZ reset once a video is done playing?


Bobo1on1,
When you state..
Known issues
Some videos don't provide correct fps information, so they'll play jerky anyway.
Do you mean that the videos themselves are reporting incorrectly or XBMC itself is reporting them incorrectly?

Thanks for all the hard work on this. Everyone has made so much progress in such a short amount of time its insane for a open source product.
edit: i had to disable trippe buffering (and remove d3overider) to get rid of tearing in the top quarter of the screen.
What's the latest revision that includes it?
They all include it as of yesterday. Is that what you are asking?
Yeah that works. Just making sure my version has it already.
Well, adjust refresh rate on windows vista is still broken.

I just tried a bunch of setting combiations, and none worked. The ONLY way to get the correct 24fps output for me is to set desktop to 24Hz AND run XBMC in window mode (where refresh rate is ignored) or fullscreen at 24hz. The "Adjust Refresh Rate" setting sure tries to change the refreshrate in other modes, but it fails in all of them, resulting in 60Hz Confused


Here's a partial debug log (only the most important messages) for playing a few different movies while running windows at 60hz, xbmc set to 1080p fullscreen and adjust refresh rate enabled:
Code:
23:51:40 T:8744 M:1223294976  NOTICE: Desktop Resolution: 1920x1080 32Bit at 60Hz
23:51:40 T:8744 M:1165058048    INFO: GUI format 1920x1080 1920x1080 @ 60.00Hz (Full Screen)
23:51:41 T:8744 M:1152270336   ERROR: unable to load:special://home/skin/Aeon/720p/Pointer.xml, Line 0
23:51:58 T:13524 M:1133248512    INFO: ffmpeg:     Stream #0.0(eng): Video: h264, yuv420p, 1280x534, PAR 1:1 DAR 640:267, 23.98 tbr, 1k tbn, 47.95 tbc

23:51:58 T:9868 M:1133051904   DEBUG: CVideoReferenceClock: Setting up Direct3d on adapter 0
23:51:58 T:7976 M:1126453248   DEBUG: CDVDPlayerVideo::OutputPicture - change configuration. 1280x534. framerate: 23.98
23:51:58 T:7976 M:1126338560  NOTICE: Display resolution ADJUST : 1920x1080 @ 24.00Hz (42)
23:51:59 T:9868 M:1079681024   DEBUG: CVideoReferenceClock: CreateDevice returned D3DERR_DEVICELOST, resetting device
23:51:59 T:9868 M:1079681024   ERROR: CThread::staticThread : Access violation at 0x006009dc: Reading location 0x00000000
23:52:12 T:33392 M:1103327232    INFO: ffmpeg:     Stream #0.0: Video: h264, yuv420p, 1920x816, PAR 1:1 DAR 40:17, 23.98 tbr, 1k tbn, 47.95 tbc
23:52:12 T:43084 M:1103183872   DEBUG: CVideoReferenceClock: Setting up Direct3d on adapter 0
23:52:12 T:43084 M:1103151104   DEBUG: CVideoReferenceClock: Unable to register window class
23:52:12 T:43084 M:1103151104   DEBUG: CVideoReferenceClock: Setup failed, falling back to QueryPerformanceCounter
23:52:12 T:43084 M:1103151104   DEBUG: CVideoReferenceClock: Cleaning up Direct3d
23:52:12 T:7972 M:1091874816   DEBUG: CDVDPlayerVideo::OutputPicture - change configuration. 1920x816. framerate: 23.98
23:52:12 T:7972 M:1091874816  NOTICE: Display resolution ADJUST : 1920x1080 @ 24.00Hz (42)
23:52:26 T:12016 M:1100328960    INFO: ffmpeg:     Stream #0.0(eng): Video: h264, yuv420p, 1280x544, PAR 1:1 DAR 40:17, 23.98 tbr, 1k tbn, 47.95 tbc
23:52:26 T:39032 M:1100206080   DEBUG: CVideoReferenceClock: Setting up Direct3d on adapter 0
23:52:26 T:39032 M:1100169216   DEBUG: CVideoReferenceClock: Unable to register window class
23:52:26 T:39032 M:1100169216   DEBUG: CVideoReferenceClock: Setup failed, falling back to QueryPerformanceCounter
23:52:26 T:39032 M:1100169216   DEBUG: CVideoReferenceClock: Cleaning up Direct3d
23:52:26 T:21332 M:1093251072   DEBUG: CDVDPlayerVideo::OutputPicture - change configuration. 1280x544. framerate: 23.98
23:52:26 T:21332 M:1093206016  NOTICE: Display resolution ADJUST : 1920x1080 @ 24.00Hz (42)
23:52:41 T:8092 M:1061670912    INFO: ffmpeg:     Stream #0.0(eng): Video: h264, yuv420p, 1920x1080, PAR 1:1 DAR 16:9, 24 tbr, 1k tbn, 47.95 tbc
23:52:41 T:21860 M:1061478400   DEBUG: CVideoReferenceClock: Setting up Direct3d on adapter 0
23:52:41 T:21860 M:1061445632   DEBUG: CVideoReferenceClock: Unable to register window class
23:52:41 T:21860 M:1061429248   DEBUG: CVideoReferenceClock: Setup failed, falling back to QueryPerformanceCounter
23:52:41 T:21860 M:1061429248   DEBUG: CVideoReferenceClock: Cleaning up Direct3d
23:52:41 T:2356 M:1042952192   DEBUG: CDVDPlayerVideo::OutputPicture - change configuration. 1920x1080. framerate: 24.00
23:52:41 T:2356 M:1042948096  NOTICE: Display resolution ADJUST : 1920x1080 @ 24.00Hz (42)
23:52:56 T:54404 M:1041039360    INFO: ffmpeg:     Stream #0.0(eng): Video: h264, yuv420p, 1280x720, PAR 1:1 DAR 16:9, 23.98 tbr, 1k tbn, 47.95 tbc
23:52:56 T:26256 M:1040863232   DEBUG: CVideoReferenceClock: Setting up Direct3d on adapter 0
23:52:56 T:26256 M:1040826368   DEBUG: CVideoReferenceClock: Unable to register window class
23:52:56 T:26256 M:1040826368   DEBUG: CVideoReferenceClock: Setup failed, falling back to QueryPerformanceCounter
23:52:56 T:26256 M:1040826368   DEBUG: CVideoReferenceClock: Cleaning up Direct3d
23:52:56 T:34532 M:1030168576   DEBUG: CDVDPlayerVideo::OutputPicture - change configuration. 1280x720. framerate: 23.98
23:52:56 T:34532 M:1030168576  NOTICE: Display resolution ADJUST : 1920x1080 @ 24.00Hz (42)
Does any of this make any sense to you you guys?
"Unable to register window class", "CreateDevice returned D3DERR_DEVICELOST" and "CThread:ConfusedtaticThread : Access violation at 0x006009dc" sure looks suspicios to me, but I don't know what to make of it... Huh
Well, I don't know what the refreshrate change issue is, but the other issues I probably fixed in revisions 20329 and 20335.
What SVN you running?
20338 is running smooth as butter on ubuntu.

Thanks bobo1on1, that makes movie watching a whole lot more enjoyable Smile
bartdesign Wrote:20338 is running smooth as butter on ubuntu.

Thanks bobo1on1, that makes movie watching a whole lot more enjoyable Smile

Image

I hate to go offtopic but your rattie or possibly mouse is cute. ^_^
Quote:Crashes in linux with the binary ati driver.

Is this known issue with the ATI driver able to be resolved at some point or does it rely on the vsync stuff working without chewing up 100% CPU?

By binary ATI driver I assume you mean the latest Catalyst fglrx driver (what I'm using).

I just turned this on this new functionality to see what happened and the xbmc.bin process locked up hard. Couldn't even kill it using sudo kill -9. Had to restart the box.
It seems to start working and then fails.

Code:
CVideoReferenceClock: Setting up Direct3d on adapter 0
...
CVideoReferenceClock: Detected refreshrate: 60 hertz
...
CVideoReferenceClock: Clock speed 100.099992%
...
CVideoReferenceClock: Detected refreshrate: 24 hertz
CVideoReferenceClock: Displaymode changed
CVideoReferenceClock: Cleaning up Direct3d
CVideoReferenceClock: Setting up Direct3d on adapter 0
CVideoReferenceClock: CreateDevice returned D3DERR_DEVICELOST
CVideoReferenceClock: Setup failed, falling back to QueryPerformanceCounter
CVideoReferenceClock: Cleaning up Direct3d

Any other attempt after that, even after restarting XBMC, always results in this -

Code:
CVideoReferenceClock: CreateDevice returned D3DERR_DEVICELOST
CVideoReferenceClock: Setup failed, falling back to QueryPerformanceCounter

The only time I'll see it detecting the refresh rate again is after a reboot of Vista.

Full debug log.

EDIT: Build 20361.
hikaricore Wrote:I hate to go offtopic but your rattie or possibly mouse is cute. ^_^
It's my rat. Rats rule, they are very intelligent.
bartdesign Wrote:It's my rat. Rats rule, they are very intelligent.

is it planning to take over the world?
Pages: 1 2 3 4 5 6