Hello,
Welcome to Microsoft Q&A!
When you used overlay image, the alpha value has not been premultiplied. Before using the image, you could set the BitmapAlphaMode as Premultiplied to premultiply the alpha value. For example:
.cs:
private async void CreateOverlays()
{
var baseVideoClip = await MediaClip.CreateFromFileAsync(baseVideoFile);
composition = new MediaComposition();
composition.Clips.Add(baseVideoClip);
using (IRandomAccessStream stream = await overlayVideoFile.OpenAsync(FileAccessMode.ReadWrite))
{
var bitmap = new BitmapImage();
await bitmap.SetSourceAsync(stream);
var writeableBitmap = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
stream.Seek(0);
await writeableBitmap.SetSourceAsync(stream);
var logicalDpi = DisplayInformation.GetForCurrentView().LogicalDpi;
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
encoder.SetPixelData(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Premultiplied,
(uint)writeableBitmap.PixelWidth,
(uint)writeableBitmap.PixelHeight,
logicalDpi,
logicalDpi,
writeableBitmap.PixelBuffer.ToArray());
await encoder.FlushAsync();
stream.Dispose();
MediaClip overlayVideoClip = await MediaClip.CreateFromImageFileAsync(overlayVideoFile, TimeSpan.FromSeconds(10));
Rect videoOverlayPosition;
videoOverlayPosition.Height = mediaElement.ActualHeight / 3;
videoOverlayPosition.Width = (double)mediaElement.ActualWidth / 3;
videoOverlayPosition.X = 0;
videoOverlayPosition.Y = 0;
var videoOverlay = new MediaOverlay(overlayVideoClip);
videoOverlay.Position = videoOverlayPosition;
videoOverlay.Opacity = 0.75;
var overlayLayer = new MediaOverlayLayer();
overlayLayer.Overlays.Add(videoOverlay);
composition.OverlayLayers.Add(overlayLayer);
// Render to MediaElement
mediaElement.Position = TimeSpan.Zero;
mediaStreamSource = composition.GeneratePreviewMediaStreamSource((int)mediaElement.ActualWidth, (int)mediaElement.ActualHeight);
mediaElement.SetMediaStreamSource(mediaStreamSource);
}
}