Exemple #1
0
        protected VideoFrame GetSubtitledFrame(string text)
        {
            var blank     = DynamicEnv.BlankClip(width: GetVideoInfo().width, height: GetVideoInfo().height);
            var subtitled = blank.Subtitle(text.Replace("\n", "\\n"), align: 8, lsp: 0, size: 24);

            return(subtitled[0]);
        }
        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);
        }
Exemple #3
0
 protected Clip GetBlankClip(Clip clip, bool white)
 {
     if (clip.GetVideoInfo().pixel_type.HasFlag(ColorSpaces.CS_PLANAR | ColorSpaces.CS_INTERLEAVED))
     {
         return(DynamicEnv.BlankClip(clip, color_yuv: white ? 0xFF0000 : 0x000000));
     }
     if (clip.GetVideoInfo().pixel_type.HasFlag(ColorSpaces.CS_PLANAR))
     {
         return(DynamicEnv.BlankClip(clip, color_yuv: white ? 0xFF8080 : 0x008080));
     }
     return(DynamicEnv.BlankClip(clip, color: white ? 0xFFFFFF : 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);
        }
Exemple #5
0
        public dynamic ResizeRotate(
            Clip clip,
            string resizeFunc, string rotateFunc,
            int width, int height, int angle = 0,
            RectangleD crop = default)
        {
            if (clip == null || crop == RectangleD.Empty && width == clip.GetVideoInfo().width&& height == clip.GetVideoInfo().height)
            {
                return(clip.Dynamic());
            }

            var intCrop = Rectangle.FromLTRB(
                (int)Math.Floor(crop.Left),
                (int)Math.Floor(crop.Top),
                (int)Math.Floor(crop.Right),
                (int)Math.Floor(crop.Bottom)
                );

            if (!intCrop.IsEmpty)
            {
                clip = DynamicEnv.Crop(clip, intCrop.Left, intCrop.Top, -intCrop.Right, -intCrop.Bottom);
                crop = RectangleD.FromLTRB(
                    crop.Left - intCrop.Left,
                    crop.Top - intCrop.Top,
                    crop.Right - intCrop.Right,
                    crop.Bottom - intCrop.Bottom
                    );
            }

            dynamic resized;

            if (crop == RectangleD.Empty)
            {
                resized = clip.Dynamic().Invoke(resizeFunc, width, height);
            }
            else
            {
                resized = clip.Dynamic().Invoke(resizeFunc, width, height,
                                                src_left: crop.Left, src_top: crop.Top,
                                                src_width: -crop.Right, src_height: -crop.Bottom);
            }
            if (angle == 0)
            {
                return(resized);
            }
            return(resized.Invoke(rotateFunc, angle / 100.0));
        }
        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]);
        }
 public Clip GetBlankClip(Clip clip, bool white)
 {
     return(clip.GetVideoInfo().IsRGB() ?
            (Clip)DynamicEnv.BlankClip(clip, color: white ? 0xFFFFFF : 0) :
            (Clip)DynamicEnv.BlankClip(clip, color_yuv: white ? 0xFF8080 : 0x008080));
 }