UWP: How to record Screen and save as mp4 file?

2019-04-01 06:11发布

问题:

I have figured out how to capture the screen and output it back to a previewer using the sample here: Microsoft Screen Capture Documentation

Which is fine as far as it goes.

What I can't figure out, nor can I find any documentation is to take those frames and write them to a video file.

Ideally I want to stream them directly into an mp4 or similar which I can then use later with the MediaComposition system to do editing.

I found VideoFrame.CreateWithDirect3D11Surface but I can't figure out how to add a video frame to an existing video file. The documentation tells you how to create a video frame and how the properties work, but it doesn't tell you how to use a video frame inside a video file, nor can I find anything about how to create a video file without a camera or other capture device.

There's also some reference from the documentation GitHub where someone is asking the same where they say MediaStreamSample is the key, but there isn't any code for that either and certainly nothing that allows saving of the file. (Here's the issue)

One would think that it would be easy to record the screen with this api and dump those frames to a raw video file that you could then bring in and edit using the MediaComposition apis.

Help please!