public static VideoResourceItem AddVideoResource(string filePath, BaseScheduleResourceContainer resourceContainer)
        {
            var resourceItem = resourceContainer.AddResource <VideoResourceItem>();

            if (!Directory.Exists(resourceItem.ResourceFolderPath))
            {
                Directory.CreateDirectory(resourceItem.ResourceFolderPath);
            }

            var sourceFilePath = Path.Combine(resourceItem.ResourceFolderPath,
                                              String.Format("{0}{1}", VideoResourceItem.VideoSourceFileName, Path.GetExtension(filePath)));

            File.Copy(filePath, sourceFilePath, true);

            var dataFilePath = Path.Combine(resourceItem.ResourceFolderPath, VideoResourceItem.VideoSourceDataFileName);

            ExtractVideoInfo(sourceFilePath, dataFilePath);

            var videoData = FFMpegData.LoadFromFile(dataFilePath);

            GenerateThumbnails(sourceFilePath, resourceItem.ResourceFolderPath, VideoResourceItem.VideoThumbnailFilePrefixName, videoData);

            return(resourceItem);
        }
        private static void GenerateThumbnails(
            string sourceFilePath,
            string destinationPath,
            string thumbnailFileNamePrefix,
            FFMpegData ffMpegData)
        {
            var allowToExit               = false;
            var converterPath             = Path.Combine(UtilitiesPath, "ffmpeg.exe");
            var destinationOutputFilePath = Path.Combine(destinationPath, String.Format("{0}%d.png", thumbnailFileNamePrefix));

            if (!File.Exists(sourceFilePath) || !File.Exists(converterPath))
            {
                return;
            }

            int    startDelay;
            int    endDelay;
            string imageExtractOption = "-vf \"{0},scale=-1:'min(ih,360)'\"";

            if (ffMpegData.Duration < 1)
            {
                startDelay         = 5;
                endDelay           = 5;
                imageExtractOption = String.Format(imageExtractOption, "fps=1") + " -vframes 1";
            }
            else if (ffMpegData.Duration < 10)
            {
                startDelay         = 1;
                endDelay           = 0;
                imageExtractOption = String.Format(imageExtractOption, "fps=1");
            }
            else if (ffMpegData.Duration < 30)
            {
                startDelay         = 5;
                endDelay           = 2;
                imageExtractOption = String.Format(imageExtractOption, "fps=1");
            }
            else if (ffMpegData.Duration < 180)
            {
                startDelay         = 5;
                endDelay           = 5;
                imageExtractOption = String.Format(imageExtractOption, "fps=1/2");
            }
            else if (ffMpegData.Duration < 300)
            {
                startDelay         = 5;
                endDelay           = 5;
                imageExtractOption = String.Format(imageExtractOption, "fps=1/6");
            }
            else
            {
                startDelay         = 7;
                endDelay           = 7;
                imageExtractOption = String.Format(imageExtractOption, "fps=1/30");
            }

            var targetDuration = ffMpegData.Duration - startDelay - endDelay;
            var videoConverter = new Process
            {
                StartInfo = new ProcessStartInfo(
                    converterPath,
                    String.Format("-i \"{0}\" -ss {2} -t {3} {4} \"{1}\"",
                                  sourceFilePath,
                                  destinationOutputFilePath,
                                  startDelay,
                                  targetDuration,
                                  imageExtractOption
                                  )
                    )
                {
                    UseShellExecute        = false,
                    RedirectStandardError  = false,
                    WindowStyle            = ProcessWindowStyle.Hidden,
                    RedirectStandardOutput = false,
                    CreateNoWindow         = true,
                },
                EnableRaisingEvents = true
            };

            videoConverter.Exited += (converterSender, converterE) =>
            {
                allowToExit = true;
            };
            videoConverter.Start();
            while (!allowToExit)
            {
                Thread.Sleep(2000);
            }
        }