I attached video to canvas. On canvas user can draw line, rectangle etc. and these drawn object are hidden or visible according to time slice. Then user can save this video with that drawn object. I used the following code for this purpose. The issue is when I save it takes time almost equal to video length. How can I reduce this saving time or is there any other fast way save cropped canvas with drawn object
I used OpenCVSharp lib to create video from cropped canvas
Application.Current.Dispatcher.Invoke(() =>
{
canvas.VideoPlayer.mp1.Clock.Controller.SeekAlignedToLastTick(timeSpan1, System.Windows.Media.Animation.TimeSeekOrigin.BeginTime);
});
var writer = new VideoWriter(fileName, OpenCvSharp.FourCC.DIVX, frameRate, new OpenCvSharp.Size(vidSize.Width, vidSize.Height));
for (int i = startFrame; i < endFrame; i++)
{
CroppedBitmap croppedImage = new();
Application.Current.Dispatcher.Invoke(() =>
{
canvas.VideoPlayer.mp1.Position.Add(frameTimeInterval);
canvas.VideoPlayer.ShowHideToolsSaveAs(frame);
// --------> some time here it shows insufficient memeory when video is around 2 mins
RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, 96d, 96d, PixelFormats.Default);
rtb.Render(canvas);
// create cropped image
croppedImage = new CroppedBitmap(rtb, vidSize);
});
if (croppedImage != null)
{
System.Drawing.Bitmap bmp = new(width, height);
byte[] byteArray = new byte[1];
Application.Current.Dispatcher.Invoke(() =>
{
bmp = BitmapFromSource(croppedImage);
byteArray = BitmapToByteArray(bmp);
});
Mat mat = new();
mat = BitmapConverter.ToMat(bmp);
writer.Write(mat);
}