How can I resize texture2d of SharpDX? I'm using SharpDX to Duplicate the screen and I use MediaFoundation to encode the texture into a video file. My problem is when I open an application into fullscreen and has a different resolution from system resolution I got a blank screen on my recording. Is there a better way I can resize the texture before encoding to mediafoundation without suffering performance? I'm using hardware accelerated. Thanks.
Asked
Active
Viewed 416 times
1 Answers
0
It depends on how exactly you use Media Foundation, but you can use the Video Processor MFT explicitly. You need to add this MFT to the topology if you use IMFMediaSession/IMFTopology. Or initialize and process the samples with this MFT if you use Sink Writer. In this case you need to supply the DX manager to the MFT, using MFT_MESSAGE_SET_D3D_MANAGER.
This MFT is only available on Windows 8 and higher. So if you need to support an older Windows version you can use Video Resizer, but it is not hardware accelerated.
Another option to resize the texture would be to create a render target of the desired size and draw the texture to it. After that you need to feed that render target to the encoder.

VuVirt
- 1,887
- 11
- 13
-
Hi Vulvrit thank you for your response. The last option is exactlty what I'am after but I ca't find any source code online on how to do it properly. I'm new to this d3d programming and still learning. Sometime I found code written in c++ and I just convert it to c#. – kripto Nov 27 '17 at 03:01
-
an Yes I use MFT_MESSAGE_SET_D3D_MANAGER. – kripto Nov 27 '17 at 03:06
-
Do you use IMFMediaSession/IMFTopology in your implementation? – VuVirt Nov 27 '17 at 06:12
-
I'm not totally sure but this is how I initialized my sink writer. please see link https://pastebin.com/te5wHTtX – kripto Nov 27 '17 at 06:29
-
I already see the link you provide but it only supports resizing to the power of 2 and does not allow resizing smaller texture to larger texture. I'm planning to use render target but I cant find tutorial on how to use it and how to grab the texture from the render target and pass it my texture allocator. – kripto Nov 27 '17 at 06:32
-
I think you should be able to send the new render target directly to the sink writer. Have you tried it? – VuVirt Nov 27 '17 at 06:35
-
Not yet but I dont think I will be able to do that because I'm feeding my sinkwriter with a generated sample from texture. sinkWriter.WriteSample(streamVidIndex, sample); – kripto Nov 27 '17 at 06:42
-
Yes sorry I meant you can wrap the render target directly with an imfsample. Or copy it to a 3d imfsample allocated by your imfsampleallocator. – VuVirt Nov 27 '17 at 07:16
-
Yes that's exactly what I've done but when I tried changing the resolution during my recording I'm getting a blank sample. render the texture with 1920x1080 on render target view and get the texture back from render target view with different resolution it can be smaller or larger resolution and then pass the texture to my encoder. so far this is my code https://pastebin.com/3TEaSKYS – kripto Nov 27 '17 at 07:36
-
Maybe you have to reinitialize the encoder (stream). – VuVirt Nov 27 '17 at 09:22