/// <summary> /// Generates the overview thumbnail page. /// </summary> /// <param name="avFiles">The <see cref="AVFileSet"/> to generate /// thumbnails for.</param> /// <param name="displayFilename">The display name of the <see cref="AVFileSet"/>.</param> /// <param name="outTemplate">The template (string format) to use when generating /// output filenames.</param> /// <param name="outputDirectory">The fullpath of the output directory.</param> /// <returns>The number of thumbnails created.</returns> public int GenerateOverviewThumbs(AVFileSet avFiles, string displayFilename, string outTemplate, string outputDirectory) { ThumbnailGrid tgrid = CreateThumbnailGrid (TNSettings.LayoutMode, TNSettings.OverviewThumbs, TNSettings.OverviewColumns, TNSettings.OverviewRows, TNSettings.OverviewThreshold); System.Collections.Generic.IEnumerator<MSEEncoder.AudioVideoFile> avFilesEnumerator = avFiles.GetEnumerator(); avFilesEnumerator.MoveNext(); MSEEncoder.AudioVideoFile avFile = avFilesEnumerator.Current; int avFileNum = 1; bool highlight = avFiles.Count > 1 ? true : false; System.Drawing.Size videoSize = AVFileSet.GetVideoSize (avFile); #if true string stats; if (videoSize.Width != TNSettings.SrcRect.Width || videoSize.Height != TNSettings.SrcRect.Height || Math.Abs ((double) videoSize.Width / videoSize.Height - TNSettings.ThumbAspectRatio) > 0.01) { stats = String.Format ("{0}x{1} ({2:F2}:1) [{3}x{4} ({5:F2}:1)] {6} {7}", TNSettings.SrcRect.Width, TNSettings.SrcRect.Height, TNSettings.ThumbAspectRatio, videoSize.Width, videoSize.Height, (double) videoSize.Width / videoSize.Height, //getAudioStreamStats(mediaItem), GetFileSizeString (avFiles.TotalFileSize), System.IO.File.GetLastWriteTime (avFile.FileName).ToString ("g") ); } else { stats = String.Format ("{0}x{1} ({2:F2}:1) {3} {4}", videoSize.Width, videoSize.Height, TNSettings.ThumbAspectRatio, //getAudioStreamStats(mediaItem), GetFileSizeString (avFiles.TotalFileSize), System.IO.File.GetLastWriteTime (avFile.FileName).ToString ("g") ); } #else string stats = String.Format ("{0}x{1} ({2:F2}:1) [{3}x{4} {5}x{6}] {7} {8}", videoSize.Width, videoSize.Height, (double) videoSize.Width / videoSize.Height, //getAudioStreamStats(mediaItem), tgrid.ThumbWidth, tgrid.ThumbHeight, tgrid.NColumns, tgrid.NRows, GetFileSizeString (mediaItem.MainMediaFile.FileSize), System.IO.File.GetLastWriteTime (displayFilename).ToString ("g") ); #endif THelper.Information ("Generating {0} {1}x{2} thumbnails on a {3}x{4} Overview page.", tgrid.NThumbs, tgrid.ThumbWidth, tgrid.ThumbHeight, tgrid.NColumns, tgrid.NRows); ThumbnailWriter writer = new ThumbnailWriter (this, tgrid, outputDirectory, displayFilename, outTemplate, avFiles.Count > 1 ? avFiles.Count : 0, stats, avFiles.TotalDuration); double intervalSeconds = ((TNSettings.End.TotalSeconds - TNSettings.Start.TotalSeconds) / (tgrid.NColumns * tgrid.NRows - 1)); int milliseconds = (int) ((intervalSeconds - Math.Truncate (intervalSeconds)) * 1000 + 0.5); TimeSpan interval = new TimeSpan (0, 0, 0, (int) intervalSeconds, milliseconds); int nThumbsAdded = 0; TimeSpan currentTime = TNSettings.Start; TimeSpan fileStartTime = new TimeSpan(0,0,0); MSEEncoder.ThumbnailGenerator thumbGenerator = avFile.CreateThumbnailGenerator (videoSize); while (currentTime <= TNSettings.End) { while (currentTime > fileStartTime + AVFileSet.GetVideoDuration(avFile)) { if (thumbGenerator != null) { thumbGenerator.Dispose(); thumbGenerator = null; } if (!avFilesEnumerator.MoveNext ()) { avFile = null; break; } fileStartTime += AVFileSet.GetVideoDuration(avFile); avFile = avFilesEnumerator.Current; avFileNum++; highlight = true; thumbGenerator = avFile.CreateThumbnailGenerator (videoSize); } if (thumbGenerator == null) break; if (BGWorker != null) { if (BGWorker.CancellationPending) { if (thumbGenerator != null) { thumbGenerator.Dispose (); thumbGenerator = null; } writer.Close (); return nThumbsAdded; } } using (System.Drawing.Bitmap resized = GenerateThumbnail (thumbGenerator, currentTime - fileStartTime, tgrid.ThumbWidth, tgrid.ThumbHeight, TNSettings.SrcRect)) { if (avFiles.Count > 1) writer.Add (resized, currentTime, highlight, avFileNum); else writer.Add (resized, currentTime, highlight, 0); highlight = false; nThumbsAdded++; } currentTime += interval; } // Last thumb should always be end time. if (nThumbsAdded < tgrid.NThumbs && thumbGenerator != null) { using (System.Drawing.Bitmap resized = GenerateThumbnail (thumbGenerator, TNSettings.End - fileStartTime, tgrid.ThumbWidth, tgrid.ThumbHeight, TNSettings.SrcRect)) { if (avFiles.Count > 1) writer.Add (resized, TNSettings.End, highlight, avFileNum); else writer.Add (resized, TNSettings.End, highlight, 0); nThumbsAdded++; } } if (thumbGenerator != null) { thumbGenerator.Dispose (); thumbGenerator = null; } writer.Close (); return tgrid.NThumbs; }
/// <summary> /// Generates the Detail thumbnail pages. /// </summary> /// <param name="avFiles">The <see cref="AVFileSet"/> to generate /// thumbnails for.</param> /// <param name="displayFilename">The display name of the <see cref="AVFileSet"/>.</param> /// <param name="outTemplate">The template (string format) to use when generating /// output filenames.</param> /// <param name="outputDirectory">The fullpath of the output directory.</param> /// <returns> /// The number of thumbnails created. /// </returns> public int GenerateDetailThumbs(AVFileSet avFiles, string displayFilename, string outTemplate, string outputDirectory) { ThumbnailGrid tgrid = CreateThumbnailGrid (TNSettings.LayoutMode, TNSettings.DetailThumbs, TNSettings.DetailColumns, TNSettings.DetailRows, TNSettings.DetailThreshold); //ThumbnailGrid tgrid = ThumbnailGrid.CreateUsingNRows (layout, _maxDetailRows, _detailColumns, // aspectRatio, _mThreshold); //layout.adjustWidth (tgrid.NColumns, tgrid.ThumbWidth); System.Collections.Generic.IEnumerator<MSEEncoder.AudioVideoFile> avFilesEnumerator = avFiles.GetEnumerator(); avFilesEnumerator.MoveNext(); MSEEncoder.AudioVideoFile avFile = avFilesEnumerator.Current; int avFileNum = 1; bool highlight = avFiles.Count > 1 ? true : false; System.Drawing.Size videoSize = AVFileSet.GetVideoSize(avFile); int nThumbsPerPage = tgrid.NColumns * tgrid.NRows; int nThumbs = (int) ((TNSettings.End - TNSettings.Start).TotalSeconds / TNSettings.Interval.TotalSeconds) + 1; // start adjustment to make thumbnails occur at _interval seconds int nExtraStartSeconds = (int) (TNSettings.Start.TotalSeconds % TNSettings.Interval.TotalSeconds); int nStartIntervals = (int) (TNSettings.Start.TotalSeconds / TNSettings.Interval.TotalSeconds); if (nExtraStartSeconds != 0) { nThumbs++; nStartIntervals++; } int nExtraEndSeconds = (int) (TNSettings.End.TotalSeconds % TNSettings.Interval.TotalSeconds); int nEndIntervals = (int) (TNSettings.End.TotalSeconds / TNSettings.Interval.TotalSeconds); TimeSpan adjustedEnd = TNSettings.End; if (nExtraEndSeconds != 0) { nThumbs++; adjustedEnd = TNSettings.End; //adjustedEnd = new TimeSpan (0, 0, nEndIntervals * // (int) tnSettings.Interval.TotalSeconds); } int nPages = (int) ((float) nThumbs / nThumbsPerPage + 0.5); if (nPages * nThumbsPerPage < nThumbs) nPages++; string stats; if (videoSize.Width != TNSettings.SrcRect.Width || videoSize.Height != TNSettings.SrcRect.Height || Math.Abs ((double) videoSize.Width / videoSize.Height - TNSettings.ThumbAspectRatio) > 0.01) { stats = String.Format ("{0}x{1} ({2:F2}:1) [{3}x{4} ({5:F2}:1)] {6} {7}", TNSettings.SrcRect.Width, TNSettings.SrcRect.Height, TNSettings.ThumbAspectRatio, videoSize.Width, videoSize.Height, (double) videoSize.Width / videoSize.Height, //getAudioStreamStats(mediaItem), GetFileSizeString (avFiles.TotalFileSize), System.IO.File.GetLastWriteTime (avFile.FileName).ToString ("g") ); } else { stats = String.Format ("{0}x{1} ({2:F2}:1) {3} {4}", videoSize.Width, videoSize.Height, TNSettings.ThumbAspectRatio, //getAudioStreamStats(mediaItem), GetFileSizeString (avFiles.TotalFileSize), System.IO.File.GetLastWriteTime (avFile.FileName).ToString ("g") ); } THelper.Information ( "Generating {0} {1}x{2} thumbnails every {3} seconds on {4} {5}x{6} Detail pages.", nThumbs, tgrid.ThumbWidth, tgrid.ThumbHeight, TNSettings.Interval.TotalSeconds, nPages, tgrid.NColumns, tgrid.NRows); ThumbnailMultiWriter mwriter = new ThumbnailMultiWriter (this, tgrid, outputDirectory, displayFilename, outTemplate, avFiles.Count > 1 ? avFiles.Count : 0, TNSettings.Interval, stats, avFiles.TotalDuration, nPages); TimeSpan currentTime = TNSettings.Start; int thumbCount = 0; TimeSpan fileStartTime = new TimeSpan(0,0,0); MSEEncoder.ThumbnailGenerator thumbGenerator = avFile.CreateThumbnailGenerator (videoSize); while (currentTime > fileStartTime + AVFileSet.GetVideoDuration(avFile)) { if (thumbGenerator != null) { thumbGenerator.Dispose(); thumbGenerator = null; } if (!avFilesEnumerator.MoveNext ()) { avFile = null; break; } fileStartTime += AVFileSet.GetVideoDuration(avFile); avFile = avFilesEnumerator.Current; avFileNum++; highlight = true; thumbGenerator = avFile.CreateThumbnailGenerator (videoSize); } if (nExtraStartSeconds != 0 && thumbGenerator != null) { using (System.Drawing.Bitmap resized = GenerateThumbnail (thumbGenerator, currentTime - fileStartTime, tgrid.ThumbWidth, tgrid.ThumbHeight, TNSettings.SrcRect)) { if (avFiles.Count > 1) mwriter.Add (resized, currentTime, highlight, avFileNum, fileStartTime); else mwriter.Add (resized, currentTime, highlight, 0, TimeSpan.Zero); thumbCount++; highlight = false; } currentTime = new TimeSpan (0, 0, 0, 0, (int) (nStartIntervals * TNSettings.Interval.TotalMilliseconds)); } while (currentTime <= adjustedEnd && thumbGenerator != null) { while (currentTime > fileStartTime + AVFileSet.GetVideoDuration(avFile)) { if (thumbGenerator != null) { thumbGenerator.Dispose(); thumbGenerator = null; } if (!avFilesEnumerator.MoveNext ()) { avFile = null; break; } fileStartTime += AVFileSet.GetVideoDuration(avFile); avFile = avFilesEnumerator.Current; avFileNum++; highlight = true; thumbGenerator = avFile.CreateThumbnailGenerator (videoSize); } if (thumbGenerator == null) break; if (BGWorker != null) { if (BGWorker.CancellationPending) { if (thumbGenerator != null) { thumbGenerator.Dispose (); thumbGenerator = null; } mwriter.Close (); return thumbCount; } } using (System.Drawing.Bitmap resized = GenerateThumbnail (thumbGenerator, currentTime - fileStartTime, tgrid.ThumbWidth, tgrid.ThumbHeight, TNSettings.SrcRect)) { if (avFiles.Count > 1) mwriter.Add (resized, currentTime, highlight, avFileNum, fileStartTime); else mwriter.Add (resized, currentTime, highlight, 0, TimeSpan.Zero); thumbCount++; highlight = false; } currentTime += TNSettings.Interval; } if (nExtraEndSeconds != 0 && thumbCount < nThumbs && thumbGenerator != null) { using (System.Drawing.Bitmap resized = GenerateThumbnail (thumbGenerator, TNSettings.End - fileStartTime, tgrid.ThumbWidth, tgrid.ThumbHeight, TNSettings.SrcRect)) { if (avFiles.Count > 1) mwriter.Add (resized, TNSettings.End, highlight, avFileNum, fileStartTime); else mwriter.Add (resized, TNSettings.End, highlight, 0, TimeSpan.Zero); thumbCount++; highlight = false; } } if (thumbGenerator != null) { thumbGenerator.Dispose (); thumbGenerator = null; } mwriter.Close (); return thumbCount; }