Ejemplo n.º 1
0
        public override List<StreamIdentifier> SetupTemplate(FFmpegCommand command, List<StreamIdentifier> streamIdList)
        {
            if (streamIdList.Count != 2)
            {
                throw new InvalidOperationException("Crossfade Concatenate requires two input video streams.");
            }

            var streamTo = streamIdList[1];
            var streamFrom = streamIdList[0];

            //grab the current length of the streamId specified
            var streamFromMetadata = MetadataHelpers.GetMetadataInfo(command, streamFrom);

            //from ==
            // - split
            //   - 1: start -> (end - durationOf)
            //   - 2: (end - durationOf) -> end

            //to ==
            // - split
            //   - 1: start -> (start + durationOf)
            //   - 2: (start + durationOf) -> end

            //blend ==
            // - from:2 / to:1

            //output ==
            // - (from:1, blend, to:2)

            var endMinusDuration = streamFromMetadata.VideoStream.VideoMetadata.Duration - Duration;

            var fromSplit = command.Select(streamFrom)
                                   .Filter(Filterchain.FilterTo<VideoStream>(new Split(2)));

            var fromMain = fromSplit.Take(0)
                                    .Filter(new TrimVideo(null, endMinusDuration.TotalSeconds, VideoUnitType.Seconds));

            var fromBlend = fromSplit.Take(1)
                                     .Filter(new TrimVideo(endMinusDuration.TotalSeconds, null, VideoUnitType.Seconds));

            var toSplit = command.Select(streamTo)
                                 .Filter(Filterchain.FilterTo<VideoStream>(new Split(2)));

            var toBlend = toSplit.Take(0)
                                 .Filter(new TrimVideo(null, Duration.TotalSeconds, VideoUnitType.Seconds));

            var toMain = toSplit.Take(1)
                                .Filter(new TrimVideo(Duration.TotalSeconds, null, VideoUnitType.Seconds));

            var blendOut = command.Select(toBlend.StreamIdentifiers)
                                  .Select(fromBlend.StreamIdentifiers)
                                  .Filter(Filterchain.FilterTo<VideoStream>(new Blend(string.Format(CrossfadeAlgorithm, Duration.TotalSeconds))));

            var result = command.Select(fromMain.StreamIdentifiers)
                                .Select(blendOut.StreamIdentifiers)
                                .Select(toMain.StreamIdentifiers)
                                .Filter(Filterchain.FilterTo<VideoStream>(new Concat()));

            return result.StreamIdentifiers;
        }
Ejemplo n.º 2
0
        public override List<StreamIdentifier> SetupTemplate(FFmpegCommand command, List<StreamIdentifier> streamIdList)
        {
            if (streamIdList.Count != 1)
            {
                throw new InvalidOperationException("Crossfade Concatenate requires two input video streams.");
            }

            //trim ==
            // - trim filter
            // - reset PTS filter

            var result = command.Select(streamIdList)
                                .Filter(Filterchain.FilterTo<VideoStream>(TrimFilter, new SetPts(SetPtsExpressionType.ResetTimestamp)));

            return result.StreamIdentifiers;
        }
Ejemplo n.º 3
0
        public override List<StreamIdentifier> SetupTemplate(FFmpegCommand command, List<StreamIdentifier> streamIdList)
        {
            if (streamIdList.Count > 1)
            {
                throw new InvalidOperationException("Pulsate requires one input video stream.");
            }
            if (FrameRate <=0)
            {
                throw new InvalidOperationException("Pulsate requires frame rate > 0.");
            }

            var streamFrom = streamIdList[0];

            //output ==
            // - (zoom-in, zoom-out)

            int zoomFrameDuration = Convert.ToInt32(Duration.TotalSeconds * 0.5 * FrameRate); // it's a half for zoom-in and another half for zoom-out
            //var zoomFrameDuration = 100;

            var streamSplit = command.Select(streamFrom)
                //.WithInput<VideoStream>(BackgroundImagePath,SettingsCollection.ForInput(new DurationInput(Duration)))
                //.Filter(new TrimVideo(null, Duration.TotalSeconds * 0.5, VideoUnitType.Seconds))
                //.Filter(Filterchain.FilterTo<VideoStream>(new Fps(FrameRate),new Scale(Convert.ToInt32(meta.Width * 1.3), Convert.ToInt32(meta.Height * 1.3))))
                                   .Filter(new TrimVideo(null, Duration.TotalSeconds * 0.5, VideoUnitType.Seconds))

                                   .Filter(Filterchain.FilterTo<VideoStream>(new Split(2)));

            var zoomIn = streamSplit.Take(0)
                                    .Filter(Filterchain.FilterTo<VideoStream>(new ZoomPan("'min(zoom+0.1,1.2)'", zoomFrameDuration, "'iw/2-(iw/zoom/2)'", "'ih/2-(ih/zoom/2)'")))
                                    ;

            var zoomOut = streamSplit.Take(1)
                                    .Filter(Filterchain.FilterTo<VideoStream>(new ZoomPan("'if(lte(zoom,1.0),1.2,max(1.001,zoom-0.1))'", zoomFrameDuration, "'iw/2-(iw/zoom/2)'", "'ih/2-(ih/zoom/2)'")))
                                    ;

            var streamFromMetadata = MetadataHelpers.GetMetadataInfo(command, streamFrom);
            var meta = streamFromMetadata.VideoStream.VideoMetadata;

            var zoom = command
                                .Select(zoomIn.StreamIdentifiers)
                                .Select(zoomOut.StreamIdentifiers)
                                .Filter(Filterchain.FilterTo<VideoStream>(new Concat()))
                                .Filter(Filterchain.FilterTo<VideoStream>(new Scale(meta.Width, meta.Height)))
                                .Filter(new TrimVideo(null, Duration.TotalSeconds, VideoUnitType.Seconds))
                                ;

            //var nsrc = new Color();
            ////nsrc.Duration = Duration;
            //nsrc.FrameRate = FrameRate;
            //nsrc.Size = new System.Drawing.Size(Convert.ToInt32(meta.Width * 1.25), Convert.ToInt32(meta.Height * 1.25));

            var overlay = new OverlayEx();
            overlay.X = "W/2-w/2";
            overlay.Y = "H/2-h/2";
            overlay.Format = OverlayVideoFormatType.Rgb;

            var result = command
                                //.WithInput<VideoStream>(BackgroundImagePath,SettingsCollection.ForInput(new DurationInput(Duration)))
                                //.Filter(new TrimVideo(null, Duration.TotalSeconds * 0.5, VideoUnitType.Seconds))
                                //.Filter(Filterchain.FilterTo<VideoStream>(new Fps(FrameRate),new Scale(Convert.ToInt32(meta.Width * 1.3), Convert.ToInt32(meta.Height * 1.3))))
                                .Select(zoom.StreamIdentifiers)
                                //.Filter(Filterchain.FilterTo<VideoStream>(overlay))
                                ;

            return result.StreamIdentifiers;
        }