private void bgWorker_DoWork(object sender, DoWorkEventArgs e) { // Note: having one background worker per file and running them all in parallel was tested // but it does more harm than good. BackgroundWorker bgWorker = sender as BackgroundWorker; List <string> filenames = e.Argument as List <string>; if (filenames.Count < 1 || bgWorker == null) { e.Result = null; return; } for (int i = 0; i < filenames.Count; i++) { if (bgWorker.CancellationPending) { break; } string filename = filenames[i]; VideoSummary summary = null; try { if (string.IsNullOrEmpty(filename)) { continue; } string extension = Path.GetExtension(filename); VideoReader reader = VideoTypeManager.GetVideoReader(extension); int numberOfThumbnails = 5; if (reader != null) { summary = reader.ExtractSummary(filename, numberOfThumbnails, maxImageSize); } } catch (Exception exp) { log.ErrorFormat("Error while extracting video summary for {0}.", filename); log.Error(exp); } if (summary == null) { summary = new VideoSummary(filename); } bgWorker.ReportProgress(i, summary); } }
public OpenVideoResult Load(string filePath) { // Instanciate appropriate video reader class depending on extension. string extension = Path.GetExtension(filePath); videoReader = VideoTypeManager.GetVideoReader(extension); if (videoReader != null) { videoReader.Options = new VideoOptions(PreferencesManager.PlayerPreferences.AspectRatio, PreferencesManager.PlayerPreferences.DeinterlaceByDefault); return(videoReader.Open(filePath)); } else { return(OpenVideoResult.NotSupported); } }
public OpenVideoResult Load(string filePath) { // Instanciate appropriate video reader class. string sequenceFilename = FilesystemHelper.GetSequenceFilename(filePath); if (!string.IsNullOrEmpty(sequenceFilename)) { videoReader = VideoTypeManager.GetImageSequenceReader(); filePath = Path.Combine(Path.GetDirectoryName(filePath), sequenceFilename); } else { if (FilesystemHelper.IsReplayWatcher(filePath)) { // This happens when we first load a file watcher into this screen. // Subsequent calls by the watcher will use the actual file name. // For this initial step, run the most recent file of the directory, if any. filePath = FilesystemHelper.GetMostRecentFile(Path.GetDirectoryName(filePath)); if (string.IsNullOrEmpty(filePath)) { // If the directory doesn't have any supported files yet it's not an error, we just load an empty player and get ready. return(OpenVideoResult.EmptyWatcher); } } videoReader = VideoTypeManager.GetVideoReader(Path.GetExtension(filePath)); } if (videoReader != null) { videoReader.Options = new VideoOptions(PreferencesManager.PlayerPreferences.AspectRatio, ImageRotation.Rotate0, Demosaicing.None, PreferencesManager.PlayerPreferences.DeinterlaceByDefault); return(videoReader.Open(filePath)); } else { return(OpenVideoResult.NotSupported); } }