locked
Play video on texture RRS feed

  • Question

  • Simple question: where to find an example of playing a video (like mpg, wmv, avi, dvd, blu-ray, etc.) using media foundation on a direct3d (directx 11) texture (ID3D11Texture2D) in c++?

    I've searched for days and couldn't find a clear answer for this simple question. Plenty of examples using directshow and directx 9, but no clear example using media foundation and directx 11. I found information on directshow (but that is/will be deprecated i read). I found information using managed directx (but i'm using c++). I found information that states that you need to use directx 9 (which seems odd, because both media foundation and directx 11 are the latest version and require vista or above). And still, if I need to use a shared device, where to find an example?

    If no examples exists, where should I start? I know how to play a video using media foundation and how to render a texture using direct3d 11. Both are in system or video memory. So basicly the direct3d texture should point to the media foundation video frame memory and have the same format (R8G8B8_UNORM?) and size. And make sure that the memory is not written to when being read. Another option is to copy the video frame data to texture data, but that would be a extra performance issue (and possibly not work with content copyright protection). Both options require some sort of callback when a new frame is available (a samplegrabber node?)

    Monday, March 7, 2011 10:41 PM

All replies

  • Hi Xoppa,

    I've searched A LOT and couldn't find anything useful either. I'm implementing something like this for MF and DirectX 9 and it seems to work alright now, but since I'm doing it for my company I'm afraid I can't post any code. I still got problems properly controlling the playback (i.e. pre rolling does not work, ...) but hopefully some moderator will react on my other postings. There seem to be at least two other forum members who try to implement the same thing besides you and me ... : )

    As to implementing this, look for the custom EVR presenter sample in the Code Gallery (see my other posts, in one of them there are links to the correct samples), use Direct3D 9Ex to create the textures inside the presenter and implement something to share the textures with your DirectX 11 device...

    Good luck... has taken me weeks and caused A LOT of headaches, but it is possible...

    Alex

    P.S.: The reason why you have to use directx9 at least for the part inside MediaFoundation is that the EVR is using Direct3D 9...

    Tuesday, March 8, 2011 11:19 AM
  • Hi,

    Thanks for your reply. If you look at the EVR presenter sample, it just doesn't seems right to have so much code for something so basic as rendering on a texture surface. I can't believe this is the way it is intended. For now i've implemented the IMFSampleGrabberSinkCallback interface and use UpdateSubresource to copy the sample content to the texture. This works and requires just a few lines of code, but is definitly not the best solution. Let's hope there will be a better solution in the future.

    Thanks

    Xoppa

    Tuesday, March 8, 2011 9:27 PM
  • Yes, it's a lot of code and I still don't get to do everything I want. Plus debugging media foundation has given me so many headaches and the documentation is pretty confusing... I think I read it 5-6 times from top to bottom and still find stuff which I only understand on the 7th read. But better this than nothing, I for one cannot wait for a better solution to arrive someday (in the sense of having to have some solution now).

    Bests

    Alex

    Wednesday, March 9, 2011 11:44 AM