public void GetMjpegStringWithNumFrameMoreDurationTest() { //Arrange const string sourceFilePath = "source file path"; const string destinationPath = "my path"; const string destinationFileName = "my file"; string destinationFilePath = Path.Combine(destinationPath, destinationFileName); MetadataServiceConfigurator serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator(); var metadata = new VideoMediaInfo { VideoDuration = (int)serviceConfigurator.ScreenshotTime.TotalMilliseconds - 1, VideoWidth = 4096, VideoHeight = 2304 }; var metadataService = new MetadataService(serviceConfigurator, metadata); var stringBuilder = new FfmpegService(metadataService, sourceFilePath, destinationPath, destinationFileName); string ffmpegStr = "-i \"{0}\" -f image2 -ss {1} -frames:v 1 -y \"{2}.jpg\""; ffmpegStr = String.Format(ffmpegStr, sourceFilePath, 0, destinationFilePath); //Act string str = stringBuilder.GetStringForScreenshot(); //Assert Assert.AreEqual(ffmpegStr, str); }
private void StartScreenshot(MetadataServiceConfigurator serviceConfigurator, string[] filePathes) { int count = 0; double avgEncodeFps = 0; var errorVideos = new List <string>(); var allSw = new Stopwatch(); var decodeSw = new Stopwatch(); foreach (string filePath in filePathes) { allSw.Restart(); Trace.WriteLine(String.Format("\n-------------Start decode file: {0}-------------\n", filePath)); try { string destinationFileName = GetDestinationFileName(filePath); var mediaInfo = new MediaInfoWrapper(); var metadataInfo = new VideoMetadataInfo(mediaInfo); VideoMediaInfo metadata = metadataInfo.GetMetadata(filePath); var metadataService = new MetadataService(serviceConfigurator, metadata); var stringBuilder = new FfmpegService(metadataService, filePath, _destinationPath, destinationFileName); var ffmpeg = new Ffmpeg(stringBuilder); string ffmpegString = stringBuilder.GetStringForScreenshot(); WriteFileInfo(ffmpegString, metadata); decodeSw.Restart(); ffmpeg.StartScreenshotProcess(); allSw.Stop(); decodeSw.Stop(); WriteFinishProcess(decodeSw.Elapsed, allSw.Elapsed, ffmpeg.EncodeFps); avgEncodeFps += ffmpeg.EncodeFps; count++; } catch (MediaFormatException ex) { string errorMessage = String.Format("Error File:\t\t{0}.\nError Param:\t\t{1}", filePath, ex.Message); Trace.WriteLine(errorMessage); errorVideos.Add(errorMessage); } catch (ExternalProcessException ex) { string errorMessage = String.Format("Error File:\t\t{0}.\nFfmpeg return:\t\t{1}\n{2}", filePath, ex.Result, ex.Arguments); Trace.WriteLine(errorMessage); errorVideos.Add(errorMessage); } finally { Trace.WriteLine(String.Format("\n-------------Finish decode file: {0}-------------\n", filePath)); } } avgEncodeFps = avgEncodeFps / count; WriteFinishInfo(avgEncodeFps, count, errorVideos); }
public void GetMjpegStringWithNumFrameMoreDurationTest() { //Arrange const string sourceFilePath = "source file path"; const string destinationPath = "my path"; const string destinationFileName = "my file"; string destinationFilePath = Path.Combine(destinationPath, destinationFileName); MetadataServiceConfigurator serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator(); var metadata = new VideoMediaInfo { VideoDuration = (int) serviceConfigurator.ScreenshotTime.TotalMilliseconds - 1, VideoWidth = 4096, VideoHeight = 2304 }; var metadataService = new MetadataService(serviceConfigurator, metadata); var stringBuilder = new FfmpegService(metadataService, sourceFilePath, destinationPath, destinationFileName); string ffmpegStr = "-i \"{0}\" -f image2 -ss {1} -frames:v 1 -y \"{2}.jpg\""; ffmpegStr = String.Format(ffmpegStr, sourceFilePath, 0, destinationFilePath); //Act string str = stringBuilder.GetStringForScreenshot(); //Assert Assert.AreEqual(ffmpegStr, str); }
private void StartScreenshot(MetadataServiceConfigurator serviceConfigurator, string[] filePathes) { int count = 0; double avgEncodeFps = 0; var errorVideos = new List<string>(); var allSw = new Stopwatch(); var decodeSw = new Stopwatch(); foreach (string filePath in filePathes) { allSw.Restart(); Trace.WriteLine(String.Format("\n-------------Start decode file: {0}-------------\n", filePath)); try { string destinationFileName = GetDestinationFileName(filePath); var mediaInfo = new MediaInfoWrapper(); var metadataInfo = new VideoMetadataInfo(mediaInfo); VideoMediaInfo metadata = metadataInfo.GetMetadata(filePath); var metadataService = new MetadataService(serviceConfigurator, metadata); var stringBuilder = new FfmpegService(metadataService, filePath, _destinationPath, destinationFileName); var ffmpeg = new Ffmpeg(stringBuilder); string ffmpegString = stringBuilder.GetStringForScreenshot(); WriteFileInfo(ffmpegString, metadata); decodeSw.Restart(); ffmpeg.StartScreenshotProcess(); allSw.Stop(); decodeSw.Stop(); WriteFinishProcess(decodeSw.Elapsed, allSw.Elapsed, ffmpeg.EncodeFps); avgEncodeFps += ffmpeg.EncodeFps; count++; } catch (MediaFormatException ex) { string errorMessage = String.Format("Error File:\t\t{0}.\nError Param:\t\t{1}", filePath, ex.Message); Trace.WriteLine(errorMessage); errorVideos.Add(errorMessage); } catch (ExternalProcessException ex) { string errorMessage = String.Format("Error File:\t\t{0}.\nFfmpeg return:\t\t{1}\n{2}", filePath, ex.Result, ex.Arguments); Trace.WriteLine(errorMessage); errorVideos.Add(errorMessage); } finally { Trace.WriteLine(String.Format("\n-------------Finish decode file: {0}-------------\n", filePath)); } } avgEncodeFps = avgEncodeFps/count; WriteFinishInfo(avgEncodeFps, count, errorVideos); }