private double GetFrameRate(string filename) { IMediaDet md = new MediaDet() as IMediaDet; Guid streamType; AMMediaType mt = new AMMediaType(); int hr, nStreams; md.put_Filename(filename); md.get_OutputStreams(out nStreams); for (int i = 0; i < nStreams; i++) { hr = md.put_CurrentStream(i); DsError.ThrowExceptionForHR(hr); hr = md.get_StreamType(out streamType); DsError.ThrowExceptionForHR(hr); if (streamType == MediaType.Video) { md.put_CurrentStream(0); double frate = 30; md.get_FrameRate(out frate); return(frate); } } return(30); }
private List <int> GetAudioStreams(string filename) { IMediaDet md = new MediaDet() as IMediaDet; Guid streamType; AMMediaType mt = new AMMediaType(); int hr, nStreams; List <int> streamList = new List <int>(); md.put_Filename(filename); md.get_OutputStreams(out nStreams); for (int i = 0; i < nStreams; i++) { hr = md.put_CurrentStream(i); DsError.ThrowExceptionForHR(hr); hr = md.get_StreamType(out streamType); DsError.ThrowExceptionForHR(hr); if (streamType == MediaType.Audio) { streamList.Add(i); } } return(streamList); }
public static bool CreateThumb(string videoFilename, string thumbFilename, double positionPercent) { Logger.ReportInfo("Creating thumb for " + videoFilename); bool rval = false; IMediaDet m = new MediaDet() as IMediaDet; m.put_Filename(videoFilename); int streamCount; m.get_OutputStreams(out streamCount); AMMediaType media_type = new AMMediaType(); for (int i = 0; i < streamCount; i++) { m.get_StreamMediaType(media_type); VideoInfoHeader vih = (VideoInfoHeader)Marshal.PtrToStructure(media_type.formatPtr, typeof(VideoInfoHeader)); if (vih == null) { continue; } double pos; m.get_StreamLength(out pos); pos = (int)(pos * positionPercent); int width = vih.BmiHeader.Width; int height = vih.BmiHeader.Height; if (height < 10 || width < 10) { continue; } string tempfile = Path.GetTempFileName() + ".bmp"; m.WriteBitmapBits(pos, width, height, tempfile); if (File.Exists(tempfile)) { using (var bitmap = new Bitmap(tempfile)) { bitmap.Save(thumbFilename, ImageFormat.Png); } File.Delete(tempfile); rval = true; } break; } Marshal.ReleaseComObject(m); return(rval); }
public static bool CreateThumb(string videoFilename, string thumbFilename, double positionPercent) { Logger.ReportInfo("Creating thumb for " + videoFilename); bool rval = false; IMediaDet m = new MediaDet() as IMediaDet; m.put_Filename(videoFilename); int streamCount; m.get_OutputStreams(out streamCount); AMMediaType media_type = new AMMediaType(); for (int i = 0; i < streamCount; i++) { m.get_StreamMediaType(media_type); VideoInfoHeader vih = (VideoInfoHeader)Marshal.PtrToStructure(media_type.formatPtr, typeof(VideoInfoHeader)); if (vih == null) { continue; } double pos; m.get_StreamLength(out pos); pos = (int)(pos * positionPercent); int width = vih.BmiHeader.Width; int height = vih.BmiHeader.Height; if (height < 10 || width < 10) { continue; } string tempfile = Path.GetTempFileName() + ".bmp"; m.WriteBitmapBits(pos, width, height, tempfile); if (File.Exists(tempfile)) { using (var bitmap = new Bitmap(tempfile)) { bitmap.Save(thumbFilename, ImageFormat.Png); } File.Delete(tempfile); rval = true; } break; } Marshal.ReleaseComObject(m); return rval; }
private List<int> GetAudioStreams(string filename) { IMediaDet md = new MediaDet() as IMediaDet; Guid streamType; AMMediaType mt = new AMMediaType(); int hr, nStreams; List<int> streamList = new List<int>(); md.put_Filename(filename); md.get_OutputStreams(out nStreams); for (int i = 0; i < nStreams; i++) { hr = md.put_CurrentStream(i); DsError.ThrowExceptionForHR(hr); hr = md.get_StreamType(out streamType); DsError.ThrowExceptionForHR(hr); if (streamType == MediaType.Audio) streamList.Add(i); } return streamList; }
private double GetFrameRate(string filename) { IMediaDet md = new MediaDet() as IMediaDet; Guid streamType; AMMediaType mt = new AMMediaType(); int hr, nStreams; md.put_Filename(filename); md.get_OutputStreams(out nStreams); for (int i = 0; i < nStreams; i++) { hr = md.put_CurrentStream(i); DsError.ThrowExceptionForHR(hr); hr = md.get_StreamType(out streamType); DsError.ThrowExceptionForHR(hr); if (streamType == MediaType.Video) { md.put_CurrentStream(0); double frate = 30; md.get_FrameRate(out frate); return frate; } } return 30; }
public static bool CreateThumb(string videoFilename, string thumbFilename, double positionPercent) { bool rval = false; IMediaDet m = new MediaDet() as IMediaDet; m.put_Filename(videoFilename); int streamCount; m.get_OutputStreams(out streamCount); AMMediaType media_type = new AMMediaType(); for (int i = 0; i < streamCount; i++) { m.get_StreamMediaType(media_type); /* * TODO: Its proing really hard to find out what the stream is major type doesn't work sometimes * Cause I only seem to get audio streams for some videos, current approach is to assume we have * a video stream and then just stop if the width is 0 * if (media_type.majorType != videoType) * { * continue; * } */ VideoInfoHeader vih = (VideoInfoHeader)Marshal.PtrToStructure(media_type.formatPtr, typeof(VideoInfoHeader)); if (vih == null) { continue; } double pos; m.get_StreamLength(out pos); pos = (int)(pos * positionPercent); int width = vih.BmiHeader.Width; int height = vih.BmiHeader.Height; if (height < 10 || width < 10) { continue; } string tempfile = Path.GetTempFileName() + ".bmp"; m.WriteBitmapBits(pos, width, height, tempfile); if (File.Exists(tempfile)) { try { using (var bitmap = new Bitmap(tempfile)) { bitmap.Save(thumbFilename, ImageFormat.Png); } } catch { } File.Delete(tempfile); rval = true; } break; } Marshal.ReleaseComObject(m); return(rval); }