c# - MediaClip is not rendered with custom IBasicVideoEffect -
i trying apply saturation video effect implemented ibasicvideoeffect according https://github.com/aarononeal/media-contrib example.
when add videoeffectdefinition mediaclip, preview video set, nothing rendered. (video disappears)
private void addsaturationeffectbutton_click(object sender, routedeventargs e) { var clip = _composition.clips[0]; clip.videoeffectdefinitions.add(new videoeffectdefinition(typeof(saturationvideoeffect).fullname)); setupmediastreamsource(); }
saturationvideoeffect implemented in separated windows runtime component (universal windows) project.
using system; using system.collections.generic; using windows.foundation.collections; using windows.graphics.directx.direct3d11; using windows.media.effects; using windows.media.mediaproperties; using microsoft.graphics.canvas; using microsoft.graphics.canvas.effects; namespace videoeffectslibrary { public sealed class saturationvideoeffect : ibasicvideoeffect { private videoencodingproperties _currentencodingproperties; private canvasdevice _canvasdevice; private ipropertyset _configuration; private float saturation { { if (_configuration != null && _configuration.containskey("saturation")) return (float)_configuration["saturation"]; else return 0.5f; } set { _configuration["saturation"] = value; } } public void processframe(processvideoframecontext context) { using (canvasbitmap inputbitmap = canvasbitmap.createfromdirect3d11surface(_canvasdevice, context.inputframe.direct3dsurface)) using (canvasrendertarget rendertarget = canvasrendertarget.createfromdirect3d11surface(_canvasdevice, context.outputframe.direct3dsurface)) using (canvasdrawingsession ds = rendertarget.createdrawingsession()) { var saturation = new saturationeffect() { source = inputbitmap, saturation = this.saturation }; ds.drawimage(saturation); } } public void setencodingproperties(videoencodingproperties encodingproperties, idirect3ddevice device) { _currentencodingproperties = encodingproperties; _canvasdevice = canvasdevice.createfromdirect3d11device(device); canvasdevice.debuglevel = canvasdebuglevel.error; } public void setproperties(ipropertyset configuration) { _configuration = configuration; } public bool isreadonly { { return false; } } public mediamemorytypes supportedmemorytypes { { return mediamemorytypes.gpu; } } public bool timeindependent { { return false; } } public ireadonlylist<videoencodingproperties> supportedencodingproperties { { return new list<videoencodingproperties>() { // note: specifying width , height necessary due bug in media pipeline when // effect being used media capture. // can changed "0, 0" in future release of fbl_impressive. videoencodingproperties.createuncompressed(mediaencodingsubtypes.argb32, 800, 600) }; } } public void close(mediaeffectclosedreason reason) { // clean devices if (_canvasdevice != null) _canvasdevice.dispose(); } public void discardqueuedframes() { // no cached frames discard } } }
how can make effect run properly? help.
Comments
Post a Comment