/// <summary> /// Generates the multi-page thumbnails OBSOLETE. /// </summary> /// <param name="mediaItem">The /// <see cref="Microsoft.Expression.Encoder.MediaItem"/> to generate /// thumbnails for.</param> /// <param name="filename">The display name of the file to generate thumbs for.</param> /// <param name="outputDirectory">The output directory.</param> /// <returns>The number of thumbnails created.</returns> public int GenerateMultiThumbs(MSEEncoder.MediaItem mediaItem, string filename, string outputDirectory) { double thumbAspectRatio = TNSettings.ThumbAspectRatio; ThumbnailPageLayout container = new ThumbnailPageLayout (TNSettings); ThumbnailGrid tgrid; if (thumbAspectRatio < 1.44) tgrid = ThumbnailGrid.CreateUsingNColumns (container, TNSettings, thumbAspectRatio, true, _debug); else tgrid = ThumbnailGrid.CreateUsingNRows (container, TNSettings, thumbAspectRatio, true, _debug); container.AdjustSize (tgrid); //ThumbnailGrid tgrid = ThumbnailGrid.CreateUsingNRows (container, _maxMultiRows, _multiColumns, // aspectRatio, _mThreshold); //container.adjustWidth (tgrid.NColumns, tgrid.ThumbWidth); if (outputDirectory == null) outputDirectory = GetDirectoryName (filename); string fixedFilename = System.IO.Path.GetFileNameWithoutExtension (filename); fixedFilename = fixedFilename.Replace ("{", "("); fixedFilename = fixedFilename.Replace ("}", ")"); string outTemplate = fixedFilename + "_page{0:D4}.jpg"; 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 (mediaItem.OriginalVideoSize.Width != TNSettings.SrcRect.Width || mediaItem.OriginalVideoSize.Height != TNSettings.SrcRect.Height || Math.Abs ((double) mediaItem.OriginalVideoSize.Width / mediaItem.OriginalVideoSize.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, mediaItem.OriginalVideoSize.Width, mediaItem.OriginalVideoSize.Height, (double) mediaItem.OriginalVideoSize.Width / mediaItem.OriginalVideoSize.Height, //getAudioStreamStats(mediaItem), GetFileSizeString (mediaItem.MainMediaFile.FileSize), System.IO.File.GetLastWriteTime (filename).ToString ("g") ); } else { stats = String.Format ("{0}x{1} ({2:F2}:1) {3} {4}", mediaItem.OriginalVideoSize.Width, mediaItem.OriginalVideoSize.Height, TNSettings.ThumbAspectRatio, //getAudioStreamStats(mediaItem), GetFileSizeString (mediaItem.MainMediaFile.FileSize), System.IO.File.GetLastWriteTime (filename).ToString ("g") ); } THelper.Information ("Duration {0} - Generating {1} thumbs every {2} seconds on {3} pages.", mediaItem.FileDuration.ToString (@"h\:mm\:ss"), nThumbs, TNSettings.Interval.TotalSeconds, nPages); ThumbnailMultiWriter mwriter = new ThumbnailMultiWriter (this, tgrid, outputDirectory, filename, outTemplate, TNSettings.Interval, stats, mediaItem.FileDuration, nPages, TNSettings.ScaleFactor, _debug); TimeSpan currentTime = TNSettings.Start; int thumbCount = 0; if (nExtraStartSeconds != 0) { using (System.Drawing.Bitmap resized = GenerateThumbnail (mediaItem, currentTime, tgrid.ThumbWidth, tgrid.ThumbHeight, TNSettings.SrcRect)) { mwriter.Add (resized, currentTime, 0, TimeSpan.Zero); thumbCount++; } currentTime = new TimeSpan (0, 0, 0, 0, (int) (nStartIntervals * TNSettings.Interval.TotalMilliseconds)); } while (currentTime <= adjustedEnd) { using (System.Drawing.Bitmap resized = GenerateThumbnail (mediaItem, currentTime, tgrid.ThumbWidth, tgrid.ThumbHeight, TNSettings.SrcRect)) { mwriter.Add (resized, currentTime, 0, TimeSpan.Zero); thumbCount++; } currentTime += TNSettings.Interval; } if (nExtraEndSeconds != 0 && thumbCount < nThumbs) { using (System.Drawing.Bitmap resized = GenerateThumbnail (mediaItem, TNSettings.End, tgrid.ThumbWidth, tgrid.ThumbHeight, TNSettings.SrcRect)) { mwriter.Add (resized, TNSettings.End, 0, TimeSpan.Zero); thumbCount++; } } mwriter.Close (); return thumbCount; }
/// <summary> /// Generates a thumbnail OBSOLETE /// </summary> /// <param name="mediaItem">The <see cref="Microsoft.Expression.Encoder.MediaItem"/> /// to use to generate the thumbnail.</param> /// <param name="time">The time of the thumbnail.</param> /// <param name="thumbWidth">Width of the thumbnail.</param> /// <param name="thumbHeight">Height of the thumbnail.</param> /// <param name="srcRect">The source rect to use when clipping the thumbnail.</param> /// <returns>A <see cref="System.Drawing.Bitmap"/>.</returns> /// <remarks> /// Generates the thumbnail at the orignal source size and then resizes it. /// </remarks> public static System.Drawing.Bitmap GenerateThumbnail(MSEEncoder.MediaItem mediaItem, TimeSpan time, int thumbWidth, int thumbHeight, System.Drawing.Rectangle srcRect) { System.Drawing.Bitmap resized = new System.Drawing.Bitmap (thumbWidth, thumbHeight); using (System.Drawing.Bitmap original = mediaItem.MainMediaFile.GetThumbnail (time, mediaItem.OriginalVideoSize)) { using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage (resized)) { // No alpha channel usage graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; //graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; //graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; // Affects image resizing graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; // Affects anti-aliasing of filled edges //graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; using (System.Drawing.Imaging.ImageAttributes att = new System.Drawing.Imaging.ImageAttributes ()) { att.SetWrapMode (System.Drawing.Drawing2D.WrapMode.TileFlipXY); graphics.DrawImage (original, new System.Drawing.Rectangle(0, 0, thumbWidth, thumbHeight), srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, System.Drawing.GraphicsUnit.Pixel, att); } } } return resized; }
/// <summary> /// Generates a thumbnail /// </summary> /// <param name="tgen">The /// <see cref="Microsoft.Expression.Encoder.ThumbnailGenerator"/> /// to use to generate the thumbnail.</param> /// <param name="time">The time of the thumbnail.</param> /// <param name="thumbWidth">Width of the thumbnail.</param> /// <param name="thumbHeight">Height of the thumbnail.</param> /// <param name="srcRect">The source rect to use when clipping the thumbnail.</param> /// <returns>A <see cref="System.Drawing.Bitmap"/>.</returns> /// <remarks> /// Generates the thumbnail at the orignal source size and then resizes it. /// </remarks> public static System.Drawing.Bitmap GenerateThumbnail(MSEEncoder.ThumbnailGenerator tgen, TimeSpan time, int thumbWidth, int thumbHeight, System.Drawing.Rectangle srcRect) { System.Drawing.Bitmap resized = new System.Drawing.Bitmap (thumbWidth, thumbHeight); System.Drawing.Bitmap original = null; int counter = 0; while (original == null) { try { original = tgen.CreateThumbnail (time); } catch (MSEEncoder.UnableToCreateThumbnailException) { THelper.Error ("Unable to create thumbnail at time {0}", time.ToString (@"h\:mm\:ss\.ffff")); time += new TimeSpan (0, 0, 0, 0, 50); THelper.Error (" Trying time {0}", time.ToString (@"h\:mm\:ss\.ffff")); counter++; if (counter > 20) throw; } } using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage (resized)) { // No alpha channel usage graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; //graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; //graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; // Affects image resizing graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; // Affects anti-aliasing of filled edges //graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; using (System.Drawing.Imaging.ImageAttributes att = new System.Drawing.Imaging.ImageAttributes ()) { att.SetWrapMode (System.Drawing.Drawing2D.WrapMode.TileFlipXY); graphics.DrawImage (original, new System.Drawing.Rectangle (0, 0, thumbWidth, thumbHeight), srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, System.Drawing.GraphicsUnit.Pixel, att); } } original.Dispose(); return resized; }
/// <summary> /// Generates the overview thumbnail page OBSOLETE. /// </summary> /// <param name="mediaItem">The /// <see cref="Microsoft.Expression.Encoder.MediaItem"/> to generate /// thumbnails for.</param> /// <param name="filename">The display name of the file to generate thumbs for.</param> /// <param name="outputDirectory">The output directory.</param> /// <returns>The number of thumbnails created.</returns> public int GenerateOverviewThumbs(MSEEncoder.MediaItem mediaItem, string filename, string outputDirectory) { double thumbAspectRatio = TNSettings.ThumbAspectRatio; ThumbnailPageLayout container = new ThumbnailPageLayout (TNSettings); ThumbnailGrid tgrid; if (thumbAspectRatio < 1.36) tgrid = ThumbnailGrid.CreateUsingNColumns (container, TNSettings, thumbAspectRatio, false, _debug); else tgrid = ThumbnailGrid.CreateUsingNRows (container, TNSettings, thumbAspectRatio, false, _debug); container.AdjustSize (tgrid); if (outputDirectory == null) outputDirectory = GetDirectoryName (filename); string outTemplate = System.IO.Path.GetFileNameWithoutExtension (filename) + "_overview.jpg"; #if true string stats; if (mediaItem.OriginalVideoSize.Width != TNSettings.SrcRect.Width || mediaItem.OriginalVideoSize.Height != TNSettings.SrcRect.Height || Math.Abs ((double) mediaItem.OriginalVideoSize.Width / mediaItem.OriginalVideoSize.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, mediaItem.OriginalVideoSize.Width, mediaItem.OriginalVideoSize.Height, (double) mediaItem.OriginalVideoSize.Width / mediaItem.OriginalVideoSize.Height, //getAudioStreamStats(mediaItem), GetFileSizeString (mediaItem.MainMediaFile.FileSize), System.IO.File.GetLastWriteTime (filename).ToString ("g") ); } else { stats = String.Format ("{0}x{1} ({2:F2}:1) {3} {4}", mediaItem.OriginalVideoSize.Width, mediaItem.OriginalVideoSize.Height, TNSettings.ThumbAspectRatio, //getAudioStreamStats(mediaItem), GetFileSizeString (mediaItem.MainMediaFile.FileSize), System.IO.File.GetLastWriteTime (filename).ToString ("g") ); } #else string stats = String.Format ("{0}x{1} ({2:F2}:1) [{3}x{4} {5}x{6}] {7} {8}", mediaItem.OriginalVideoSize.Width, mediaItem.OriginalVideoSize.Height, (double) mediaItem.OriginalVideoSize.Width / mediaItem.OriginalVideoSize.Height, //getAudioStreamStats(mediaItem), tgrid.ThumbWidth, tgrid.ThumbHeight, tgrid.NColumns, tgrid.NRows, GetFileSizeString (mediaItem.MainMediaFile.FileSize), System.IO.File.GetLastWriteTime (filename).ToString ("g") ); #endif THelper.Information ("Generating {0} overview page thumbs.", tgrid.NThumbs); ThumbnailWriter writer = new ThumbnailWriter (this, tgrid, outputDirectory, filename, outTemplate, stats, mediaItem.FileDuration, TNSettings.ScaleFactor, _debug); 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; while (currentTime <= TNSettings.End) { using (System.Drawing.Bitmap resized = GenerateThumbnail (mediaItem, currentTime, tgrid.ThumbWidth, tgrid.ThumbHeight, TNSettings.SrcRect)) { writer.Add (resized, currentTime); nThumbsAdded++; } currentTime += interval; } // Last thumb should always be end time. if (nThumbsAdded < tgrid.NThumbs) { using (System.Drawing.Bitmap resized = GenerateThumbnail (mediaItem, TNSettings.End, tgrid.ThumbWidth, tgrid.ThumbHeight, TNSettings.SrcRect)) { writer.Add (resized, TNSettings.End); nThumbsAdded++; } } writer.Close (); return tgrid.NThumbs; }