protected override VideoFrame GetFrame(int n) { var info = GetOverlayInfo(n);//.Resize(Source.GetSize(), Overlay.GetSize()); if (Invert) { info = info.Invert(); } var res = NewVideoFrame(StaticEnv); var outClips = contexts.Select(ctx => RenderFrame(ctx, info)); //outClips = contexts.Select(ctx => ctx.Source); var hybrid = contexts.Count == 1 ? outClips.First() : DynamicEnv.CombinePlanes(outClips, planes: contexts.Select(p => p.Plane.GetLetter()).Aggregate(string.Concat), pixel_type: $"YUV4{4 / targetSubsample.Width}{(4 / targetSubsample.Width - 4) + 4 / targetSubsample.Height}P{GetVideoInfo().pixel_type.GetBitDepth()}"); if (BlankColor >= 0 && Mode == FramingMode.Fill) { var ctx = contexts.First(); var frameParams = ctx.CalcFrame(info); var mask = DynamicEnv.StaticOverlayRender(ctx.Source.ConvertToY8(), ctx.Overlay.ConvertToY8(), info.X, info.Y, info.Angle, info.Width, info.Height, info.GetCrop(), info.Diff, overlayMode: "blend", width: frameParams.FinalWidth, height: frameParams.FinalHeight, mode: (int)FramingMode.Mask); mask = InitClip(mask, ctx.TargetInfo.Width, ctx.TargetInfo.Height, 0xFF8080).Overlay(mask, frameParams.FinalX, frameParams.FinalY); var background = InitClip(hybrid, ctx.TargetInfo.Width, ctx.TargetInfo.Height, ctx.BlankColor);//, ctx.TargetInfo.Info.IsRGB() ? "RGB24" : "YV24"); hybrid = hybrid.Overlay(background, mask: mask.Invert()); } if (Debug) { hybrid = hybrid.Subtitle(info.DisplayInfo().Replace("\n", "\\n"), lsp: 0); } using VideoFrame frame = hybrid[info.FrameNumber]; Parallel.ForEach(planes, plane => { for (var y = 0; y < frame.GetHeight(plane); y++) { OverlayUtils.CopyMemory(res.GetWritePtr(plane) + y * res.GetPitch(plane), frame.GetReadPtr(plane) + y * frame.GetPitch(plane), res.GetRowSize(plane)); } }); return(res); }
private VideoFrame GetFrameWithSmooth(int n) { if (GetVideoInfo().pixel_type.IsRealPlanar()) { dynamic ProcessPlane(YUVPlanes plane, dynamic srcClip, dynamic overClip) => planes.Contains(plane) ? DynamicEnv.Invoke(nameof(ComplexityOverlay), srcClip, overClip, mask: Mask, steps: Steps, smooth: Smooth, preference: Preference) : Mask?srcClip.BlankClip(color_yuv : 0x00800000) : srcClip; var y = ProcessPlane(YUVPlanes.PLANAR_Y, Source.Dynamic().ExtractY(), Overlay.Dynamic().ExtractY()); var u = ProcessPlane(YUVPlanes.PLANAR_U, Source.Dynamic().ExtractU(), Overlay.Dynamic().ExtractU()); var v = ProcessPlane(YUVPlanes.PLANAR_V, Source.Dynamic().ExtractV(), Overlay.Dynamic().ExtractV()); return(DynamicEnv.CombinePlanes(y, u, v, planes: "YUV", sample_clip: Source)[n]); } var mask = DynamicEnv.Invoke(nameof(ComplexityOverlay), Source, Overlay, mask: true, steps: Steps, preference: Preference).Blur(Smooth); return(Mask ? mask[n] : Source.Dynamic().Overlay(Overlay, mask: mask)[n]); }