Exemplo 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.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);
        }
        public static CommandStage Select <TStreamType>(this FFmpegCommand command, int index)
            where TStreamType : class, IStream
        {
            var streamId = command.StreamIdentifier <TStreamType>(index);

            return(command.Select(streamId));
        }
        public static CommandStage WithInput <TStreamType>(this FFmpegCommand command, string fileName, SettingsCollection settings)
            where TStreamType : class, IStream
        {
            command.AddInput(fileName, settings);

            return(command.Select(command.LastInputStream <TStreamType>()));
        }
        public static CommandStage Select(this FFmpegCommand command, params CommandStage[] stages)
        {
            if (stages == null || stages.Length == 0)
            {
                throw new ArgumentNullException("stages");
            }

            return(command.Select(stages.ToList()));
        }
        public static CommandStage Select(this FFmpegCommand command, StreamIdentifier streamId)
        {
            var streamIdList = new List <StreamIdentifier>()
            {
                streamId
            };

            return(command.Select(streamIdList));
        }
        public static CommandStage Select(this FFmpegCommand command, CommandInput resource)
        {
            if (resource == null)
            {
                throw new ArgumentNullException("resource");
            }

            return(command.Select(resource.GetStreamIdentifier()));
        }
        public static CommandStage Select <TStreamType>(this FFmpegCommand command, CommandInput resource)
            where TStreamType : class, IStream
        {
            if (resource == null)
            {
                throw new ArgumentNullException("resource");
            }

            return(command.Select(resource.GetStreamIdentifier <TStreamType>()));
        }
        public static CommandStage Select(this FFmpegCommand command, List <CommandStage> stages)
        {
            var streams = new List <StreamIdentifier>();

            foreach (var commandStage in stages)
            {
                if (commandStage.StreamIdentifiers == null)
                {
                    continue;
                }

                streams.AddRange(commandStage.StreamIdentifiers);
            }

            return(command.Select(streams));
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        public static CommandStage WithInput <TStreamType>(this FFmpegCommand command, List <string> files)
            where TStreamType : class, IStream
        {
            if (files == null || files.Count == 0)
            {
                throw new ArgumentException("Files cannot be null or empty.", "files");
            }

            var streamIds = files.Select(fileName =>
            {
                command.AddInput(fileName);

                return(command.LastInputStream <TStreamType>());
            }).ToList();

            return(command.Select(streamIds));
        }
Exemplo n.º 11
0
        public static CommandStage Filter(this FFmpegCommand command, Filterchain filterchain)
        {
            var outputStreamIdentifiers = command.FilterchainManager.Add(filterchain, null);

            return(command.Select(outputStreamIdentifiers));
        }
Exemplo n.º 12
0
        public static CommandStage Take(this FFmpegCommand command, int index)
        {
            var streamId = command.StreamIdentifier(index);

            return(command.Select(streamId));
        }
Exemplo n.º 13
0
        public static CommandStage SelectAll(this FFmpegCommand command)
        {
            var streamIdList = command.Inputs.SelectMany(r => r.GetStreamIdentifiers()).ToList();

            return(command.Select(streamIdList));
        }
Exemplo n.º 14
0
        public static CommandStage Select(this FFmpegCommand command, params StreamIdentifier[] streamIds)
        {
            var streamIdList = new List <StreamIdentifier>(streamIds);

            return(command.Select(streamIdList));
        }
Exemplo n.º 15
0
        public static CommandStage WithInputNoLoad(this FFmpegCommand command, string fileName)
        {
            command.AddInputNoLoad(fileName);

            return(command.Select(command.LastInputStream()));
        }