protected override VideoFrame GetFrame(int n)
        {
            OverlayInfo info;

            lock (Child)
                using (var infoFrame = Child.GetFrame(n, StaticEnv))
                    info = OverlayInfo.FromFrame(infoFrame).First();
            var crop   = info.GetCrop();
            var hybrid = DynamicEnv.Invoke(Function,
                                           Engine, Source, Overlay, info.X, info.Y, info.Angle / 100.0, info.Width, info.Height,
                                           crop.Left, crop.Top, crop.Right, crop.Bottom, info.Diff);

            if (Debug)
            {
                hybrid = hybrid.Subtitle(info.ToString().Replace("\n", "\\n"), lsp: 0);
            }
            var res = NewVideoFrame(StaticEnv);

            using (VideoFrame frame = hybrid[n])
            {
                Parallel.ForEach(new[] { YUVPlanes.PLANAR_Y, YUVPlanes.PLANAR_U, YUVPlanes.PLANAR_V }, 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);
        }
        protected override VideoFrame GetFrame(int n)
        {
            OverlayInfo info;

            lock (Child)
                using (var infoFrame = Child.GetFrame(n, StaticEnv))
                    info = OverlayInfo.FromFrame(infoFrame);
            var hybrid = RenderFrame(info);

            if (debug)
            {
                hybrid = hybrid.Subtitle(info.ToString().Replace("\n", "\\n"), lsp: 0);
            }
            var res = NewVideoFrame(StaticEnv);

            using (VideoFrame frame = hybrid[n])
            {
                Parallel.ForEach(new[] { YUVPlanes.PLANAR_Y, YUVPlanes.PLANAR_U, YUVPlanes.PLANAR_V }, 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);
        }
Beispiel #3
0
        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);
        }