Smoothvideo ("Sync playback to display" feature) now merged in the mainline branch

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Closed
bobo1on1 Offline
cheapass Team-XBMC Developer
Posts: 2,758
Joined: Dec 2008
Reputation: 22
Thumbs Up  Smoothvideo ("Sync playback to display" feature) now merged in the mainline branch
Post: #1
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.
(This post was last modified: 2009-11-25 18:52 by bobo1on1.)
find
SlaveUnit Offline
Posting Freak
Posts: 1,736
Joined: Oct 2008
Reputation: 14
Location: San Diego
Post: #2
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.
(This post was last modified: 2009-05-15 18:32 by SlaveUnit.)
find
Louike Offline
Donor
Posts: 223
Joined: Sep 2008
Reputation: 0
Post: #3
edit: i had to disable trippe buffering (and remove d3overider) to get rid of tearing in the top quarter of the screen.
(This post was last modified: 2009-05-15 18:55 by Louike.)
find
wildonrio Offline
Senior Member
Posts: 222
Joined: Mar 2008
Reputation: 0
Post: #4
What's the latest revision that includes it?
(This post was last modified: 2009-05-15 23:26 by wildonrio.)
find
SlaveUnit Offline
Posting Freak
Posts: 1,736
Joined: Oct 2008
Reputation: 14
Location: San Diego
Post: #5
They all include it as of yesterday. Is that what you are asking?
find
wildonrio Offline
Senior Member
Posts: 222
Joined: Mar 2008
Reputation: 0
Post: #6
Yeah that works. Just making sure my version has it already.
find
seeker83 Offline
Member
Posts: 67
Joined: Apr 2009
Reputation: 0
Post: #7
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 Frown


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::staticThread : Access violation at 0x006009dc" sure looks suspicios to me, but I don't know what to make of it... Confused
find
bobo1on1 Offline
cheapass Team-XBMC Developer
Posts: 2,758
Joined: Dec 2008
Reputation: 22
Post: #8
Well, I don't know what the refreshrate change issue is, but the other issues I probably fixed in revisions 20329 and 20335.
find
SlaveUnit Offline
Posting Freak
Posts: 1,736
Joined: Oct 2008
Reputation: 14
Location: San Diego
Post: #9
What SVN you running?
find
bartdesign Offline
Member
Posts: 75
Joined: Jun 2008
Reputation: 0
Location: Netherlands
Post: #10
20338 is running smooth as butter on ubuntu.

Thanks bobo1on1, that makes movie watching a whole lot more enjoyable Smile
find
hikaricore Offline
Posting Freak
Posts: 1,515
Joined: Dec 2008
Reputation: 0
Location: Tuesday
Post: #11
bartdesign Wrote:20338 is running smooth as butter on ubuntu.

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

[Image: image.php?u=33581&dateline=1234735292]

I hate to go offtopic but your rattie or possibly mouse is cute. ^_^
find
dteirney Offline
Team-XBMC Developer
Posts: 830
Joined: Jul 2007
Reputation: 6
Location: New Zealand
Post: #12
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.
find
Hitcher Offline
Skilled Skinner
Posts: 10,639
Joined: Aug 2007
Reputation: 91
Location: Eastleigh, UK
Post: #13
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.
(This post was last modified: 2009-05-16 12:22 by Hitcher.)
find
bartdesign Offline
Member
Posts: 75
Joined: Jun 2008
Reputation: 0
Location: Netherlands
Post: #14
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.
find
Louike Offline
Donor
Posts: 223
Joined: Sep 2008
Reputation: 0
Post: #15
bartdesign Wrote:It's my rat. Rats rule, they are very intelligent.

is it planning to take over the world?
find
Thread Closed