Exemple #1
0
        /// <summary>
        /// Class describing a video file, manipulated using VLC libraries
        /// </summary>
        /// <param name="fileName"></param>
        public Video(string fileName)
        {
            FileInfo file        = new FileInfo(fileName);
            bool     initialized = false;

            if (!VideoTools.checkVlcLib())
            {
                throw new Exception("Cannot find the VLC library... Please make sure you're running this application from inside your PinUp folder...");
            }
            try
            {
                VlcMediaPlayer mediaPlayer = new VlcMediaPlayer(VideoTools.GetLibVlcLocation(), VideoTools.GetVlcOptionsHeadless(0));
                initialized = true;
                mediaPlayer.SetMedia(file);
                mediaPlayer.GetMedia().Parse();
                this.Duration = mediaPlayer.GetMedia().Duration.TotalSeconds;
                this.Width    = (int)mediaPlayer.GetMedia().TracksInformations[0].Video.Width;
                this.Height   = (int)mediaPlayer.GetMedia().TracksInformations[0].Video.Height;
                this.FileName = fileName;
                mediaPlayer.Dispose();
            }
            catch (Exception exc)
            {
                if (!initialized)
                {
                    throw (new Exception("Cannot initialize VLC player library: " + exc.Message));
                }
                else
                {
                    throw (new Exception("VLC library error: " + exc.Message));
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Extract a still frame from a video
        /// </summary>
        /// <param name="startAt"></param>
        /// <returns></returns>
        public Bitmap GetFrame(double startAt)
        {
            FileInfo file  = new FileInfo(this.FileName);
            FileInfo file2 = new FileInfo(Path.GetTempPath() + "\\snapshot.png");

            if (File.Exists(file2.FullName))
            {
                File.Delete(file2.FullName);
            }
            VlcMediaPlayer mediaPlayer = new VlcMediaPlayer(VideoTools.GetLibVlcLocation(), VideoTools.GetVlcOptionsHeadless(startAt));

            try
            {
                bool done         = false;
                bool takesnapshot = true;
                mediaPlayer.PositionChanged += (sender, e) =>
                {
                    if (takesnapshot)
                    {
                        takesnapshot = false; // avoid re-entry
                        mediaPlayer.TakeSnapshot(file2);
                        done = true;
                    }
                };
                mediaPlayer.SetMedia(file);
                mediaPlayer.Play();
                DateTime start = DateTime.UtcNow;
                while (!done) // wait for video to start, timeout 3 seconds
                {
                    if ((DateTime.UtcNow - start).TotalMilliseconds >= 3000)
                    {
                        throw (new Exception("Error when starting video!"));
                    }
                }
                mediaPlayer.Dispose();
            }
            catch (Exception exc)
            {
                mediaPlayer.Dispose();
                throw (new Exception("VLC library error:" + exc.Message));
            }

            if (File.Exists(file2.FullName))
            {
                Bitmap pic = new Bitmap(file2.FullName);
                return(pic);
            }
            else
            {
                throw (new Exception("Error while extracting snapshot from video!"));
            }
        }
        private void loadPicToWindow(string picturePath)
        {
            Bitmap bgPic = null;

            MatDWindow.PictureSource source = MatDWindow.PictureSource.none;
            string defaultPicFileName       = "";
            string defaultResName           = "";
            string extension = Path.GetExtension(picturePath).ToUpper();

            if (extension == ".MP4")
            {
                Video vid = new Video(picturePath);
                bgPic              = vid.GetFrame(vid.Duration / 2);
                source             = MatDWindow.PictureSource.video;
                defaultPicFileName = Path.GetFileNameWithoutExtension(picturePath) + "-snapshot.png";
            }
            else if (extension == ".DB2S" || extension == ".DIRECTB2S")
            {
                B2s b2s = new B2s(picturePath);
                if (b2s.IsValid)
                {
                    B2sForm frm = new B2sForm("You picked a DB2S file... Which image would you like to import?",
                                              "Backglass only", true,
                                              "Backglass with speaker grill", b2s.HasGrill(),
                                              "Speaker grill only", b2s.HasGrill());
                    frm.TopMost = true;
                    DialogResult dlg = frm.ShowDialog(this);
                    if (dlg == DialogResult.OK)
                    {
                        bgPic = (Bitmap)b2s.BackGlassImage(false);
                        defaultPicFileName = Path.GetFileNameWithoutExtension(picturePath) + "-backglass.png";
                    }
                    else if (dlg == DialogResult.Retry)
                    {
                        bgPic = (Bitmap)b2s.BackGlassImage(true);
                        defaultPicFileName = Path.GetFileNameWithoutExtension(picturePath) + "-backglass_with_grill.png";
                    }
                    else if (dlg == DialogResult.Ignore)
                    {
                        bgPic = (Bitmap)b2s.GrillImage();
                        defaultPicFileName = Path.GetFileNameWithoutExtension(picturePath) + "-grill.png";
                    }
                    defaultResName = Path.GetFileNameWithoutExtension(picturePath) + ".res";
                    source         = MatDWindow.PictureSource.db2s;
                }
            }
            else
            {
                bgPic              = new Bitmap(picturePath);
                source             = MatDWindow.PictureSource.picture;
                defaultPicFileName = Path.GetFileNameWithoutExtension(picturePath) + ".png";
            }

            if (bgPic != null)
            {
                string extraInfoCaption = "(" + source + " " + bgPic.Width.ToString() + "x" + bgPic.Height.ToString() + ")";
                selectedPupScreen.Window.LoadPicture(VideoTools.CopyAndReleaseImage(bgPic), source, extraInfoCaption, defaultPicFileName, defaultResName);
            }
            else
            {
                throw new Exception("Unrecognized format");
            }
        }