示例#1
0
 public IVideoReader GetVideoReader()
 {
     if (!HasVideo || !CanReadVideo)
     {
         throw new Exception("Can't read the video stream");
     }
     if (videoSourceFile == null || videoReader == null)
     {
         lock (this)
         {
             if (videoSourceFile == null)
             {
                 videoSourceFile = AvsFile.ParseScript(ScriptServer.GetInputLine(file,
                                                                                 PossibleSources.directShow, false, false, false, FPS));
                 videoReader = null;
             }
             if (videoReader == null)
             {
                 videoReader = videoSourceFile.GetVideoReader();
             }
         }
     }
     return(videoReader);
 }
示例#2
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);
        }