Beispiel #1
0
        public List <VideoThumbnailInfo> TakeThumbnails()
        {
            List <VideoThumbnailInfo> tempThumbnails = new List <VideoThumbnailInfo>();

            for (int i = 0; i < Options.ThumbnailCount; i++)
            {
                string mediaFileName = Path.GetFileNameWithoutExtension(MediaPath);

                int timeSliceElapsed;

                if (Options.RandomFrame)
                {
                    timeSliceElapsed = GetRandomTimeSlice(i);
                }
                else
                {
                    timeSliceElapsed = GetTimeSlice(Options.ThumbnailCount) * (i + 1);
                }

                string filename          = string.Format("{0}-{1}.{2}", mediaFileName, timeSliceElapsed, Options.ImageFormat.GetDescription());
                string tempThumbnailPath = Path.Combine(GetOutputDirectory(), filename);

                using (Process process = new Process())
                {
                    ProcessStartInfo psi = new ProcessStartInfo()
                    {
                        FileName        = FFmpegPath,
                        Arguments       = $"-ss {timeSliceElapsed} -i \"{MediaPath}\" -f image2 -vframes 1 -y \"{tempThumbnailPath}\"",
                        UseShellExecute = false,
                        CreateNoWindow  = true
                    };

                    process.StartInfo = psi;
                    process.Start();
                    process.WaitForExit(1000 * 30);
                }

                if (File.Exists(tempThumbnailPath))
                {
                    VideoThumbnailInfo screenshotInfo = new VideoThumbnailInfo(tempThumbnailPath)
                    {
                        Timestamp = TimeSpan.FromSeconds(timeSliceElapsed)
                    };

                    tempThumbnails.Add(screenshotInfo);
                }

                OnProgressChanged(i + 1, Options.ThumbnailCount);
            }

            return(Finish(tempThumbnails));
        }
Beispiel #2
0
        public List<VideoThumbnailInfo> TakeScreenshots()
        {
            List<VideoThumbnailInfo> tempScreenshots = new List<VideoThumbnailInfo>();

            for (int i = 0; i < Options.ScreenshotCount; i++)
            {
                string mediaFileName = Path.GetFileNameWithoutExtension(MediaPath);

                int timeSliceElapsed;

                if (Options.RandomFrame)
                {
                    timeSliceElapsed = GetRandomTimeSlice(i);
                }
                else
                {
                    timeSliceElapsed = GetTimeSlice(Options.ScreenshotCount) * (i + 1);
                }

                string filename = string.Format("{0}-{1}.{2}", mediaFileName, timeSliceElapsed, Options.ImageFormat.GetDescription());
                string tempScreenshotPath = Path.Combine(GetOutputDirectory(), filename);

                using (Process p = new Process())
                {
                    ProcessStartInfo psi = new ProcessStartInfo(FFmpegPath);
                    psi.WindowStyle = ProcessWindowStyle.Hidden;
                    psi.Arguments = string.Format("-ss {0} -i \"{1}\" -f image2 -vframes 1 -y \"{2}\"", timeSliceElapsed, MediaPath, tempScreenshotPath);
                    p.StartInfo = psi;
                    p.Start();
                    p.WaitForExit(1000 * 30);
                }

                if (File.Exists(tempScreenshotPath))
                {
                    VideoThumbnailInfo screenshotInfo = new VideoThumbnailInfo(tempScreenshotPath)
                    {
                        Timestamp = TimeSpan.FromSeconds(timeSliceElapsed)
                    };

                    tempScreenshots.Add(screenshotInfo);
                }

                OnProgressChanged(i + 1, Options.ScreenshotCount);
            }

            return Finish(tempScreenshots);
        }