コード例 #1
0
        public void PlayFile()
        {
            MLVReader reader = null;
            Graphics picGraph = null;
            int lastFrameNumber = 1;

            string suffix = FileName.ToLower().Substring(FileName.Length - 4, 2);

            try
            {
                if (suffix == ".m")
                {
                    reader = new MLVReader(FileName, Handler.BlockHandler);
                }
                else
                {
                    reader = new RAWReader(FileName, Handler.BlockHandler);
                }
            }
            catch (ArgumentException)
            {
                MessageBox.Show("Failed to load file");
                PlayThread = null;
                return;
            }

            Invoke(new Action(() =>
            {
                trackBarPosition.Minimum = 1;
                trackBarPosition.Maximum = 1;
                trackBarPosition.Value = 1;
            }));
            try
            {
                while (true)
                {
                    while (reader.ReadBlock())
                    {
                        if (Handler.FileHeader.videoClass != 0x01)
                        {
                            MessageBox.Show("This video has an unsupported format (" + Handler.FileHeader.videoClass + ")");
                            reader.Close();
                            return;
                        }

                        ForceReread = false;

                        /* create info string */
                        string metaData = CreateMetaData();

                        if (Handler.FrameUpdated)
                        {
                            Invoke(new Action(() =>
                            {
                                try
                                {
                                    txtInfo.Text = metaData.ToString();
                                    trackBarPosition.Maximum = (int)reader.HighestVideoFrameNumber + 1;

                                    FramePositionWarning = "";

                                    if (trackBarPosition.Value == lastFrameNumber)
                                    {
                                        trackBarPosition.Value = (int)Math.Min(trackBarPosition.Maximum, Handler.VidfHeader.frameNumber + 1);
                                    }
                                    else
                                    {
                                        int block = reader.GetVideoFrameBlockNumber((uint)trackBarPosition.Value - 1);

                                        if (block >= 0)
                                        {
                                            reader.CurrentBlockNumber = (int)block;
                                        }
                                        else
                                        {
                                            FramePositionWarning = "  |  This particular frame is not part of the footage. Maybe some chunks missing?";
                                        }
                                    }

                                    lastFrameNumber = (int)Handler.VidfHeader.frameNumber + 1;

                                    Bitmap frame = Handler.CurrentFrame;

                                    string advText = "File: '" + reader.FileNames[reader.FileNum] + "' Offset: 0x" + reader.FilePos.ToString("X8") + " FrameSpace: 0x" + (Handler.VidfHeader.frameSpace-Handler.RawFixOffset).ToString("X4");

                                    lblPosition.Text = "Current position: " + (Handler.VidfHeader.frameNumber + 1) + "/" + (reader.TotalVideoFrameCount) + FramePositionWarning;
                                    lblPosition.Text += "    |    " + advText;

                                    /* update picturebox - this is very slow and inefficient */
                                    if (frame != null)
                                    {
                                        if (pictureBox.Image == null || pictureBox.Image.Size != frame.Size)
                                        {
                                            if (picGraph != null)
                                            {
                                                picGraph.Dispose();
                                            }
                                            Bitmap bmp = new Bitmap(frame);
                                            picGraph = Graphics.FromImage(bmp);
                                            pictureBox.Image = bmp;
                                        }
                                        picGraph.DrawImage(frame, 0, 0, frame.Size.Width, Handler.CurrentFrame.Size.Height);
                                        pictureBox.Refresh();
                                    }
                                }
                                catch (Exception e)
                                {
                                    MessageBox.Show("Exception: " + e);
                                }
                            }));
                        }

                        if (Paused && reader.LastType == "VIDF")
                        {
                            while (Paused)
                            {
                                bool reread = false;

                                Thread.Sleep(100);
                                Invoke(new Action(() =>
                                {
                                    try
                                    {
                                        if (trackBarPosition.Value != lastFrameNumber || ForceReread)
                                        {
                                            int block = reader.GetVideoFrameBlockNumber((uint)trackBarPosition.Value - 1);

                                            if (block >= 0)
                                            {
                                                reader.CurrentBlockNumber = (int)block;
                                            }
                                            reread = true;
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        MessageBox.Show("Exception: " + e);
                                    }
                                }));

                                if (reread)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (reader.CurrentBlockNumber < reader.MaxBlockNumber - 1)
                            {
                                reader.CurrentBlockNumber++;
                            }
                            else
                            {
                                reader.CurrentBlockNumber = 0;
                                Invoke(new Action(() =>
                                {
                                    trackBarPosition.Value = (int)Math.Min(trackBarPosition.Maximum, Handler.VidfHeader.frameNumber + 1);
                                }));
                            }
                        }
                    }
                }
            }
            catch (ThreadAbortException ex)
            {
                reader.Close();
                throw ex;
            }
        }
コード例 #2
0
        public void PlayFile()
        {
            MLVReader reader          = null;
            Graphics  picGraph        = null;
            int       lastFrameNumber = 1;

            string suffix = FileName.ToLower().Substring(FileName.Length - 4, 2);

            try
            {
                if (suffix == ".m")
                {
                    reader = new MLVReader(FileName, Handler.BlockHandler);
                }
                else
                {
                    reader = new RAWReader(FileName, Handler.BlockHandler);
                }
            }
            catch (ArgumentException)
            {
                MessageBox.Show("Failed to load file");
                PlayThread = null;
                return;
            }

            Invoke(new Action(() =>
            {
                trackBarPosition.Minimum = 1;
                trackBarPosition.Maximum = 1;
                trackBarPosition.Value   = 1;
            }));
            try
            {
                while (true)
                {
                    while (reader.ReadBlock())
                    {
                        if (Handler.FileHeader.videoClass != 0x01)
                        {
                            MessageBox.Show("This video has an unsupported format (" + Handler.FileHeader.videoClass + ")");
                            reader.Close();
                            return;
                        }

                        ForceReread = false;

                        /* create info string */
                        string metaData = CreateMetaData();

                        if (Handler.FrameUpdated)
                        {
                            Invoke(new Action(() =>
                            {
                                try
                                {
                                    txtInfo.Text             = metaData.ToString();
                                    trackBarPosition.Maximum = (int)reader.HighestVideoFrameNumber + 1;

                                    FramePositionWarning = "";

                                    if (trackBarPosition.Value == lastFrameNumber)
                                    {
                                        trackBarPosition.Value = (int)Math.Min(trackBarPosition.Maximum, Handler.VidfHeader.frameNumber + 1);
                                    }
                                    else
                                    {
                                        int block = reader.GetVideoFrameBlockNumber((uint)trackBarPosition.Value - 1);

                                        if (block >= 0)
                                        {
                                            reader.CurrentBlockNumber = (int)block;
                                        }
                                        else
                                        {
                                            FramePositionWarning = "  |  This particular frame is not part of the footage. Maybe some chunks missing?";
                                        }
                                    }

                                    lastFrameNumber = (int)Handler.VidfHeader.frameNumber + 1;

                                    Bitmap frame = Handler.CurrentFrame;

                                    string advText = "File: '" + reader.FileNames[reader.FileNum] + "' Offset: 0x" + reader.FilePos.ToString("X8") + " FrameSpace: 0x" + (Handler.VidfHeader.frameSpace - Handler.RawFixOffset).ToString("X4");

                                    lblPosition.Text  = "Current position: " + (Handler.VidfHeader.frameNumber + 1) + "/" + (reader.TotalVideoFrameCount) + FramePositionWarning;
                                    lblPosition.Text += "    |    " + advText;

                                    /* update picturebox - this is very slow and inefficient */
                                    if (frame != null)
                                    {
                                        if (pictureBox.Image == null || pictureBox.Image.Size != frame.Size)
                                        {
                                            if (picGraph != null)
                                            {
                                                picGraph.Dispose();
                                            }
                                            Bitmap bmp       = new Bitmap(frame);
                                            picGraph         = Graphics.FromImage(bmp);
                                            pictureBox.Image = bmp;
                                        }
                                        picGraph.DrawImage(frame, 0, 0, frame.Size.Width, Handler.CurrentFrame.Size.Height);
                                        pictureBox.Refresh();
                                    }
                                }
                                catch (Exception e)
                                {
                                    MessageBox.Show("Exception: " + e);
                                }
                            }));
                        }

                        if (Paused && reader.LastType == "VIDF")
                        {
                            while (Paused)
                            {
                                bool reread = false;

                                Thread.Sleep(100);
                                Invoke(new Action(() =>
                                {
                                    try
                                    {
                                        if (trackBarPosition.Value != lastFrameNumber || ForceReread)
                                        {
                                            int block = reader.GetVideoFrameBlockNumber((uint)trackBarPosition.Value - 1);

                                            if (block >= 0)
                                            {
                                                reader.CurrentBlockNumber = (int)block;
                                            }
                                            reread = true;
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        MessageBox.Show("Exception: " + e);
                                    }
                                }));

                                if (reread)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (reader.CurrentBlockNumber < reader.MaxBlockNumber - 1)
                            {
                                reader.CurrentBlockNumber++;
                            }
                            else
                            {
                                reader.CurrentBlockNumber = 0;
                                Invoke(new Action(() =>
                                {
                                    trackBarPosition.Value = (int)Math.Min(trackBarPosition.Maximum, Handler.VidfHeader.frameNumber + 1);
                                }));
                            }
                        }
                    }
                }
            }
            catch (ThreadAbortException ex)
            {
                reader.Close();
                throw ex;
            }
        }
コード例 #3
0
        private void DisplayFunc()
        {
            Graphics picGraph = null;

            Handler.UseCorrectionMatrices = false;
            Handler.SelectDebayer(2);

            string suffix = FileInfo.Extension.ToLower().Substring(0, 2);

            try
            {
                if (suffix == ".m")
                {
                    Reader = new MLVReader(FileInfo.FullName, Handler.BlockHandler);
                }
                else
                {
                    Reader = new RAWReader(FileInfo.FullName, Handler.BlockHandler);
                }
            }
            catch (ArgumentException)
            {
                SetText("Load failed");
                DisplayThread = null;
                return;
            }

            try
            {
                while (true)
                {
                    while (Reader.ReadBlock())
                    {
                        if (Handler.FileHeader.videoClass != 0x01)
                        {
                            SetText("Not supported");
                            Reader.Close();
                            DisplayThread = null;
                            return;
                        }

                        UpdateMetadata();

                        if (Handler.FrameUpdated)
                        {
                            try
                            {
                                Invoke(new Action(() =>
                                {
                                    try
                                    {
                                        Bitmap frame = Handler.CurrentFrame;

                                        /* update picturebox - this is very slow and inefficient */
                                        if (frame != null)
                                        {
                                            if (pictureBox.Image == null || pictureBox.Image.Size != frame.Size)
                                            {
                                                if (picGraph != null)
                                                {
                                                    picGraph.Dispose();
                                                }
                                                Bitmap bmp = new Bitmap(frame);
                                                picGraph = Graphics.FromImage(bmp);
                                                pictureBox.Image = bmp;
                                            }
                                            picGraph.DrawImage(frame, 0, 0, frame.Size.Width, Handler.CurrentFrame.Size.Height);
                                            pictureBox.Refresh();
                                        }

                                        textLabel.Text = FileInfo.Name + Environment.NewLine + "(Frame " + (Handler.VidfHeader.frameNumber + 1) + "/" + (Reader.HighestVideoFrameNumber + 1) + ")";

                                        if (Reader.FrameErrors > 0)
                                        {
                                            textLabel.BackColor = Color.Red;
                                            textLabel.Text += " (Errors)";

                                            if (Reader.FrameMissingErrors > 0)
                                            {
                                                SetMetadata("Error: Missing frames", Reader.FrameMissingErrors + " frame IDs are missing in the MLV. If this is a multi-chunk video, make sure you have all chunks in the same place.");
                                            }
                                            if(Reader.FrameRedundantErrors > 0)
                                            {
                                                SetMetadata("Error: Redundant frames", Reader.FrameRedundantErrors + " frames with same ID appeared more than once in the MLV. Report please.");
                                            }
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        SetText(e);
                                    }
                                }));
                            }
                            catch (Exception ex)
                            {
                            }

                            /* videos that are not selected, run very slowly */
                            if (!Selected)
                            {
                                Thread.Sleep(1000);
                            }

                            if (SingleStep)
                            {
                                SingleStep = false;
                                Paused = true;
                            }

                            /* dont break when there was no preview frame processed yet */
                            while (Paused && pictureBox.Image != null)
                            {
                                Thread.Sleep(50);
                            }
                        }

                        if (Reader.CurrentBlockNumber < Reader.MaxBlockNumber - 1)
                        {
                            Reader.CurrentBlockNumber++;
                        }
                        else
                        {
                            if (pictureBox.Image == null)
                            {
                                SetText("Contains no video");
                                DisplayThread = null;
                                return;
                            }
                            Reader.CurrentBlockNumber = 0;
                        }

                        if (NextBlockNumber >= 0)
                        {
                            Reader.CurrentBlockNumber = NextBlockNumber;
                            NextBlockNumber = -1;
                        }
                    }
                }
            }
            catch (ThreadAbortException ex)
            {
                Reader.Close();
                throw ex;
            }
            catch (IOException ex)
            {
                SetText(ex);
                return;
            }
            catch (Exception ex)
            {
                SetText(ex);
                return;
            }
        }