Beispiel #1
0
        /// <summary>
        /// Converts an image sequence to a video.
        /// </summary>
        /// <param name="output">Output video file.</param>
        /// <param name="frameRate">FPS</param>
        /// <param name="images">Image sequence collection</param>
        /// <returns>Output video information.</returns>
        public VideoInfo JoinImageSequence(FileInfo output, double frameRate = 30, params ImageInfo[] images)
        {
            var temporaryImageFiles = images.Select((image, index) =>
            {
                FFMpegHelper.ConversionSizeExceptionCheck(Image.FromFile(image.FullName));
                var destinationPath = image.FullName.Replace(image.Name, $"{index.ToString().PadLeft(9, '0')}{image.Extension}");
                File.Copy(image.FullName, destinationPath);

                return(destinationPath);
            }).ToList();

            var firstImage = images.First();

            var args = ArgumentsStringifier.FrameRate(frameRate) +
                       ArgumentsStringifier.Size(new Size(firstImage.Width, firstImage.Height)) +
                       ArgumentsStringifier.StartNumber(0) +
                       ArgumentsStringifier.Input($"{firstImage.Directory}\\%09d.png") +
                       ArgumentsStringifier.FrameOutputCount(images.Length) +
                       ArgumentsStringifier.Video(VideoCodec.LibX264) +
                       ArgumentsStringifier.Output(output);

            try
            {
                if (!RunProcess(args, output))
                {
                    throw new FFMpegException(FFMpegExceptionType.Operation, "Could not join the provided image sequence.");
                }

                return(new VideoInfo(output));
            }
            finally
            {
                Cleanup(temporaryImageFiles);
            }
        }