[UWP][VB]Limiting Stream Size For MediaCapture

Roy Li - MSFT 31,766 Reputation points Microsoft Vendor
2019-12-12T08:29:43.047+00:00

Source Link: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/2aa719db-7aa2-4b2f-bc39-b8fca5fda397/uwpvblimiting-stream-size-for-mediacapture?forum=wpdevelop

I have a MediaCapture from which I want to capture a stream, as follows:

Await Me.cardcapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreatePng(), stream)  

This works fine, except that the stream is larger than I want (I want to keep it below 2MB). I have looked at the following page:

https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/set-media-encoding-properties

But I wasn't quite sure what to do. I also tried the following page:

https://learn.microsoft.com/en-us/uwp/api/windows.media.capture.mediacapture.preparelowlagrecordtostreamasync

But I couldn't get it to work. All I need is to get a smaller stream, can anybody help me? Thanks.

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Roy Li - MSFT 31,766 Reputation points Microsoft Vendor
    2019-12-12T08:33:19.143+00:00

    Hello,

    Welcome to Microsoft Q&A!

    First, if you want to get smaller steam from CapturePhotoToStreamAsync, you could try to lower the steam resolution before you capture the photo using VideoDeviceController.SetMediaStreamPropertiesAsync() Method.

    Here is the test I tried on my side:
    alt text

    alt text
    From the screenshot, you could see that the size of the steam is smaller in the second test.

    For more information, you could refer to Scenario 2 of the official sample here: CameraResolution.

    0 comments No comments