I'm trying to get one video stream (like webcam) with MediaCapture and apply a Chromakey effect on it and overlay the result on another video stream (like another webcam) with MediaCapture too and record the result in a mp4 file during "live".

I've tried with custom video effect. The ChromaKeyEffect works but I've failed having the secondary input stream for put is as background in my effect class.

I've also try with MediaComposition but it doesn't work with MediaCapture. It use only MediaClips witch are not "live".

I don't know how should I do this.

Edit: In my page

            VideoEffectDefinition definition = new VideoEffectDefinition(typeof(AlphaOnMediaCaptureEffect).FullName);
            await mediaCapture.AddVideoEffectAsync(definition, MediaStreamType.VideoRecord);

In a AlphaOnMediaCaptureEffect: IBasicVideoEffect


 public async void ProcessFrame(ProcessVideoFrameContext context){
                using (CanvasBitmap inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(canvasDevice, context.InputFrame.Direct3DSurface))
                using (CanvasRenderTarget renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(canvasDevice, context.OutputFrame.Direct3DSurface, 96))
                using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession())
                    {

                    ChromaKeyEffect chromaKeyEffect = new ChromaKeyEffect
                    {
                        Source = inputBitmap,
                        Color = Color.FromArgb(255, 0, 255, 0),
                        Feather = true
                    };
                    chromaKeyEffect.Tolerance = 0.3f;

                    CompositeEffect compositeEffect = new CompositeEffect
                    {
                        Sources = { otherInputBitmap, chromaKeyEffect }
                    };
                    compositeEffect.Mode = CanvasComposite.SourceIn;
                    ds.DrawImage(compositeEffect);
}

I need another CanvasBitmap like inputBitmap (otherInputBitmap) which contains frames from a second mediacapture. I said "I've failed" because I didn't find a way to code this. I think I wrong in the "process" to obtain this live video overlay on a live video with an ChromaKeyEffect. I'm not sure that IBasicVideoEffect is the best way to do this.

0

There are 0 best solutions below