コード例 #1
0
        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);
        }
コード例 #2
0
        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;
        }
コード例 #3
0
    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);
    }