Ejemplo n.º 1
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)
        {
            lock (this)
            {
                if (file != null)
                    file.Dispose();
                if (videoPreview.Image != null)
                    videoPreview.Image.Dispose(); // get rid of previous bitmap
            }

            try
            {
                if (inlineAvs)
                {
                    file = AvsFile.ParseScript(path);
                }
                else
                {
                    file = mainForm.MediaFileFactory.Open(path);
                    if (file == null && !(file.Info.HasVideo && file.CanReadVideo))
                        throw new ArgumentException("The video stream cannot be opened");
                }
                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 Please make sure it's a valid AviSynth script and that AviSynth is "
                    + " properly installed.\r\nYou can check the validity of your script and AviSynth installation by opening the file in your favorite media player.\r\n"
                    + " If that works, try opening the video in VirtualDub(Mod) as well. If the former works and the latter doesn't, install a YV12 codec.\r\n"
                    + "Error message for your reference: " + 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.Value = startFrame >= 0 ? startFrame : reader.FrameCount / 2;
                this.positionSlider.TickFrequency = this.positionSlider.Maximum / 20;
                this.viewerType = type;
                this.hasAR = hasAR;
                this.videoWindowWidth = (int)file.Info.Width;
                this.videoWindowHeight = (int)file.Info.Height;
                zoomWidth = (int)file.Info.Width;
                doInitialAdjustment();
                adjustSize();
                positionSlider_Scroll(null, null); // makes the image visible
                this.Text = "Current position: " + this.positionSlider.Value + "/" + this.positionSlider.Maximum;
                isRunning = false;
                millisecondsPerFrame = (int)(1000 / file.Info.FPS);
                return true;
            }
            return false;
        }
Ejemplo n.º 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>
 /// <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)
 {
     return loadVideo(mainForm, path, type, hasAR, inlineAvs, -1);
 }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 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>
 /// <returns>true if the video could be opened, false if not</returns>
 public bool loadVideo(MainForm mainForm, string path, PREVIEWTYPE type, bool hasAR)
 {
     return loadVideo(mainForm, path, type, hasAR, false, -1);
 }
Ejemplo n.º 5
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>
 /// <returns>true if the video could be opened, false if not</returns>
 public bool loadVideo(MainForm mainForm, string path, PREVIEWTYPE type, bool hasAR)
 {
     return(loadVideo(mainForm, path, type, hasAR, false, -1, false));
 }