robmikh / SimpleRecorder

A simple screen recorder using both the Windows.Graphics.Capture and Windows.Media.Transcoding APIs.
MIT License
219 stars 43 forks source link

why not use win2d? #20

Closed jtorjo closed 4 years ago

jtorjo commented 4 years ago

Hi Rob,

It's really sad that Microsoft time and again doesn't believe in its own projects. You have an awesome lib (win2d), yet you use sharpDX.

Frankly, I would not have minded, but nothing works -- I'm trying to capture Thunderbird or notepad++ (just for testing, of course), and the end result is some part of the title. It seems to work fine 1 out of 10 times. This is completely unuseable code to me.

I can't bear to learn yet another library just for this.

robmikh commented 4 years ago

I should note that if you're having a problem capturing Thunderbird or Notepad++, Win2D is not going to fix your problem. What's your scenario? Is it your own code that's having these issues or SimpleRecorder? FWIW, I'm able to consistently capture both. What GPU are you using?

If you'd like to check out a Win2D version, that's actually what I started with. The last commit that used Win2D is at 9f6dd36e73bfd62f6515fd45cfa52552c64de07b.

Win2D is a fantastic library, and I use it in my other projects. But you should understand what the best tool for the job is. Win2D is a wrapper around Direct2D, which has its own way to enqueue work before sending it to the GPU. That poses a synchronization issue since the media code will also be partying on the same D3D device.

SharpDX on the other hand is just a set of bindings of Direct3D (I'm using D3D11). Since I'm not doing any complex operations, just copies, this is preferable. I can also control the synchronization this way. If I were doing this in C++, I wouldn't be using SharpDX and would be using Direct3D11 directly.

jtorjo commented 4 years ago

Thanks for showing me the last version with win2d. That's perfect - I'll definitely start from there.

Win2D is not going to fix your problem. What's your scenario? Is it your own code that's having these issues or SimpleRecorder? FWIW, I'm able to consistently capture both. What GPU are you using?

I have a video editor, and I want to add the capability to record the screen. As for GPU, I have an Nvidia with 2 GB or RAM.

I've looked again at your code - I think you're using a MediaTranscoder for capture. What I want to use is MediaComposition - I'm not entirely sure how easy this will be, but I should make it work.

I've started from here - https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/screen-capture

I can see that simple bitmap capture works (and it does work on Thunderbird and Notepad++), so I think this will definitely work.

robmikh commented 4 years ago

I'd be careful of using MediaComposition directly by feeding it individual frames. I haven't looked at how it's implemented, but the last time I used it it seemed to keep all frames in system memory. That can balloon really quickly if you're recording a longer video at 60Hz. It's really meant to be used to compose things, not to encode a video from frames.

I would look at first encoding the video somewhere to disk using MediaTranscoder and then import the resulting encoded video into MediaComposition.

Good luck!

jtorjo commented 4 years ago

@robmikh Thanks again for pointing me to the last version that was using win2d. That got me started. I did encountered a few bugs, did a bit (a lot, actually) of cursing, but right now, it works.

robmikh commented 4 years ago

I'd love to see your app once you ship the feature! 🙂

Let me know if you run into issues using the API.

jtorjo commented 4 years ago

Sounds good, will show you!