/// <summary> /// Processes the file as media item. OBSOLETE /// </summary> /// <param name="filename">The filename.</param> /// <param name="outputDirectory">The output directory.</param> private void processFile(string filename, string outputDirectory) { THelper.Information ("Processing {0} ...", filename); DateTime startTime = DateTime.Now; MSEEncoder.MediaItem mediaItem; try { mediaItem = new MSEEncoder.MediaItem (filename); } catch (MSEEncoder.InvalidMediaFileException) { THelper.Critical("\"" + filename + "\" isn't a video file."); return; } bool hasVideo = (mediaItem.OriginalFileType & MSEEncoder.FileType.Video) == MSEEncoder.FileType.Video; if (!hasVideo) { THelper.Critical ("\"" + filename + "\" isn't a video file."); return; } if (_tnSettings.End == TimeSpan.Zero) _tnSettings.End = mediaItem.FileDuration - new TimeSpan (0, 0, 5); else if (_tnSettings.End < TimeSpan.Zero) _tnSettings.End = mediaItem.FileDuration + _tnSettings.End; else if (_tnSettings.End > mediaItem.FileDuration) _tnSettings.End = mediaItem.FileDuration; DateTime mediaItemCreated = DateTime.Now; THelper.Information ("{0} to create Microsoft.Encoder.MediaItem.", (mediaItemCreated - startTime).ToString(@"h\:mm\:ss")); ThumbnailCreator tg; DateTime overviewCreated; int nThumbs; int originalBorder = _tnSettings.Border; _tnSettings.SrcRect = new System.Drawing.Rectangle (0, 0, mediaItem.OriginalVideoSize.Width, mediaItem.OriginalVideoSize.Height); double videoAspect = (double) mediaItem.OriginalVideoSize.Width / mediaItem.OriginalVideoSize.Height; _tnSettings.ThumbAspectRatio = videoAspect; int x, y, newWidth, newHeight; if (_cropAspect != 0.0) { if (_cropAspect > videoAspect) { x = 0; newWidth = mediaItem.OriginalVideoSize.Width; newHeight = (int) (mediaItem.OriginalVideoSize.Width / _cropAspect + 0.5); y = (int) ((mediaItem.OriginalVideoSize.Height - newHeight) / 2.0); } else { y = 0; newHeight = mediaItem.OriginalVideoSize.Height; newWidth = (int) (mediaItem.OriginalVideoSize.Height * _cropAspect + 0.5); x = (int) ((mediaItem.OriginalVideoSize.Width - newWidth) / 2.0); } _tnSettings.SrcRect = new System.Drawing.Rectangle (x, y, newWidth, newHeight); _tnSettings.ThumbAspectRatio = (double) newWidth / newHeight; } if (_stretchAspect != 0.0) { _tnSettings.ThumbAspectRatio = _stretchAspect; } if (!_skipOverview) { _tnSettings.Border = 1; tg = new ThumbnailCreator (_tnSettings, _debug); nThumbs = tg.GenerateOverviewThumbs (mediaItem, filename, outputDirectory); overviewCreated = DateTime.Now; THelper.Information ("{0} to create overview thumbnails.", (overviewCreated - mediaItemCreated).ToString(@"h\:mm\:ss")); THelper.Information ("{0} thumbs created. {1:F2} seconds / thumb.", nThumbs, (overviewCreated - mediaItemCreated).TotalSeconds / nThumbs); } else { overviewCreated = DateTime.Now; THelper.Information ("Overview page skipped."); } _tnSettings.Border = originalBorder; tg = new ThumbnailCreator (_tnSettings, _debug); nThumbs = 0; if (_tnSettings.Interval.TotalSeconds > 0) { TimeSpan originalInterval = _tnSettings.Interval; if (mediaItem.FileDuration.TotalMinutes < 45 && originalInterval.TotalSeconds > 2) _tnSettings.Interval = new TimeSpan (0, 0, 2); nThumbs = tg.GenerateMultiThumbs (mediaItem, filename, outputDirectory); _tnSettings.Interval = originalInterval; } DateTime multiCreated = DateTime.Now; if (nThumbs > 0) { THelper.Information ("{0} to generate multi-page thumbnails.", (multiCreated - overviewCreated).ToString(@"h\:mm\:ss")); THelper.Information ("{0} thumbs created. {1:F2} seconds / thumb.", nThumbs, (multiCreated - overviewCreated).TotalSeconds / nThumbs); } else { THelper.Information ("Multi-page thumbnails skipped."); } THelper.Information ("{0} overall time to process {1}.", (multiCreated - startTime).ToString(@"h\:mm\:ss"), filename); THelper.Information (); }
/// <summary> /// Generate thumbnail pages for the set of video files in list. /// </summary> /// <param name="filenames">A list of video files. Only a single /// thumbnail set is generated. Multiple files are /// treated as one long video.</param> /// <param name="displayFilename">The display filename to use for the video file /// set.</param> /// <param name="outputDirectory">The output directory.</param> private void ProcessFiles(List<string> filenames, string displayFilename, string outputDirectory) { DateTime startTime = DateTime.Now; AVFileSet avFiles = new AVFileSet (); MSEEncoder.AudioVideoFile avFile; DateTime tempStart, tempEnd; foreach (string filename in filenames) { try { THelper.Information ("Processing {0} ...", filename); tempStart = DateTime.Now; avFile = new MSEEncoder.AudioVideoFile (filename); tempEnd = DateTime.Now; THelper.Debug ("{0} to create Microsoft.Encoder.AudioVideoFile.", (tempEnd - tempStart).ToString (@"h\:mm\:ss\.ff")); } catch (MSEEncoder.InvalidMediaFileException) { THelper.Critical ("\"" + filename + "\" isn't a video file."); return; } tempStart = DateTime.Now; MSEEncoder.MediaItem mediaItem = new MSEEncoder.MediaItem (avFile); tempEnd = DateTime.Now; THelper.Debug ("{0} to create Microsoft.Encoder.MediaItem.", (tempEnd - tempStart).ToString (@"h\:mm\:ss\.ff")); bool hasVideo = (mediaItem.OriginalFileType & MSEEncoder.FileType.Video) == MSEEncoder.FileType.Video; if (!hasVideo) { THelper.Critical ("\"" + filename + "\" isn't a video file."); return; } tempStart = DateTime.Now; avFile.CalculateDuration (AVFileSet.IndexProgessHandler); Console.Write ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); tempEnd = DateTime.Now; THelper.Debug ("{0} to run CalculateDuration.", (tempEnd - tempStart).ToString (@"h\:mm\:ss\.ff")); THelper.Debug ("AudioVideoFile.Duration {0} {1}.", avFile.Duration.ToString (@"h\:mm\:ss\.ffff"), filename); THelper.Debug ("VideoStream.Duration {0} {1}.", AVFileSet.GetVideoDuration(avFile).ToString (@"h\:mm\:ss\.ffff"), filename); THelper.Debug ("AudioStream.Duration {0} {1}.", AVFileSet.GetAudioDuration(avFile).ToString (@"h\:mm\:ss\.ffff"), filename); THelper.Debug ("AudioStream channels = {0} {1}.", AVFileSet.GetAudioChannels(avFile), filename); avFiles.Add (avFile); } avFiles.UpdateTotals (); DateTime avFileSetCreated = DateTime.Now; THelper.Information ("{0} Total time to create AVFileSet.", (avFileSetCreated - startTime).ToString (@"h\:mm\:ss")); THelper.Debug ("Using {0} Layout Mode.", _tnSettings.LayoutMode); if (_tnSettings.End == TimeSpan.Zero) _tnSettings.End = avFiles.TotalDuration; else if (_tnSettings.End < TimeSpan.Zero) _tnSettings.End = avFiles.TotalDuration + _tnSettings.End; else if (_tnSettings.End > avFiles.TotalDuration) _tnSettings.End = avFiles.TotalDuration; THelper.Information ( "Thumbnails Range {0} -> {1}", _tnSettings.Start.ToString(@"h\:mm\:ss\.fff"), _tnSettings.End.ToString (@"h\:mm\:ss\.fff")); THelper.Information ("Thumbnail Duration {0} (Total {1})", (_tnSettings.End - _tnSettings.Start).ToString(@"h\:mm\:ss\.fff"), avFiles.TotalDuration.ToString (@"h\:mm\:ss\.fff")); avFile = avFiles[0]; System.Drawing.Size videoSize = AVFileSet.GetVideoSize(avFile); if (outputDirectory != null) THelper.Information ("OutputDirectory is \"{0}\"", outputDirectory); string baseDirectory = outputDirectory; if (outputDirectory == null) { outputDirectory = ThumbnailCreator.GetDirectoryName (avFile.FileName); baseDirectory = outputDirectory; if (_tnSettings.SubDirectory.Length > 0) { outputDirectory = System.IO.Path.Combine (outputDirectory, _tnSettings.SubDirectory); if (!System.IO.Directory.Exists (outputDirectory)) System.IO.Directory.CreateDirectory (outputDirectory); } } if (displayFilename == null) displayFilename = avFiles.GetDisplayName (baseDirectory); ThumbnailCreator creator; DateTime overviewCreated; int nThumbs; int originalBorder = _tnSettings.Border; _tnSettings.SrcRect = new System.Drawing.Rectangle (0, 0, videoSize.Width, videoSize.Height); double videoAspect = (double) videoSize.Width / videoSize.Height; _tnSettings.ThumbAspectRatio = videoAspect; THelper.Debug ("Video Frame Size {0}x{1} ({2:F2})", videoSize.Width, videoSize.Height, videoAspect); bool manualSrcRect = false; if (_srcRect.Width != 0 && _srcRect.Height != 0) { _tnSettings.SetSrcRect (_srcRect); manualSrcRect = true; THelper.Information ("Changing video rectangle from 0,0+{0}x{1} to {2},{3}+{4}x{5}", videoSize.Width, videoSize.Height, _srcRect.X, _srcRect.Y, _srcRect.Width, _srcRect.Height); } else if (_cropAspect != 0.0) { _tnSettings.AdjustThumbAspectRatio (_cropAspect, videoAspect, videoSize); manualSrcRect = true; THelper.Information ("Cropping aspect ratio from {0:F3} to {1:F3}", videoAspect, _cropAspect); } if (_stretchAspect != 0.0) { _tnSettings.ThumbAspectRatio = _stretchAspect; manualSrcRect = true; THelper.Information ("Stretching aspect ratio from {0:F3} to {1:F3}", videoAspect, _stretchAspect); } if (!manualSrcRect && _autoAspectRatio) { double displayAspect = AVFileSet.GetAspectRatio(avFile); if (Math.Abs(videoAspect - displayAspect) > 0.05) { //if (displayAspect > videoAspect) // displayAspect -= 0.01; //else // displayAspect += 0.01; _tnSettings.AdjustThumbAspectRatio (displayAspect, videoAspect, videoSize); THelper.Information ("Auto adjusting aspect ratio from {0:F3} to {1:F3}", videoAspect, displayAspect); } } string outTemplate; if (_createOverview) { //_tnSettings.Border = 1; creator = new ThumbnailCreator (_tnSettings, null); outTemplate = System.IO.Path.GetFileNameWithoutExtension (displayFilename) + "_overview.jpg"; nThumbs = creator.GenerateOverviewThumbs (avFiles, displayFilename, outTemplate, outputDirectory); overviewCreated = DateTime.Now; THelper.Information ("{0} to create Overview thumbnails.", (overviewCreated - avFileSetCreated).ToString (@"h\:mm\:ss")); THelper.Information ("{0} thumbnails created. {1:F2} seconds / thumbnail.", nThumbs, (overviewCreated - avFileSetCreated).TotalSeconds / nThumbs); } else { overviewCreated = DateTime.Now; THelper.Information ("Overview page skipped."); } _tnSettings.Border = originalBorder; if (_tnSettings.Interval.TotalSeconds > 0) { nThumbs = 0; creator = new ThumbnailCreator (_tnSettings, null); TimeSpan originalInterval = _tnSettings.Interval; if (_autoInterval) { IEnumerator<KeyValuePair<int,int>> ranges = _autoIntervals.GetEnumerator (); ranges.MoveNext (); KeyValuePair<int,int> range = ranges.Current; int interval = range.Value; int maxInterval = interval; double totalMinutes = (_tnSettings.End - _tnSettings.Start).TotalMinutes; while (ranges.MoveNext ()) { range = ranges.Current; if (totalMinutes < range.Key) { THelper.Information ("Duration {0:F2} < {1} minutes. AutoInterval is {2} seconds.", totalMinutes, range.Key, range.Value); interval = range.Value; break; } } _tnSettings.Interval = new TimeSpan (0, 0, interval); if (interval == maxInterval) THelper.Information ("Duration {0:F2} > {1} minutes. AutoInterval is {2} seconds", totalMinutes, range.Key, interval); } outTemplate = System.IO.Path.GetFileNameWithoutExtension (displayFilename); outTemplate = outTemplate.Replace ("{", "("); outTemplate = outTemplate.Replace ("}", ")"); outTemplate = outTemplate + "_page{0:D4}.jpg"; nThumbs = creator.GenerateDetailThumbs (avFiles, displayFilename, outTemplate, outputDirectory); _tnSettings.Interval = originalInterval; DateTime detailsCreated = DateTime.Now; if (nThumbs > 0) { THelper.Information ("{0} to generate Detail page thumbnails.", (detailsCreated - overviewCreated).ToString (@"h\:mm\:ss")); THelper.Information ("{0} thumbnails created. {1:F2} seconds / thumbnail.", nThumbs, (detailsCreated - overviewCreated).TotalSeconds / nThumbs); } } else { THelper.Information ("Detail page thumbnails skipped."); } DateTime overall = DateTime.Now; THelper.Information ("{0} overall time to process {1}.", (overall - startTime).ToString (@"h\:mm\:ss"), displayFilename); THelper.Information (); }