public void TestRunInBlocking()
        {
            ProcessHandler p = new ProcessHandler(@"C:\Windows\System32\tree.com", @"c:\temp");

            ProcessHandler.ProcessOutput output = p.StartInBlockingMode();
            Assert.IsNotNull(output);
        }
예제 #2
0
        internal void CompressVideo(string sourceFileName, string destinationFileName)
        {
            KillFfmpegProcess();
            if (!File.Exists(sourceFileName))
            {
                throw new FileNotFoundException("File " + sourceFileName + " is not exist");
            }
            if (String.IsNullOrEmpty(destinationFileName))
            {
                throw new InvalidOperationException("Destination can't be empty");
            }
            File.Delete(destinationFileName);
            if (File.Exists(destinationFileName))
            {
                throw new InvalidProgramException("Failed to delete destination file.");
            }
            ProcessHandler compressProcess = new ProcessHandler(ffmpegPath + @"ffmpeg.exe", String.Format(COMPRESS_VIDEO, sourceFileName, destinationFileName));

            ProcessHandler.ProcessOutput processOutput = compressProcess.StartInBlockingMode();

            if (processOutput.ErrorCode != 0)
            {
                throw new InvalidProgramException("Failed to compress movie");
            }
        }
        public void TestRunInNonBlocking()
        {
            ProcessHandler p = new ProcessHandler(@"C:\Windows\System32\tree.com", @"c:\");

            p.StartInNonBlockingMode();
            Thread.Sleep(100);
            ProcessHandler.ProcessOutput output = p.WaitForProcessToEnd();
            Assert.IsNotNull(output);
        }
예제 #4
0
 /// <summary>
 /// Capture video without compressing. you usually would like to compress the video after saving it.
 /// </summary>
 /// <param name="frameRate"></param>
 /// <param name="fileName">Should end with .mkv</param>
 internal void CaptureRawVideo(string fileName, float frameRate = 24)
 {
     KillFfmpegProcess();
     if (null == fileName)
     {
         throw new ArgumentNullException("Arguments can't be null");
     }
     File.Delete(fileName);
     ffmpegProcess = new ProcessHandler(ffmpegPath + @"ffmpeg.exe", String.Format(CAPUTRE_VIDEO_RAW, frameRate, fileName));
     ffmpegProcess.StartInNonBlockingMode();
 }
예제 #5
0
 /// <summary>
 /// Stat capturing the video.
 ///
 /// This is a none blocking operation.
 /// </summary>
 /// <param name="frameRate">The framerate to capture the video</param>
 /// <param name="fileName">Name of the output file. should end with .mp4</param>
 internal void CaptureCompressedVideo(string fileName, float frameRate = 24)
 {
     if (null == fileName)
     {
         throw new ArgumentNullException("Arguments can't be null");
     }
     KillFfmpegProcess();
     File.Delete(fileName);
     ffmpegProcess = new ProcessHandler(ffmpegPath + @"ffmpeg.exe", String.Format(CAPTURE_VIDEO_WITH_COMPRESSION, frameRate, fileName));
     ffmpegProcess.StartInNonBlockingMode();
 }
예제 #6
0
        internal void TrimMovie(string sourceFileName, string destinationFileName, int timeToKeepInSeconds)
        {
            KillFfmpegProcess();
            TimeSpan movieLength = FetchVideoDetails(sourceFileName).Duration;

            File.Delete(destinationFileName);
            ProcessHandler trimProcess = new ProcessHandler(ffmpegPath + @"ffmpeg.exe", String.Format(TRIM_COMPRESSED_MOVIE, movieLength - TimeSpan.FromSeconds(timeToKeepInSeconds), sourceFileName, TimeSpan.FromSeconds(timeToKeepInSeconds), destinationFileName));

            ProcessHandler.ProcessOutput processOutput = trimProcess.StartInBlockingMode();
            if (processOutput.ErrorCode != 0)
            {
                throw new InvalidProgramException("Failed to trim movie");
            }
        }
예제 #7
0
        internal VideoDetails FetchVideoDetails(string fileName)
        {
            KillFfmpegProcess();
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("File " + fileName + " is not exist");
            }
            ProcessHandler compressProcess = new ProcessHandler(ffmpegPath + @"ffprobe.exe", String.Format(GET_VIDEO_DETAILS, fileName));

            ProcessHandler.ProcessOutput processOutput = compressProcess.StartInBlockingMode();
            if (processOutput.ErrorCode != 0)
            {
                throw new InvalidProgramException("Failure while trying to fetch video details: " + processOutput.Stderror);
            }
            Regex           rgx     = new Regex(VIDEO_DETAILS_REGEX);
            MatchCollection matches = rgx.Matches(processOutput.Stderror);

            if (matches.Count == 0)
            {
                throw new InvalidProgramException("Failed to fetch duration");
            }
            return(new VideoDetails(TimeSpan.Parse(matches[0].Groups[1].Value)));
        }