Exemple #1
0
        public IMediaFile Open(string file)
        {
            int        bestHandleLevel = -1;
            IMediaFile bestMediaFile   = null;

            foreach (IMediaFileFactory factory in mainForm.PackageSystem.MediaFileTypes.Values)
            {
                int handleLevel = factory.HandleLevel(file);
                if (handleLevel < 0)
                {
                    continue;
                }
                IMediaFile mFile = factory.Open(file);
                if (mFile != null && handleLevel > bestHandleLevel)
                {
                    bestHandleLevel = handleLevel;
                    bestMediaFile   = mFile;
                }
                else if (mFile != null)
                {
                    mFile.Dispose();
                }
            }
            return(bestMediaFile);
        }
Exemple #2
0
        public IMediaFile Open(string file)
        {
            int        bestHandleLevel = -1;
            IMediaFile bestMediaFile   = null;

            foreach (IMediaFileFactory factory in mainForm.PackageSystem.MediaFileTypes.Values)
            {
                int handleLevel = factory.HandleLevel(file);
                if (handleLevel < 0)
                {
                    continue;
                }
                try
                {
                    if (handleLevel > bestHandleLevel)
                    {
                        IMediaFile mFile = factory.Open(file);
                        if (mFile != null)
                        {
                            bestHandleLevel = handleLevel;
                            if (bestMediaFile != null)
                            {
                                bestMediaFile.Dispose();
                            }
                            bestMediaFile = mFile;
                        }
                    }
                }
                catch (Exception ex) { string test = ex.Message; }
            }
            return(bestMediaFile);
        }
Exemple #3
0
 public void Dispose()
 {
     if (videoSourceFile != null)
     {
         videoSourceFile.Dispose();
         videoSourceFile = null;
         videoReader     = null;
     }
 }
Exemple #4
0
        /// <summary>
        /// loads the video, sets up the proper window size and enables / disables the GUI buttons depending on the
        /// preview type set
        /// </summary>
        /// <param name="path">path of the video file to be loaded</param>
        /// <param name="type">type of window</param>
        /// <param name="inlineAvs">true if path contain not filename but avsynth script to be parsed</param>
        /// <param name="startFrame">Select a specific frame to start off with or -1 for middle of video</param>
        /// <returns>true if the video could be opened, false if not</returns>
        public bool loadVideo(MainForm mainForm, string path, PREVIEWTYPE type, bool hasAR, bool inlineAvs, int startFrame, bool originalSize)
        {
            videoPreview.UnloadVideo();
            bInlineAVS    = inlineAvs;
            strFileName   = path;
            bOriginalSize = originalSize;

            lock (this)
            {
                if (file != null)
                {
                    file.Dispose();
                }
            }

            try
            {
                if (inlineAvs)
                {
                    file = AvsFile.ParseScript(path, true);
                    btnReloadVideo.Enabled = false;
                }
                else
                {
                    file = mainForm.MediaFileFactory.Open(path);
                    if (file == null)
                    {
                        throw new Exception("The video stream cannot be opened");
                    }
                    btnReloadVideo.Enabled = true;
                }
                reader = file.GetVideoReader();
            }
            catch (AviSynthException e)
            {
                MessageBox.Show("AviSynth script error:\r\n" + e.Message, "AviSynth error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (ArgumentException e)
            {
                MessageBox.Show("AviSynth script error:\r\n" + e.Message, "AviSynth error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (Exception e)
            {
                MessageBox.Show("The file " + path + " cannot be opened.\r\n"
                                + "Error message: " + e.Message,
                                "Cannot open video input", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }

            if (reader != null && reader.FrameCount > 0)
            {
                this.positionSlider.Minimum       = 0;
                this.positionSlider.Maximum       = reader.FrameCount - 1;
                this.positionSlider.TickFrequency = this.positionSlider.Maximum / 20;
                this.viewerType = type;
                this.hasAR      = hasAR;
                zoomMaxWidth    = 0;
                SetMaxZoomWidth();
                doInitialAdjustment();
                int iStart = 0;
                if (startFrame >= 0)
                {
                    iStart = startFrame;
                }
                else
                {
                    iStart = reader.FrameCount / 2;
                }
                videoPreview.LoadVideo(reader, file.VideoInfo.FPS, iStart);
                setTitleText();
                return(true);
            }
            return(false);
        }