How to render direct3d in a directshow source filter - c++

Using c++ in visual studio 2008. How can I render d3d content as a directshow source filter.
Matt

Why is DirectShow involved? A DirectShow source filter provides a stream of data for other filters to process. Direct3D is an API that allows for accessing the graphics card for rendering. DirectShow and Direct3D are two separate things.
If you want to render Direct3D content, then you use Direct3D. There are some Direct3D 9.0 samples here for you to examine. I suggest you start looking at the "Initialization" sample and work upwards from there.
Edit: If we're not talking about a full-blown high-performance graphics solution, you can refer to this Stack Overflow question and this MSDN forum question. Hopefully it can get you started.

There's a nice example video source filter at http://tmhare.mvps.org/downloads.htm "capture source filter"

Related

Creating a texture from a image in DX 12 VC++

I just want know Directx 12 API to create texture from image.
For DX11 it is D3DX11CreateShaderResourceViewFromFile and for DX9 it is D3DXCreateTextureFromFileEx and for DX12 ?
Things are a little bit better by now. Microsoft rewrote their DDSTextureLoader for DX12 and released it as part of their MiniEngine on GitHub
https://github.com/Microsoft/DirectX-Graphics-Samples/blob/master/MiniEngine/Core/DDSTextureLoader.cpp
You also may want to take a look at my derivative work that is intended to make use of the DDSTextureLoader a bit easier outside of MiniEngine.
https://github.com/ClemensX/ShadedPath12/blob/master/ShadedPath12/ShadedPath12/DDSTextureLoader.cpp
I use this loader for all my texture files. It parses DDS (DirectDrawSurface) file format pretty well, including mipmaps.
There isn't one.
Direct3D 12 is a low-level API. A very low-level API. It doesn't have convenience functions that create textures out of whole cloth from just a filename. If you want to create a texture, you have to work for it. You have to load the file, figure out what format you want it in, allocate memory for it by asking the system how much memory it would take, then go through a complex series of steps to transfer your loaded image into that memory.
The official 'utility header' for Direct3D 12 is d3dx12.h. It's an inline header and has no DLL or static library, so the functionality provided is limited to true helpers. It has no equivalent to D3DX11CreateShaderResourceViewFromFile. It is not included as part of the Windows SDK, but instead is provided under the MIT license and you are expected to just copy it into your project--it's included in the various DirectX 12 Visual Studio templates including my Direct3D Game templates.
You can use the DDSTextureLoader and WICTextureLoader modules provided in the DirectX Tool Kit for DirectX 12 for some ready-to-use texture loader for Direct3D 12. See this tutorial lesson.
It's worth noting that D3DX9, D3DX10, and D3DX11 are all deprecated and only available as part of the legacy DirectX SDK per MSDN. In other words, you shouldn't be using D3DX11CreateShaderResourceViewFromFile for your Direct3D 11 code. See this blog post for a full list of D3DX9/10/11 replacements. TL;DR: use DDSTextureLoader and WICTextureLoader in DirectX Tool Kit for DirectX 11.
Google keeps referring to this topic for questions around DX-12 and textures, so let's update.
1. Managed
If you insist on "managed" check out the samples with the last version of SharpDX (2019)
https://github.com/discosultan/dx12-game-programming
It provides a C# interface to DX-12 native and it works, there are a lot of very nice samples, including texturing,
09-Crate loads a single DDS texture and shows it on a cube
09-TexColumns shows basic UV-coordinate actions on various shapes
.. but IMHO it's not really advisable, to keep depending on the good old SharpDX library, because that library is not maintained anymore. I can't advise good alternatives for C# atm, I'm not an expert on Unity and Vulkan.
2. Unmanaged
As mentioned earlier in this topic, DX-12 things improve. They still do. Check out Chuck Walbourn's current samples here,
https://github.com/microsoft/Xbox-ATG-Samples
For straight PC/x64, you'll find this,
https://github.com/microsoft/Xbox-ATG-Samples/tree/master/PCSamples
For PC/UWP, you'll find this,
https://github.com/microsoft/Xbox-ATG-Samples/tree/master/UWPSamples
These are very nice x64 unmanaged C++ 14.0 examples, using DirectXtk for DirectX-12. Last update in the Master was 3 months ago. Examples involving textures, also straight bitmap textures are
SimpleTexturePC12 loads a single .jpg texture and shows it in front view
DirectXTKSimpleSample12 loads several textures
Graphics\VideoTexturePC12 shows a dynamic texture read from an .mp4 video
These projects are configured for VS2017, but they convert out of the box when loading them in VS2019 and they compile and run ok.
Other sources
A known switchboard on DX-12 is vinjn on github, his page is
http://www.vinjn.com/awesome-d3d12/
Navigate from there to study articles and find various other samples.
There is a 3dgep.com tutorial on the subject of DX12 textures, that is
https://www.3dgep.com/learning-directx-12-4/
.. accompanied by
https://github.com/jpvanoosten/LearningDirectX12

Video Playback in DirectX 11

Pretty self explanatory. Microsoft had DirectShow for DirectX 9, but using DirectShow with DX11 is a COM nightmare beyond words. Is there a standard for video rendering I haven't heard of, or perhaps a free third-party library for this purpose?
Edit: Thanks to Mgetz, I am aware of Microsoft's attempt at a solution, Media Foundation. However, it's limited to Windows 8+, which I would much prefer to avoid.
This may not exactly match your requirement, but for your GOAL, you may take a look on ffmpeg, libx264 and theora(for ogg sound) or faad(decode aac).
I have done using ffmpeg to open container(3gp/mp4 is simple to implment yourself btw if full GPL licence is a concern), libx264 to decode to frame and upload to opengl texture, performance is good (on mac pro it can render 50 fps for 1080p without optimization) and by getting your hand dirty you can have fun doing stupid things with the texture and 3d transforms.
Media Foundation says that it "enables the development of applications and components for using digital media on Windows Vista and later."
So, it looks like it should work for Vista, Windows 7, and Windows 8.
There is DirectX Video Acceleration 2.0 which has a fabulous API, the DXVA-HD (after one has seen VMR9's API, especially with that custom allocator/presenter for renderless drawing, every other API is fabulous :) )
Have a look at: https://msdn.microsoft.com/en-us/library/windows/desktop/ee663586(v=vs.85).aspx
Also, there is a sample in: https://msdn.microsoft.com/en-us/library/windows/desktop/dd756740(v=vs.85).aspx
Windows 7 is the minimum supported windows version
You will not believe how straight forward it is with this API to have it decode the video into your texture.

DirectShow webcam recording

I need to use DirectShow (C++) for recording a webcam and saving the data to a file.
I really don't know how DirectShow works, this is a "stage" (working experience), but at school we didn't study it.
I think the best way to implement this could be:
List the video devices connected to the computer
Select the correct camera (there will be only one)
Retrieve the video
Save it to a file
Now there are two problems:
Where can I find a good reference book or how do I start?
The saved video shouldn't be too big, does DirectShow provide a way to compress it?
I won't use OpenCV because sometime it doesn't work properly (It doesn't find the camera).
Are there any high level wrapper that could help?
EDIT: the program won't have a window, it will run in background called by a dll.
Where can I find a good reference book or how do I start?
DirectShow introduction material
The saved video shouldn't be too big, does DirectShow provide a way to compress it?
Yes it provides capabilities to attach codecs, that needs to be installed in the system. These are typically third party codecs (for reasons beyond the scope of brief answer). You might want to record into Windows Media files to not depend on third party codecs. SWee more on MSDN: Choosing a Compression Filter.

C++ video handling

What is the easiest method for reading in the raw data (raw RGB image data for each frame) from a video file, in C++.
I really would appreciate some good detailed responses, or helpful links. I intend to manipulate the data using inline assembly.
I am using microsoft visual C++ 2010 express.
If you want to manipulate the frame, OpenCV is a good tool. Here you have a pointer to read video.
You could use DirectShow for this purpose. There are many add-ons available to help you render most of the video formats. It also supports rendering images from webcams AFAIK. The other alternative would be to use MediaFoundation SDK that comes with Windows SDK 7.0. MediaFoundation SDK will supersede DirectShow in future.

How to overlay direct3d in directshow

I am looking for a tutorial or documentation on how to overlay direct3d on top of a video (webcam) feed in directshow.
I want to provide a virtual web cam (a virtual device that looks like a web cam to the system (ie. so that it be used where ever a normal webcam could be used like IM video chats)
I want to capture a video feed from a webcam attached to the computer.
I want to overlay a 3d model on top of the video feed and provide that as the output.
I had planned on doing this in directshow only because it looked possible to do this in it. If you have any ideas about possible alternatives, I am all ears.
I am writing c++ using visual studio 2008.
Use the Video Mixing Renderer Filter to render the video to a texture, then render it to the scene as a full screen quad. After that you can render the rest of the 3D stuff on top and then present the scene.
Are you after a filter that sits somewhere in the graph that renders D3D stuff over the video?
If so then you need to look at deriving a filter from CTransformFilter. Something like the EZRGB example will give you something to work from. Basically once you have this sorted your filter needs to do the Direct 3D rendering and, literally, insert the resulting image into the direct show stream. Alas you can't render the Direct3D directly to a direct show video frame so you will have to do your rendering then lock the front/back buffer and copy the 3D data out and into the direct show stream. This isn't ideal as it WILL be quite slow (compared to standard D3D rendering) but its the best you can do, to my knowledge.
Edit: In light of your update what you want is quite complicated. You need to create a source filter (You should look at the CPushSource example) to begin with. Once you've done that you will need to register it as a video capture source. Basically you need to do this by using the IFilterMapper2::RegisterFilter call in your DLLRegisterServer function and pass in a class ID of "CLSID_VideoInputDeviceCategory". Adding the Direct3D will be as I stated above.
All round you want to spend as much time reading through the DirectShow samples in the windows SDK and start modifying them to do what YOU want them to do.