[UWP][C#] How do I set the bitrate of a preview/recording within the MediaCapture API?

Alfonso Crawford 136 Reputation points
2021-10-31T15:57:54.003+00:00

I want to set the average bitrate of my MediaCapture recordings to 300 Kbps, so I don't have to transcode them down to that bitrate after each recording session. The purpose of reducing quality is to reduce the final size of the video files.

Setting the encoding property via SetEncoderProperty() doesn't appear to make any difference (the visual fidelity is the same). StartPreviewToCustomSinkAsync() looks promising, but I can't get a straight answer on what I'm supposed to plug in as a custom media sink.

I already have a video effect that watermarks the frames of the recording with a specified image: could I use that effect to lower the bitrate, as well?

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Roy Li - MSFT 32,071 Reputation points Microsoft Vendor
    2021-11-12T01:50:41.127+00:00

    Hello,

    Welcome to Microsoft Q&A!

    @Alfonso Crawford Sorry for the delay. I've talked with another engineer from the team and there is something that should help.

    In the beginning, you could create a MediaEncodingProfile object. Then you could specify one of the VideoEncodingQuality enums that will have a preset bitrate for the property.

    After that, you can create a MediaEncodingProfile where you can get the Video.Bitrate property. You can set it to a VideoEncodingQuality enum or override it. Now you can use your desired value when initializing the MediaCapture.

    Here is the code sample that you could refer to:

                var mediaEncodingProfile = new MediaEncodingProfile();  
                // you can use one of the  VideoEncodingQuality enums or you can choose to set to whatever you want  
                mediaEncodingProfile.Video.Bitrate = (uint)VideoEncodingQuality.Auto;  
       
                // now you can use mediaEncodingProfile.Video.Bitrate in initializing MediaCapture.SetEncoderProperty  
                MediaCapture.SetEncoderProperty(  
               MediaStreamType.VideoPreview,  
               new Guid("20332624-fb0d-4d9e-bd0d-cbf6786c102e"),   
               mediaEncodingProfile.Video.Bitrate);  
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments