Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- [StructLayout(LayoutKind.Sequential)]
- struct RECT
- {
- public int left;
- public int top;
- public int right;
- public int bottom;
- }
- [StructLayout(LayoutKind.Sequential)]
- struct VideoHeaderInfo
- {
- public RECT rcSource;
- public RECT rcTarget;
- public UInt32 dwbitrate;
- public UInt32 dwbiterrorrate;
- public long AvgTimePerFrame;
- public BITMAPINFOHEADER bmiHeader;
- }
- [StructLayout(LayoutKind.Sequential, Pack = 1)]
- public struct BITMAPINFOHEADER
- {
- public UInt32 biSize;
- public Int32 biWidth;
- public Int32 biHeight;
- public Int16 biPlanes;
- public Int16 biBitCount;
- public UInt32 biCompression;
- public UInt32 biSizeImage;
- public Int32 biXPelsPerMeter;
- public Int32 biYPelsPerMeter;
- public UInt32 biClrUsed;
- public UInt32 biClrImportant;
- }
- static void SaveMovieThumbnail(string filename, string thumbnail_filename)
- {
- IMediaDet mediaInt = new MediaDetClass();
- mediaInt.Filename = filename;
- bool videoStreamFound = false;
- _AMMediaType oMediaType = mediaInt.StreamMediaType;
- System.Guid videoHeader = new
- System.Guid("05589f80-c356-11ce-bf01-00aa0055595a");
- int streamCount = mediaInt.OutputStreams;
- for (int counter = 0; counter < mediaInt.OutputStreams; counter++)
- {
- mediaInt.CurrentStream = counter;
- oMediaType = mediaInt.StreamMediaType;
- if (oMediaType.formattype == videoHeader)
- {
- videoStreamFound = true;
- break;
- }
- }
- unsafe
- {
- if (videoStreamFound)
- {
- VideoHeaderInfo* header =
- (VideoHeaderInfo*)(oMediaType.pbFormat.ToPointer());
- double length = mediaInt.StreamLength;
- for (int i = 1; i < 30; i++)
- {
- string bitmap_path = "temp" + i.ToString() + ".bmp";
- mediaInt.WriteBitmapBits(
- length * (i / 30.0),
- header->bmiHeader.biWidth,
- header->bmiHeader.biHeight,
- bitmap_path);
- using (FileStream fs = new FileStream(bitmap_path, FileMode.Open))
- {
- BitmapDecoder decoder = BitmapDecoder.Create(fs, BitmapCreateOptions.None, BitmapCacheOption.None);
- JpegBitmapEncoder encoder = new JpegBitmapEncoder();
- encoder.Frames.Add(decoder.Frames[0]);
- using (FileStream jpeg_fs = new FileStream("temp" + i.ToString() + ".jpg", FileMode.Create))
- {
- encoder.Save(jpeg_fs);
- }
- }
- File.Delete(bitmap_path);
- }
- Marshal.FreeCoTaskMem((System.IntPtr)header);
- }
- }
- Marshal.FinalReleaseComObject(mediaInt);
- }
- static void SaveMovieThumbnail2(string filename, string thumbnail_filename)
- {
- }
- static void Main(string[] args)
- {
- string movie_path = @"Y:\Videos\Movies\Postal.LIMITED.DVDRip.XViD-PUKKA\p-p.avi";
- string out_path = "temp.jpg";
- SaveMovieThumbnail(movie_path, out_path);
- }
Add Comment
Please, Sign In to add comment