Commits

Justin Lloyd committed 005d1eb

Used DisableAudio option instead of "-an" in extract image function
Switch from using raw string of options to using FFMPEGParameters structure in extract image function
Changed the exception message being thrown to properly insert the Environment.NewLine constant at the correct place
Added the DisableAudio option to FFMPEGParameters

  • Participants
  • Parent commits 14cf802

Comments (0)

Files changed (2)

FFMPEGWrapper/FFMPEGParameters.cs

         public Size Size = Size.Empty;
         public bool Overwrite;
         public bool SameQ;
+        public bool DisableAudio;
 
         public string VideoFilter;
 
                 AddOption("vf", VideoFilter);
             }
 
+            if (DisableAudio)
+            {
+                AddOption("an");
+            }
+
             if (!String.IsNullOrWhiteSpace(OutputOptions))
             {
                 AddSeparator(" ");

FFMPEGWrapper/VideoFile.cs

 
         public VideoFile(string filePath)
         {
-            //first make sure we have a value for the video file setting
             if (string.IsNullOrEmpty(filePath))
             {
                 throw new Exception("Could not find the location of the video file");
             }
 
-            //Now see if the video file exists
             if (!File.Exists(filePath))
             {
                 throw new Exception(String.Format("The video file {0} does not exist.", FilePath));
             return loadedImage;
         }
 
-        public Image ExtractSingleFrame(int positionToExtract)
+        public Image ExtractSingleFrame(int positionToExtract, Size dimensions = Size.Empty)
         {
             string tempFile = Path.ChangeExtension(Path.GetTempFileName(), "jpg");
-            string ffmpegParameters = string.Format("-f image2 -ss {1} -vframes 1 -an {0}", tempFile, positionToExtract);
-            string output = FFMPEG.Execute(FilePath, ffmpegParameters);
+            FFMPEGParameters parameters = new FFMPEGParameters()
+            {
+                InputFilePath = FilePath,
+                DisableAudio = true,
+                OutputOptions = String.Format("-f image2 -ss {0} -vframes 1", positionToExtract),
+                Size = dimensions,
+                OutputFilePath = tempFile,
+            };
+
+            ;
+            string output = FFMPEG.Execute(parameters);
 
             if (!File.Exists(tempFile))
             {
         {
             string output = FFMPEG.Execute(FilePath);
 
-            //get duration
             Duration = InfoProcessor.GetDuration(output);
-
-            //get audio bit rate
-            //AudioBitRate = FFMPEG.LastAudioBitRate;
             AudioBitRate = InfoProcessor.GetAudioBitRate(output);
-
-            //get the audio format
             AudioFormat = InfoProcessor.GetAudioFormat(output);
-
-            //get the video format
             VideoFormat = InfoProcessor.GetVideoFormat(output);
-
-            //get the video dimensions
             Dimensions = InfoProcessor.GetVideoDimensions(output);
         }
 
             string output = FFMPEG.Execute(parameters);
             if (File.Exists(tempOutputFile) == false)
             {
-                throw new ApplicationException(String.Format("Failed to watermark video {0}" + Environment.NewLine + "{1}", FilePath, output));
+                throw new ApplicationException(String.Format("Failed to watermark video {0}{1}{2}", FilePath, Environment.NewLine, output));
             }
 
             FileInfo watermarkedVideoFileInfo = new FileInfo(tempOutputFile);
             if (watermarkedVideoFileInfo.Length == 0)
             {
-                throw new ApplicationException(String.Format("Failed to watermark video {0}" + Environment.NewLine + "{1}", FilePath, output));
+                throw new ApplicationException(String.Format("Failed to watermark video {0}{1}{2}", FilePath, Environment.NewLine, output));
             }
 
             if (overwrite)