Guest User

Untitled

a guest
May 26th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. class Program
  2. {
  3.  
  4.  
  5.  
  6. [StructLayout(LayoutKind.Sequential)]
  7. struct RECT
  8. {
  9. public int left;
  10. public int top;
  11. public int right;
  12. public int bottom;
  13. }
  14.  
  15. [StructLayout(LayoutKind.Sequential)]
  16. struct VideoHeaderInfo
  17. {
  18. public RECT rcSource;
  19. public RECT rcTarget;
  20. public UInt32 dwbitrate;
  21. public UInt32 dwbiterrorrate;
  22. public long AvgTimePerFrame;
  23. public BITMAPINFOHEADER bmiHeader;
  24. }
  25.  
  26.  
  27. [StructLayout(LayoutKind.Sequential, Pack = 1)]
  28. public struct BITMAPINFOHEADER
  29. {
  30. public UInt32 biSize;
  31. public Int32 biWidth;
  32. public Int32 biHeight;
  33. public Int16 biPlanes;
  34. public Int16 biBitCount;
  35. public UInt32 biCompression;
  36. public UInt32 biSizeImage;
  37. public Int32 biXPelsPerMeter;
  38. public Int32 biYPelsPerMeter;
  39. public UInt32 biClrUsed;
  40. public UInt32 biClrImportant;
  41. }
  42.  
  43.  
  44. static void SaveMovieThumbnail(string filename, string thumbnail_filename)
  45. {
  46. IMediaDet mediaInt = new MediaDetClass();
  47. mediaInt.Filename = filename;
  48.  
  49. bool videoStreamFound = false;
  50. _AMMediaType oMediaType = mediaInt.StreamMediaType;
  51.  
  52. System.Guid videoHeader = new
  53. System.Guid("05589f80-c356-11ce-bf01-00aa0055595a");
  54.  
  55. int streamCount = mediaInt.OutputStreams;
  56. for (int counter = 0; counter < mediaInt.OutputStreams; counter++)
  57. {
  58. mediaInt.CurrentStream = counter;
  59. oMediaType = mediaInt.StreamMediaType;
  60. if (oMediaType.formattype == videoHeader)
  61. {
  62. videoStreamFound = true;
  63. break;
  64. }
  65. }
  66.  
  67. unsafe
  68. {
  69.  
  70. if (videoStreamFound)
  71. {
  72. VideoHeaderInfo* header =
  73. (VideoHeaderInfo*)(oMediaType.pbFormat.ToPointer());
  74.  
  75. double length = mediaInt.StreamLength;
  76.  
  77.  
  78. for (int i = 1; i < 30; i++)
  79. {
  80. string bitmap_path = "temp" + i.ToString() + ".bmp";
  81. mediaInt.WriteBitmapBits(
  82. length * (i / 30.0),
  83. header->bmiHeader.biWidth,
  84. header->bmiHeader.biHeight,
  85. bitmap_path);
  86.  
  87. using (FileStream fs = new FileStream(bitmap_path, FileMode.Open))
  88. {
  89. BitmapDecoder decoder = BitmapDecoder.Create(fs, BitmapCreateOptions.None, BitmapCacheOption.None);
  90. JpegBitmapEncoder encoder = new JpegBitmapEncoder();
  91. encoder.Frames.Add(decoder.Frames[0]);
  92. using (FileStream jpeg_fs = new FileStream("temp" + i.ToString() + ".jpg", FileMode.Create))
  93. {
  94. encoder.Save(jpeg_fs);
  95. }
  96. }
  97. File.Delete(bitmap_path);
  98.  
  99. }
  100.  
  101.  
  102. Marshal.FreeCoTaskMem((System.IntPtr)header);
  103. }
  104. }
  105. Marshal.FinalReleaseComObject(mediaInt);
  106. }
  107.  
  108. static void SaveMovieThumbnail2(string filename, string thumbnail_filename)
  109. {
  110.  
  111. }
  112.  
  113. static void Main(string[] args)
  114. {
  115.  
  116. string movie_path = @"Y:\Videos\Movies\Postal.LIMITED.DVDRip.XViD-PUKKA\p-p.avi";
  117. string out_path = "temp.jpg";
  118.  
  119. SaveMovieThumbnail(movie_path, out_path);
  120.  
  121.  
  122.  
  123. }
Add Comment
Please, Sign In to add comment