Hello,
Welcome to Microsoft Q&A.
By testing, there is no effect in the MediaStreamSource
when we assign MediaEncodingProfile.Video.Bitrate
in your scenario.
You could use Windows.Media.Transcoding APIs to transcode video files from one format to another to show the effect of assigning bitrate.
Please check the following code as a sample:
private MediaComposition VideoComposition;
private MediaStreamSource mediaStreamSource;
private StorageFile destination;
……
private async void button_Click(object sender, RoutedEventArgs e)
{
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary;
picker.FileTypeFilter.Add(".mp4");
Windows.Storage.StorageFile pickedFile = await picker.PickSingleFileAsync();
if (pickedFile == null)
{
return;
}
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
destination = await localFolder.CreateFileAsync("destination.mp4",CreationCollisionOption.ReplaceExisting);
MediaEncodingProfile profile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.HD720p);
MediaTranscoder transcoder = new MediaTranscoder();
profile.Video.Bitrate = 50000; // Any Bitrate
PrepareTranscodeResult prepareOp = await
transcoder.PrepareFileTranscodeAsync(pickedFile, destination, profile);
if (prepareOp.CanTranscode)
{
var transcodeOp = prepareOp.TranscodeAsync();
transcodeOp.Completed +=
new AsyncActionWithProgressCompletedHandler<double>(TranscodeComplete);
}
else
{
switch (prepareOp.FailureReason)
{
case TranscodeFailureReason.CodecNotFound:
System.Diagnostics.Debug.WriteLine("Codec not found.");
break;
case TranscodeFailureReason.InvalidProfile:
System.Diagnostics.Debug.WriteLine("Invalid profile.");
break;
default:
System.Diagnostics.Debug.WriteLine("Unknown failure.");
break;
}
}
}
private async void TranscodeComplete(IAsyncActionWithProgress<double> asyncInfo, AsyncStatus asyncStatus)
{
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => {
var stream = await destination.OpenAsync(Windows.Storage.FileAccessMode.Read);
videoPlayer.SetSource(stream, destination.ContentType);
});
}
You could delete the destination
file if you do not want to save the file.
If the response is helpful, please click "Accept Answer" and upvote it.
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.