Exemplo n.º 1
0
        private void buttonDecode_Click(object sender, EventArgs e)
        {
            string fn  = string.Format(textOutputMask.Text, 0);
            string dir = Path.GetDirectoryName(fn);

            Directory.CreateDirectory(dir);

            FileStream    fs = new FileStream(videoFileName, FileMode.Open);
            IEntropyCodec s;

            if (fs == null)
            {
                return;
            }

            using ( fs )
            {
                labelSpeed.Text = "Decoding..";
                Stopwatch sw = new Stopwatch();
                sw.Start();

                VideoCodec vc = new VideoCodec();
                s = vc.DecodeHeader(fs);
                int i = 0;
                do
                {
                    using (Bitmap fi = vc.DecodeFrame(i, s))
                    {
                        if (fi == null)
                        {
                            s.Close();
                            fs.Close();
                            labelSpeed.Text = string.Format("Decoded {0} frames in {1:f} s!", i, (float)(sw.ElapsedMilliseconds * 0.001));
                            sw.Stop();
                            return;
                        }
                        fn = string.Format(textOutputMask.Text, i++);
                        fi.Save(fn, ImageFormat.Png);
                    }
                }while (true);
            }
        }
Exemplo n.º 2
0
        private void buttonEncode_Click(object sender, EventArgs e)
        {
            string fn = string.Format(textInputMask.Text, 0);

            if (!File.Exists(fn))
            {
                MessageBox.Show("Invalid input files!");
                return;
            }

            string         cd  = Directory.GetCurrentDirectory();
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Title        = "Save Video File";
            sfd.Filter       = "BIN Files|*.bin";
            sfd.AddExtension = true;
            sfd.FileName     = videoFileName;
            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            videoFileName = Path.GetFullPath(sfd.FileName);
            FileStream fs = new FileStream(videoFileName, FileMode.Create);
            VideoCodec vc = new VideoCodec();

            Directory.SetCurrentDirectory(cd);

            labelSpeed.Text = "Encoding..";
            Stopwatch sw = new Stopwatch();

            sw.Start();

            Bitmap        frameImage = (Bitmap)Image.FromFile(fn);
            IEntropyCodec s          = vc.EncodeHeader(frameImage.Width, frameImage.Height, (float)numericFps.Value, fs);
            int           i          = 0;

            do
            {
                vc.EncodeFrame(i, frameImage, s);
                frameImage.Dispose();
                frameImage = null;

                // next frame:
                fn = string.Format(textInputMask.Text, ++i);
                if (!File.Exists(fn))
                {
                    break;
                }
                frameImage = (Bitmap)Image.FromFile(fn);
            }while (true);

            if (frameImage != null)
            {
                frameImage.Dispose();
            }
            s.Close();
            labelSpeed.Text = string.Format("Encoded {0} frames in {1:f} s!", i, (float)(sw.ElapsedMilliseconds * 0.001));
            sw.Stop();
            fs.Close();
        }
Exemplo n.º 3
0
 private VideoCodec GetVideoCodec(StreamWriter log)
 {
     VideoCodec codec = new VideoCodec(log);
     codec.MCSearchLineSize = (int)mcHorizVertNumeric.Value;
     codec.MCSearchSquareSize = (int)mcSquareNumeric.Value;
     codec.VisualizeMCBlockTypes = blockTypeVizCheckBox.Checked;
     codec.DeflateCompressionEnabled = deflateCheckBox.Checked;
     codec.IntraFrameFrequency = (int)intraFreqNumeric.Value;
     return codec;
 }