[PATCH] Deinterlacing support for DXVA2 accelerated playback

  Thread Rating:
  • 3 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
a11599 Offline
Team-Kodi Member
Posts: 305
Joined: Sep 2010
Reputation: 3
Location: Budapest, Hungary
Post: #1
Hi All,

I just submitted a patch to enable deinterlacing on Windows with DXVA accelerated decoding. NOTE: VC-1 deinterlacing is not possible due to lack of interlaced VC-1 support in ffmpeg. It supports standard DXVA2 bob and advanced (HQ) deinterlace video processors. To keep the GUI lean, only four new options are added to deinterlace options with DXVA decoding: "Bob", "Best available" and their bottom field first counterparts marked with "(inverted)". If the best deinterlacer offered by the card is bob, bob will be used for "Best available" option as well.

Bob should work everywhere because it is required by DXVA specification. The "Best available" option evaluates all available DXVA processor devices available for the video format and looks for the processor offered with the "best" deinterlacing algorithm by the video driver. HQ deinterlacer preference is:
- Vector adaptive (Ati)
- Motion adaptive (Ati)
- Adaptive (Ati)
- Spatial-temporal (nVidia)
- Edge directed (?) (Intel)
- Bob

If the hardware does not report a known processor GUID which is better than standard Bob, processors will be ranked according to the reported deinterlacing technology and the number of reference samples required (the higher the better).

Automatic selection of deinterlace method based on stream properties is supported. Automatic deinterlacing uses internally the "Best available" option, but this can be constrained to bob using advancedsettings.xml if the video hardware is not capable of doing advanced deinterlacing above a certain resolution/framerate (see below).

As of v5, it is not possible to switch hardware deinterlace processors without reinitializing the entire decoder chain (quick switch) so switching between deinterlace methods should be very smooth now. If quick switch fails for some reason, the old codec reset method will be used. Quick switch can also be forced disabled in advancedsettings.xml if you are experiencing any troubles with it.

The following advancedsettings are supported (here with default values). Neither of them is mandatory, the patch works without advancedsettings straight out of the box.
Code:
<advancedsettings>
  <video>
    <dxvadeinterlace>
      <enablequickswitch>true</enablequickswitch>
      <automaxhqwidth>9999</automaxhqwidth>
      <automaxhqheight>9999</automaxhqheight>
      <automaxhqfps>99.9</automaxhqfps>
    </dxvadeinterlace>
  </video>
</advancedsettings>

<enablequickswitch>: Set to false to force disable quick switch and to revert old (pre-v5) behavior.

<automaxhq*>: Set these to force Bob deinterlace for automatic deinterlace method if your hardware has problems with HQ deinterlacing above certain resolutions/framerates. Bob will be used if the source material is greater either horizontally or vertically than the width and height specified AND the decoded framerate (ie. after deinterlacing) exceeds the maximum specified.

Example 1: Force Bob above 720i:
Code:
<automaxhqwidth>1280</automaxhqwidth>
<automaxhqheight>720</automaxhqheight>
<automaxhqfps>0</automaxhqfps>

Example 2: HQ works fine for 1080i50, but struggles with 1080i60:
Code:
<automaxhqwidth>1280</automaxhqwidth>
<automaxhqheight>720</automaxhqheight>
<automaxhqfps>50</automaxhqfps>

Example 2: Force Bob for all resolutions above 50 fps:
Code:
<automaxhqwidth>0</automaxhqwidth>
<automaxhqheight>0</automaxhqheight>
<automaxhqfps>50</automaxhqfps>

How does it work?

There are four new deinterlace methods: VS_INTERLACEMETHOD_DXVA_BOB, VS_INTERLACEMETHOD_DXVA_BOB_INVERTED, VS_INTERLACEMETHOD_DXVA_HQ and VS_INTERLACEMETHOD_DXVA_HQ_INVERTED. CWinRenderer::Supports() now reports true for the four new DXVA deinterlace methods as well as VS_INTERLACEMETHOD_AUTO if DXVA hardware decoding is used.

CProcessor::Render() evaluates whether the selected deinterlace method has changed or if the stream interlace format changed and deinterlace method is set to automatic. In these cases, CProcessor::SelectProcessor() is called to perform quick switch of processors. This method has also got a new parameter which is 1 if the source is interlaced and the bottom field has to be rendered and 0 in all other cases. Per DXVA2 specification the deinterlaced material has 2x frame rate as the original source. This parameter is used to display the "extra" frames. CWinRenderer::RenderProcessor() has been updated to provide the extra parameter.

CProcessor::Open() has been refactored and most of the init code has been moved to CProcessor::FindProcessors() and CProcessor::SelectProcessor().

CProcessor::FindProcessors() performs a lookup on supported hardware video processors and will store GUIDs of progressive, bob and high quality deinterlace processors. This runs only once when the processor is open. The largest number of references required by processors will be stored in m_size variable so the required reference samples are available for all processors during a mid-stream change.

CProcessor::SelectProcessor() is responsible to select and initialize the DXVA video processor depending on deinterlace method. If deinterlace method is set to automatic, the processor is selected based on the stream's interlaced type. When quick switch is disabled, m_size will be set to the amount of required reference samples of the selected processor. This decreases the number of textures allocated for progressive and bob-deinterlaced material for Ati (also maybe for others as well).

CProcessor::SetStreamSampleFormat() is used to tell the processor the stream format (DXVA2_Sample* enums). This method is called by CWinRenderer::AddProcessor(). CWinRenderer::AddProcessor() has now an additional parameter which contains the iFlags member of the CDVDVideoPicture struct to find out the stream's interlace format. CDVDVideoPlayer::ProcessOverlays() provides this information.

CProcessor::GetStreamSampleFormat() is used to query the current stream interlaced format. CProcessor::IsInitied() returns false if the processor was unable to perform quick switch and the processor failed to initialize.

CDecoder::Check() will call CProcessor::IsInited(). If it returns false then quick switch failed and a codec reset has to be performed. CProcessor::GetStreamSampleFormat() is then called and the result is stored so the decoder will be initialized with the proper SampleFormat (for automatic deinterlace method) when the codec is reinitialized.

CDecoder::OpenTarget() has been updated to prefer NV12 output, because usually it supports better quality hardware deinterlacers.

CXBMCRenderManager::Present() has been updated to call PresentBob() when any of the DXVA deinterlace options are selected, or deinterlace is automatic and source is interlaced. You can see in player statistics, that framerate is doubled with DXVA deinterlace options.
(This post was last modified: 2011-05-11 20:13 by a11599.)
find quote
ashlar Offline
Donor
Posts: 2,112
Joined: Mar 2006
Reputation: 27
Post: #2
Wow! Thank you! I can't wait for this to be included in the nightlies Big Grin

For troubleshooting and bug reporting please make sure you read this first.
find quote
Schumi Offline
Member
Posts: 57
Joined: Dec 2009
Reputation: 0
Post: #3
That would be great in future when we are watching SD Live TV in XBMC-PVR
find quote
alanwww1 Offline
Team-Kodi Member
Posts: 1,362
Joined: Nov 2008
Reputation: 33
Location: Hungary
Post: #4
Schumi Wrote:That would be great in future when we are watching SD Live TV in XBMC-PVR

Tested, works great on Intel Core i3 530 with BOB. Thanks for the patch

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote
Schumi Offline
Member
Posts: 57
Joined: Dec 2009
Reputation: 0
Post: #5
alanwww1 Wrote:Tested, works great on Intel Core i3 530 with BOB. Thanks for the patch

Can you share your compiled exe file ?
find quote
ghostelement Offline
Fan
Posts: 442
Joined: Sep 2010
Reputation: 3
Location: Portland, Oregon
Post: #6
I would like to test this out too if someone wants to share their compiled exe.

[Image: tgdb-buttonlogosmall.png]
thegamesdb.net - An open video games database.
scottbrant.net - Blog
find quote
alanwww1 Offline
Team-Kodi Member
Posts: 1,362
Joined: Nov 2008
Reputation: 33
Location: Hungary
Post: #7
ghostelement Wrote:I would like to test this out too if someone wants to share their compiled exe.

Not sure how to compile a release. I always tried a debug compile with Visual Studio 2010. I try to make a release out of it.

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote
Montellese Offline
Team-XBMC Developer
Posts: 3,753
Joined: Jan 2009
Reputation: 36
Location: Switzerland
Post: #8
alanwww1 Wrote:Not sure how to compile a release. I always tried a debug compile with Visual Studio 2010. I try to make a release out of it.

Run the BuildSetup.bat file in xbmc/project/Win32BuildSetup to get a full release with installer and everything.

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

[Image: badge.gif]
find quote
opdenkamp Offline
Team-XBMC PVR Developer
Posts: 2,224
Joined: Feb 2009
Reputation: 29
Location: Heerlen, The Netherlands
Post: #9
Schumi Wrote:That would be great in future when we are watching SD Live TV in XBMC-PVR
this will be nice for those windows users indeed, since most tv video streams are interlaced.

opdenkamp / dushmaniac

xbmc-pvr [Eden-PVR builds] [now included in mainline XBMC, so no more source link here :)]
personal website: [link]

Found a problem with PVR? Report it on Trac, under "PVR - core components". Please attach the full debug log.

If you like my work, please consider donating to me and/or Team XBMC.
find quote
ruben35 Offline
Junior Member
Posts: 2
Joined: Mar 2011
Reputation: 0
Post: #10
Hi
I use XBMC 10.1 (Win7-64)

Does this patch solve the VC-1 1080i video playback problem with the internal DSPlayer ?

what should I tweak to pull off the 1080i in ffdshow ?

See also:
http://forum.xbmc.org/archive/index.php/t-82929.html

Thanks for help
find quote
alanwww1 Offline
Team-Kodi Member
Posts: 1,362
Joined: Nov 2008
Reputation: 33
Location: Hungary
Post: #11
ruben35 Wrote:Hi
I use XBMC 10.1 (Win7-64)

Does this patch solve the VC-1 1080i video playback problem with the internal DSPlayer ?

what should I tweak to pull off the 1080i in ffdshow ?

See also:
http://forum.xbmc.org/archive/index.php/t-82929.html

Thanks for help

As i know it has nothing to do with DSplayer. It is an implementation of the dxva2 api interlacers.

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote
alanwww1 Offline
Team-Kodi Member
Posts: 1,362
Joined: Nov 2008
Reputation: 33
Location: Hungary
Post: #12
I created a build with the interlace patch for testing:

http://jkft.info/xbmc/Winbuilds/XBMCSetu...tch-dx.exe

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote
tocinillo Offline
Fan
Posts: 317
Joined: Dec 2010
Reputation: 2
Post: #13
alanwww1 Wrote:I created a build with the interlace patch for testing:

http://jkft.info/xbmc/Winbuilds/XBMCSetu...tch-dx.exe

Thanks, but "Live TV" dont show....Sad
find quote
alanwww1 Offline
Team-Kodi Member
Posts: 1,362
Joined: Nov 2008
Reputation: 33
Location: Hungary
Post: #14
tocinillo Wrote:Thanks, but "Live TV" dont show....Sad

It is not a PVR brach build ! It is from main trunk, with the dinterlace patch.

But you can test it ithout EPG and other stuff if you add your TV server as a source you can still test it. For TVHeadend:

htsp://your.ip.add.res

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote
a11599 Offline
Team-Kodi Member
Posts: 305
Joined: Sep 2010
Reputation: 3
Location: Budapest, Hungary
Post: #15
Hm, it looks like that (at least) Ati cards report all of their adaptive deinterlacers as pixel adaptive and I should distinguish between them based on GUID. That explains why I have three different DXVA processors with pixel adaptive technology. What a PITA. Will see how to handle that. Maybe a list of "preferred" GUIDs with deinterlace caps fallback mechanism... But according to the Cheese Slicies sample it looks like (my display is only 1680x1050) I get 1080i30 vector adaptive deinterlacing with my 3850 in XBMC which sounds pretty cool. Smile Will report back.
find quote
Post Reply