private static IEnumerable<string> ExecuteFFMPEGAndGetImageFiles(ImageJobGroup imageJobGroup, string mediaFilePath) { using (var ffmpeg = new FFMPEGProcess(new FFMPEGProcessSettings(mediaFilePath, imageJobGroup.Timestamp - TimeSpan.FromSeconds(1)))) { ffmpeg.Execute(); } return GetImageFilePaths(imageJobGroup, mediaFilePath); }
private static IEnumerable<string> GetImageFilePaths(ImageJobGroup group, string mediaFilePath) { var rootMediaFileName = Path.GetFileNameWithoutExtension(mediaFilePath); return Directory.EnumerateFiles( Directory.GetCurrentDirectory(), string.Format( "AUTOGEN_({0})_TIME_({1})_SNAPSHOT*.png", rootMediaFileName, FFMPEGProcess.FormatTimeSpanFileName(group.Timestamp) ) ); }
/// <summary> /// Groups ImageJobs by their timestamp /// </summary> /// <param name="imageJobs">The ImageJobs object containing all of the individual ImageJob(s)</param> /// <returns>A map between timestamps and ImageJobGroups</returns> public static IDictionary<TimeSpan, ImageJobGroup> GroupImageJobs(ImageJobs imageJobs) { var groups = new Dictionary<TimeSpan, ImageJobGroup>(); foreach (var imageJob in imageJobs.Images) { var focusTimeSpan = imageJob.SnapshotTimestamp; ImageJobGroup group; if (groups.TryGetValue(focusTimeSpan, out group) == false) { group = new ImageJobGroup { Jobs = new HashSet<ImageJob>(), Timestamp = focusTimeSpan, }; groups.Add(focusTimeSpan, group); } group.Jobs.Add(imageJob); } return groups; }
private static IEnumerable<string> TakeSnapshots(ImageJobGroup imageJobGroup, IEnumerable<string> mediaFilePaths) { return from mediaFilePath in mediaFilePaths.AsParallel() from snapshotPath in ExecuteFFMPEGAndGetImageFiles(imageJobGroup, mediaFilePath) select snapshotPath; }