Sascha-L / WPF-MediaKit

Microsoft Public License
363 stars 115 forks source link

User FFD Show Decoder/filter instead of LAV Decoder #80

Closed rexn8r closed 6 years ago

rexn8r commented 6 years ago

Hello,

I want to implement a media player using WPFMediaKit. I suppose by default it uses LAV Decoder. I want to use FFDShow decoder/filter. I went through all the issues as well as on stackoverflow but could not find any solution. There was one question on stackoverflow regarding ffdshow decoder but it did not provide example. i.e. https://stackoverflow.com/questions/46390432/how-to-use-ffdshow-with-wpf-mediakit

this is what i have tried in my code;

player.MediaUriPlayer.VideoDecoder = "FFDShow Video Decoder";

but when i stop and close the file, i could see the graph spitting information in my debug panel in Visual Studio and i saw the graph was still using LAV Video Decoder.

how can i set the ffdshow decoder through code?

any example would be highly appreciated as i don't know how to find filter id etc. and include in the wpfmediakit source.

thanks rex

xmedeko commented 6 years ago

Debug MediaUriPlayer.OpenSource(). If the preferred VideoDecoder fails, then this falls back to the oldOpenSource() method, which just uses the first video decoder by the merit. Also, is DirectShowUtil.AddFilterToGraph successful?

rexn8r commented 6 years ago

Hi xmedeko,

thanks for your response. This is what i have done with the Test application provided in with the source code.

I uninstalled K-Lite code mega pack from my system. I downloaded ffdshow codec pack from https://sourceforge.net/projects/ffdshow-tryout/ and installed it.

I commented the following line in the test applicaiton;

mediaUriElement.MediaUriPlayer.SplitterSource = "ffdshow Video Decoder";

Then i ran the test application and selected an MP4 file from one of my folder. I started debug with OpenSource routine.

The function could not find LAV video decoder so it went to oldOpenSource code block.

In the CreateVideoRenderer function, i could see the program is moving to "CreateVideoMixingRenderer9" function call and created the renderer.

Next, the "VideoPinFrom" is null so hasvideo is set to false

finally it throws "Could not render any streams from the source Uri" message.

The message on the form says "Could not add SplitterSource to Graph".

I then stopped debugging and un-commented the following line;

mediaUriElement.MediaUriPlayer.SplitterSource = "ffdshow Video Decoder";

and ran the program. The opensource function found the ffdshow filter and added it into the graph but threw following error;

"Unable to cast COM object of type 'System.__ComObject' to interface type 'DirectShowLib.IFileSourceFilter'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{56A868A6-0AD4-11CE-B03A-0020AF0BA770}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

then the routine went to oldOpenSource() and still the hasvideo = false and finally "Could not render any streams from the source Uri" error.

I opened up "ffdshow video decoder configuration" window and set "libavcodec" as decoder to all the file types. Clicked on "Directshow control" tab and set the merit to very high and also unchecked both the check boxes to use ffdshow in mpc player...

Still there is no luck to play mp4 file.

any thoughts on why it would not play with ffdshow codec?

thanks rex

xmedeko commented 6 years ago

I do not understand DirectX video in such a depth to help you.

It's strange the video filter does not implement IFileSourceFilter. Probably, the AddFilterToGraph() should skip such filters. If you run the program form VisualStudio, you should see debug logs from AddFilterToGraph() in the debug output, so you should see a log Added filter: ... and maybe some errors.

Also, check GraphStudioNext with your mp4 file. It will show you the default DirectX graph - which splitter and filters are used?

BTW are you sure you need ffdshow? The LAV codecs are considered to supersede the ffdshow. Check the https://sourceforge.net/projects/ffdshow-tryout/ - last update: 2015-08-09.

rexn8r commented 6 years ago

hi xmedeko,

it's working now.

I installed K-Lite codec corporate pack which doesn't have LAV video decoder. I ran the codec tool (Win7DSFilterTweaker_2.9.exe) and set ffdshow as preferred decoder.

I then ran Graphstudio and loaded the mp4 file and i could see ffdshow as the filter added into the graph.

I ran the program and now i can see it picking up the ffdshow filter and playing the video file as expected by the "oldOpenSource()" function..

thanks rex

xmedeko commented 6 years ago

Maybe you can still set the SplitterSource and VideoDecoder not to fall into the oldOpenSource() and if you really want to enforce the ffdshow even on machines, which have LAV codecs installed.