• 1(current)
  • 2
  • 3
  • 4
  • 5
  • 7
[PATCH] Deinterlacing support for DXVA2 accelerated playback
#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:TonguerocessOverlays() 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:Tongueresent() 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.
Reply
#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 (usually it's enough to follow instructions in the second post).
Reply
#3
That would be great in future when we are watching SD Live TV in XBMC-PVR
Reply
#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.
Reply
#5
alanwww1 Wrote:Tested, works great on Intel Core i3 530 with BOB. Thanks for the patch

Can you share your compiled exe file ?
Reply
#6
I would like to test this out too if someone wants to share their compiled exe.
Image
thegamesdb.net - An open video games database.
scottbrant.net - Blog
Reply
#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.
Reply
#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 online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#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.
Reply
#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
Reply
#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.
Reply
#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.
Reply
#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
Reply
#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.
Reply
#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.
Reply
  • 1(current)
  • 2
  • 3
  • 4
  • 5
  • 7

Logout Mark Read Team Forum Stats Members Help
[PATCH] Deinterlacing support for DXVA2 accelerated playback3