コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public static Bitmap GetBitmap(double position, string movieFileName, int width, int height)
        {
            //DexterLib.MediaLocatorClass
            MediaDet det = new MediaDet();

            det.Filename      = movieFileName;
            det.CurrentStream = 0;
            double len = det.StreamLength;

            if (position > len)
            {
                return(null);
            }


            string myTempFile = System.IO.Path.GetTempFileName();

            det.WriteBitmapBits(position, width, height, myTempFile);
            Bitmap myBMP;

            using (FileStream lStream = new FileStream(myTempFile, FileMode.Open, FileAccess.Read)) {
                myBMP = (Bitmap)Image.FromStream(lStream);
            }
            System.IO.File.Delete(myTempFile);
            return(myBMP);
        }
コード例 #4
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);
        }
コード例 #5
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;
        }
コード例 #6
0
ファイル: OSDVideo.cs プロジェクト: duyisu/MissionPlanner
        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;
        }
コード例 #7
0
ファイル: OSDVideo.cs プロジェクト: duyisu/MissionPlanner
        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;
        }
コード例 #8
0
        /// <summary>
        /// Open an image associated with the current metadata
        /// </summary>
        private void Browse_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
            ofd.Multiselect = false;

            ofd.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.JPEG)|*.BMP;*.JPG;*.GIF;*.JPEG|Audio and Video Files(*.MOV;*.AVI;*.MP4;*.WMV)|*MOV;*AVI;*.MP4;*.WMV|All files (*.*)|*.*"; //Only allow image and video type metadata

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string[] filePath = ofd.FileNames;
                string[] safeFilePath = ofd.SafeFileNames;
                for (int i = 0; i < safeFilePath.Length; i++)
                {
                    //if image
                    if (_helper.IsImageFile(filePath[i]))
                    {
                        type = "Image";
                        System.Windows.Controls.Image wpfImage = new System.Windows.Controls.Image();
                        try
                        {
                            FileStream stream = new FileStream(@filePath[i], FileMode.Open);

                            System.Drawing.Image dImage = System.Drawing.Image.FromStream(stream);

                            wpfImage = _helper.ConvertDrawingImageToWPFImage(dImage);

                            stream.Close();
                            image1.Source = wpfImage.Source;
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show("The image is broken or invalid!");
                            return;
                        }
                    }
                    //if video
                    else if (_helper.IsVideoFile(filePath[i]))
                    {
                        type = "Video";
                        BitmapImage videoThumb = new BitmapImage();

                        if (_helper.IsDirShowFile(filePath[i]))
                        {
                            //creating and saving thumbnail image
                            DexterLib.MediaDet md = new MediaDet();
                            md.Filename = @filePath[i];
                            md.CurrentStream = 0;
                            string fBitmapName = @filePath[i];
                            fBitmapName = fBitmapName.Remove(fBitmapName.Length - 4, 4);
                            fBitmapName += ".bmp";
                            md.WriteBitmapBits(md.StreamLength / 2, 400, 240, fBitmapName);

                            Image wpfImage = new Image();
                            FileStream stream = new FileStream(fBitmapName, FileMode.Open);
                            System.Drawing.Image dImage = System.Drawing.Image.FromStream(stream);
                            wpfImage = _helper.ConvertDrawingImageToWPFImage(dImage);
                            stream.Close();

                            Utils.setAspectRatio(imageCanvas, imageRec, image1, wpfImage, 4);
                            image1.Source = videoThumb;

                        }
                        else
                        {
                            String sImageText = Path.GetFileNameWithoutExtension(filePath[i]);
                            System.Drawing.Bitmap objBmpImage = new System.Drawing.Bitmap(1,1);

                            int intWidth = 0;
                            int intHeight = 0;

                            // Create the Font object for the image text drawing.
                            System.Drawing.Font objFont = new System.Drawing.Font("Arial", 20, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);

                            // Create a graphics object to measure the text's width and height.
                            System.Drawing.Graphics objGraphics = System.Drawing.Graphics.FromImage(objBmpImage);

                            // This is where the bitmap size is determined.
                            intWidth = (int)objGraphics.MeasureString(sImageText, objFont).Width;
                            intHeight = (int)objGraphics.MeasureString(sImageText, objFont).Height;
                            System.Drawing.Size newsize = new System.Drawing.Size(intWidth, intHeight);

                            // Create the bmpImage again with the correct size for the text and font.
                            objBmpImage = new System.Drawing.Bitmap(objBmpImage, newsize);

                            // Add the colors to the new bitmap.
                            objGraphics = System.Drawing.Graphics.FromImage(objBmpImage);

                            // Set Background color
                            objGraphics.Clear(System.Drawing.Color.White);
                            objGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;//SmoothingMode.AntiAlias;
                            objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;//TextRenderingHint.AntiAlias;
                            objGraphics.DrawString(sImageText, objFont, new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(102, 102, 102)), 0, 0);
                            objGraphics.Flush();

                            string fBitmapName = @filePath[i];
                            fBitmapName = fBitmapName.Remove(fBitmapName.Length - 4, 4);
                            fBitmapName += ".bmp";
                            objBmpImage.Save(fBitmapName);

                            FileStream stream = new FileStream(fBitmapName, FileMode.Open);
                            System.Windows.Controls.Image wpfImage = new System.Windows.Controls.Image();
                            System.Drawing.Image dImage = System.Drawing.Image.FromStream(stream);
                            wpfImage = _helper.ConvertDrawingImageToWPFImage(dImage);

                            stream.Close();
                            image1.Source = wpfImage.Source;
                        }

                        title_tag.Text = safeFilePath[i];
                        metaImagePath = filePath[i];
                    }

                    string filename = safeFilePath[i];
                    string extension = Path.GetExtension(safeFilePath[i]);
                    string tempFileName = Path.GetFileNameWithoutExtension(safeFilePath[i]);
                    Random random = new Random();
                    int randomNumber = random.Next(0, 100000000);
                    filename = tempFileName + randomNumber + extension;
                    while (File.Exists("Data/Images/Metadata/" + filename))
                    {
                        randomNumber = random.Next(0, 100000000);
                        filename = tempFileName + randomNumber + extension;
                    }
                    title_tag.Text = filename;

                    metaImagePath = filePath[i];
                }
            }
        }
コード例 #9
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);
    }