private void recordVideo()
        {
            AVIWriter writer = new AVIWriter("wmv3");

            writer.Open("test.avi", 320, 240);
            Bitmap image = new Bitmap(320, 240);

            for (int i = 0; i < 240; i = i + 5)
            {
                if (i == 235)
                {
                    break;
                }
                if (i > 4)
                {
                    image.SetPixel(i - 1, i - 1, Color.Black);
                    image.SetPixel(i - 2, i - 2, Color.Black);
                    image.SetPixel(i - 3, i - 3, Color.Black);
                    image.SetPixel(i - 4, i - 4, Color.Black);
                    image.SetPixel(i - 5, i - 5, Color.Black);
                }

                image.SetPixel(i, i, Color.Red);
                image.SetPixel(i + 1, i + 1, Color.Red);
                image.SetPixel(i + 2, i + 2, Color.Red);
                image.SetPixel(i + 3, i + 3, Color.Red);
                image.SetPixel(i + 4, i + 4, Color.Red);

                writer.AddFrame(image);
            }
            writer.Close();
        }
コード例 #2
0
ファイル: SandBoxForm.cs プロジェクト: Tirkirill/Paint
        private void SaveAnimationButton_Click(object sender, EventArgs e)
        {
            if (bitmaps.Count == 0)
            {
                MessageBox.Show(StringResources.NoFrame);
                return;
            }
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.DefaultExt   = "avi";
            sfd.AddExtension = true;
            sfd.Filter       = "(*.avi)|*.avi";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                AVIWriter aw = new AVIWriter("MSVC");
                aw.FrameRate = Settings.framerate;
                aw.Open(sfd.FileName, FrameWidth, FrameHeight);
                for (int j = 0; j < bitmaps.Count; j++)
                {
                    Bitmap bitmap = (Bitmap)bitmaps[j].Clone();
                    double secs   = FrameDurations[j];
                    for (int i = 0; i < secs * Settings.framerate; i++)
                    {
                        aw.AddFrame(bitmap);
                    }
                }
                aw.Quality = 1;
                aw.Close();
            }
        }
コード例 #3
0
ファイル: frmScreen.cs プロジェクト: randianb/DownLoadDemo
 private void aviSaveAs()
 {
     try
     {
         OleDbConnection conn = bc.GetConn();
         conn.Open();
         OleDbCommand cmd = new OleDbCommand("select strPath from tb_VideoPath where ID=1", conn);
         string       str = cmd.ExecuteScalar().ToString().Trim();
         FileInfo     fi  = new FileInfo(str);
         if (fi.Exists)
         {
             fi.Delete();
         }
         conn.Close();
         aviWriter = new AVIWriter();
         //avi中所有图像皆不能小于width及height
         avi_frame = aviWriter.Create(str, 1, SWidth, SHeight);
         for (int i = 0; i < al.Count; i++)
         {
             //获得图像
             Bitmap cache = new Bitmap(Image.FromFile(al[i].ToString()));
             //由于转化为avi后呈现相反,所以翻转
             cache.RotateFlip(RotateFlipType.Rotate180FlipX);
             //载入图像
             aviWriter.LoadFrame(cache);
             aviWriter.AddFrame();
         }
         aviWriter.Close();
         avi_frame.Dispose();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #4
0
        public ViewerWindow(string serverHostIp, int serverPort, string captureAviFile)
        {
            this.captureAviFile = captureAviFile;
            InitializeComponent();

            videoClient = new TcpVideoClient(serverHostIp, serverPort);

            grabWidth  = 320;
            grabHeight = 240;

            imageWidth  = grabWidth * 2;
            imageHeight = grabHeight * 2;

            Height = imageHeight + 210;

            aviWriter = new AVIWriter();

            ImageViewer.Width        = imageWidth;
            ImageViewer.Height       = imageHeight;
            compressionRate          = 30;
            CompressionLabel.Content = string.Format("{0}%", compressionRate);
            CompressionSlider.Value  = compressionRate;

            StartVideoButton.Visibility = Visibility.Visible;
            StopVideoButton.Visibility  = Visibility.Hidden;
        }
コード例 #5
0
        private void MonitorForm_Load(object sender, EventArgs e)
        {
            // 初始化数据库连接并打开
            pgsql = new PgsqlDB(ConfigurationManager.AppSettings.Get("dbHost"),
                                ConfigurationManager.AppSettings.Get("dbName"),
                                ConfigurationManager.AppSettings.Get("dbUser"),
                                ConfigurationManager.AppSettings.Get("dbPassword"));
            pgsql.open();
            sqlite = new SqliteDB(ConfigurationManager.AppSettings.Get("dbPath"));
            sqlite.open();
            sqlite.initCameraDatabase();
            _log.Info("Pgsql DB & SQLite connected!");

            // 初始化视频流显示
            videoStream           = new MJPEGStream();
            videoStream.NewFrame += new NewFrameEventHandler(videoStream_NewFrame);
            _log.Info("Video Stream inited!");

            // 保存视频
            if (!Directory.Exists("_video_saved"))
            {
                Directory.CreateDirectory("_video_saved");
            }
            videoWriter           = new AVIWriter();
            videoWriter.FrameRate = 2;

            // 初始化摄像头列表
            cameras = sqlite.getCameras();
            cameras.ForEach(camera => lbCameras.Items.Add(camera));
        }
コード例 #6
0
        //call back for timer which is used to display
        //alarm window on motion detection. The timer
        //interval is 1 sec, and alarmInterval is increased
        //by n sec by alarm callback
        void timer_Tick(object sender, EventArgs e)
        {
            if (alarmInterval > 0)
            {
                alarmInterval--;
            }
            if (alarmInterval == 0)
            {
                audioPlayed        = false;
                frameDropThreshold = 0;

                if (recording)
                {
                    if (videoWriter != null)
                    {
                        try
                        {
                            Log.info(String.Format("Closing idle writer for camera {0}", options.Name));
                            videoWriter.Close();
                            videoWriter = null;
                        }
                        catch (Exception io)
                        {
                            Log.warn(String.Format("Error closing recorded video file for {0}. Record Folder: {1}. Message: {2}", options.Name, options.RecordFolder, io.Message));
                        }
                    }
                    recording = false;
                }
            }
        }
コード例 #7
0
ファイル: FormMain.cs プロジェクト: fedimser/Aldyparen
        private void makeVideo(object _param)
        {
            isNowVideoSaving = true;
            photoThreadsCounter++;

            VideoParameters param = (VideoParameters)_param;

            Accord.Video.VFW.AVIWriter wr;
            wr = new AVIWriter();

            wr.FrameRate = Convert.ToInt32(param.FPS);
            wr.Open(param.path, 2 * param.halfWidth, 2 * param.halfHeight);

            int frameCount = param.movie.frameCount();

            for (int i = 0; i < frameCount; i++)
            {
                wr.AddFrame(param.movie[i].getFrame(param.halfWidth, param.halfHeight, grid));
                Console.WriteLine("Frame {0} out of {1} is done!", i + 1, frameCount);
                statusFrames = String.Format("{0}/{1}", i + 1, frameCount);
            }

            wr.Close();

            photoThreadsCounter--;
            isNowVideoSaving = false;
            statusFrames     = "";
        }
コード例 #8
0
        private void GrabarVideo()
        {
            AVIWriter grabadorVideo = new AVIWriter();

            try
            {
                Bitmap   imagen       = Camaras.CapturarImagen(visorCamara1);
                DateTime Hoy          = DateTime.Now;
                string   fecha_actual = Hoy.ToString("dd-MM-yyyy HH-mm-ss");
                grabadorVideo.Open(rutaCapturas + "\\video_" + fecha_actual + ".avi", imagen.Width, imagen.Height);
                while (true)
                {
                    if (grabandoVideo1)
                    {
                        grabadorVideo.AddFrame(Camaras.CapturarImagen(visorCamara1));
                        Thread.Sleep(50);
                    }
                    else
                    {
                        break;
                    }
                }
                grabadorVideo.Close();
            }
            catch (Exception)
            {
                grabadorVideo.Close();
            }
        }
コード例 #9
0
        private void Camera_NewFrame(object sender, EventArgs e)
        {
            if ((intervalsToSave != 0) && (saveOnMotion == true))
            {
                // lets save the frame
                if (writer == null)
                {
                    string fileName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".avi";
                    try
                    {
                        writer = new AVIWriter("wmv3");                                                 // create AVI writer
                        writer.Open(fileName, _CameraWindow.Camera.Width, _CameraWindow.Camera.Height); // open AVI file
                    }
                    catch (ApplicationException ex)
                    {
                        if (writer != null)
                        {
                            writer.Dispose();
                            writer = null;
                        }
                    }
                }

                Camera camera = _CameraWindow.Camera;   // save the frame
                camera.Lock();
                writer.AddFrame(camera.LastFrame);
                camera.Unlock();
            }
        }
コード例 #10
0
        // Close current file
        private void CloseFile( )
        {
            Camera camera = cameraWindow.Camera;

            if (camera != null)
            {
                // detach camera from camera window
                cameraWindow.Camera = null;

                // signal camera to stop
                camera.SignalToStop( );
                // wait for the camera
                camera.WaitForStop( );

                camera = null;

                if (detector != null)
                {
                    detector.Reset( );
                }
            }

            if (writer != null)
            {
                writer.Dispose( );
                writer = null;
            }
            intervalsToSave = 0;
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: iceslab/KamerkaWF
        private void RecordButton_Click(object sender, EventArgs e)
        {
            if (!recordVideo)
            {
                SaveFileDialog dialog = new SaveFileDialog();

                dialog.Filter           = "Plik AVI (*.avi)|*.avi";
                dialog.FilterIndex      = 1;
                dialog.RestoreDirectory = true;
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    writer           = new AVIWriter("cvid");
                    writer.FrameRate = 5;
                    var width  = videoSource.VideoResolution.FrameSize.Width;
                    var height = videoSource.VideoResolution.FrameSize.Height;

                    writer.Open(dialog.FileName, width, height);
                    recordVideo       = true;
                    RecordButton.Name = "Stop recording";
                }
            }
            else
            {
                recordVideo = false;
                captureThread.Join();
                writer.Close();
                RecordButton.Name = "Recording";
            }
        }
コード例 #12
0
 public void Dispose()
 {
     if (writer_ != null)
     {
         writer_.Close();
         writer_.Dispose();
         writer_ = null;
     }
 }
コード例 #13
0
        public API_AForge_Video newVideo(string pathToVideo)
        {
            PathToAviVideo        = pathToVideo;
            VideoWriter           = new AVIWriter(VideoCodec);
            VideoWriter.FrameRate = FrameRate;

            VideoWriter.Open(PathToAviVideo, VideoWidth, VideoHeight);
            return(this);
        }
コード例 #14
0
ファイル: JLvideo.cs プロジェクト: xuhui/MyUsbPrj
 public JLvideo()
 {
     // create JPEG video source
     mStream = new AForge.Video.JPEGStream();
     // set NewFrame event handler
     mStream.NewFrame += new AForge.Video.NewFrameEventHandler(video_NewFrame);
     // instantiate AVI writer, use WMV3 codec
     mAviWriter = new AVIWriter("wmv3");
 }
コード例 #15
0
        //private void jpgToAVIByFFpeg(String[] pic, String newPic, int delayTime)
        //{
        //    int frameRate = 25;

        //    if (delayTime > 0)
        //        frameRate = Convert.ToInt32(1000f / delayTime);

        //    VideoFileWriter writer = new VideoFileWriter();


        //    Image im;
        //    if (tVLeft.Nodes.Count > 0)
        //    {
        //        im = Image.FromFile(tVLeft.Nodes[0].Name.ToString());
        //        int w = im.Width;
        //        int h = im.Height;
        //        progressBar1.Maximum = tVLeft.Nodes.Count;
        //        if (w % 2 != 0)
        //            w += 1;
        //        if (h % 2 != 0)
        //            h += 1;

        //        writer.Open(newPic, w, h, frameRate, VideoCodec.MPEG4);

        //        for (int i = 0; i < tVLeft.Nodes.Count; i++)
        //        {
        //            im.Dispose();
        //            im = Image.FromFile(tVLeft.Nodes[i].Name.ToString());
        //            im = BitmapToBlowUp(im, w, h);

        //            this.pictureBox1.Image = im;
        //            this.pictureBox1.Refresh();
        //            if ((im.Height != h) | (im.Width != w))
        //                MessageBox.Show(tVLeft.Nodes[i].Name.ToString() + " 文件大小与首张不符!");
        //            writer.WriteVideoFrame((Bitmap)im);

        //            progressBar1.Value += 1;

        //            curFile.Text = i.ToString() + ">>> " + getFileNameOnly(pic[i]);
        //            curFile.Refresh();
        //        }
        //        writer.Close();
        //        writer.Dispose();

        //        MessageBox.Show("AVI 动画文件转换完毕!");
        //    }
        //} // FFPEG 类生成AVI,使用 MPG4 格式压缩
        // 如果使用 FFPEG 类,则需要:
        // 1、引用如下类库:
        //  AForge.Video.FFMPEG
        // 2、将如下类库 Copy 到目标程度所在文件夹,如 bin\debug 等。
        // AForge.Net FrameWork \Externals\FFMPEG\BIN文件夹下的所有 DLL 文件
        // avcodec-53.dll,avdevice-53.dll,avfilter-2.dll,avformat-53.dll,avutil-51.dll,postproc-52.dll,swresample-0.dll,swscale-2.dll
        private void jpgToAVI(String[] pic, String newPic, int delayTime)
        {
            int frameRate = 25;

            if (delayTime > 0)
            {
                frameRate = Convert.ToInt32(1000f / delayTime);
            }

            AVIWriter aviWriter = new AVIWriter("wmv3");

            aviWriter.FrameRate = frameRate;

            Image im;

            if (tVLeft.Nodes.Count > 0)
            {
                im = Image.FromFile(tVLeft.Nodes[0].Name.ToString());
                int w = im.Width;
                int h = im.Height;
                progressBar1.Maximum = tVLeft.Nodes.Count;

                if (w % 2 != 0)
                {
                    w += 1;
                }
                if (h % 2 != 0)
                {
                    h += 1;
                }

                aviWriter.Open(newPic, w, h);  // 输出到指定的文件

                for (int i = 0; i < tVLeft.Nodes.Count; i++)
                {
                    im.Dispose();
                    im = Image.FromFile(tVLeft.Nodes[i].Name.ToString());
                    im = BitmapToBlowUp(im, w, h);

                    this.pictureBox1.Image = im;
                    this.pictureBox1.Refresh();
                    if ((im.Height != h) | (im.Width != w))
                    {
                        MessageBox.Show(tVLeft.Nodes[i].Name.ToString() + " 文件大小与首张不符!");
                    }
                    aviWriter.AddFrame((Bitmap)im);
                    progressBar1.Value += 1;

                    curFile.Text = i.ToString() + ">>> " + getFileNameOnly(pic[i]);
                    curFile.Refresh();
                }
                aviWriter.Close();
                aviWriter.Dispose();
                MessageBox.Show("AVI 动画文件转换完毕!");
            }
        } // WMV3 格式压缩
コード例 #16
0
 public static void WriteAvi(string path, int width, int height, VideoType videoType = VideoType.Default)
 {
     avi = new AVIWriter();
     if (videoType != VideoType.Default)
     {
         avi.Codec = videoType.ToString();
     }
     avi.FrameRate = 10;
     avi.Open(path, width, height);
 }
コード例 #17
0
 public void MakePreparedWriterActive()
 {
     lock (aviWatchDog)
     {
         AVIWriter tmp = currentAvi;
         currentAvi  = preparedAvi;
         preparedAvi = tmp;
         FileName    = PreparedFileName;
     }
 }
コード例 #18
0
        private void StartConsumerThread()
        {
            if (!IsWorking)
            {
                IsWorking = true;

                Helpers.CreateDirectoryIfNotExist(OutputPath);

                AVIWriter aviWriter = new AVIWriter(OutputPath, FPS, Size.Width, Size.Height, ShowOptions);

                task = TaskEx.Run(() =>
                {
                    try
                    {
                        position = 0;

                        while (!imageQueue.IsCompleted)
                        {
                            Image img = null;

                            try
                            {
                                img = imageQueue.Take();

                                if (img != null)
                                {
                                    //img.Save("Test\\" + position + ".bmp", ImageFormat.Bmp);
                                    aviWriter.AddFrame((Bitmap)img);
                                    position++;
                                }
                            }
                            catch (InvalidOperationException)
                            {
                            }
                            finally
                            {
                                if (img != null)
                                {
                                    img.Dispose();
                                }
                            }
                        }
                    }
                    finally
                    {
                        IsWorking = false;

                        if (aviWriter != null)
                        {
                            aviWriter.Dispose();
                        }
                    }
                });
            }
        }
コード例 #19
0
ファイル: AVICache.cs プロジェクト: Z1ni/ShareX
        public AVICache(string outputPath, int fps, Size size, bool showOptions = false)
        {
            OutputPath = outputPath;
            FPS = fps;
            Size = size;
            ShowOptions = showOptions;

            Helpers.CreateDirectoryIfNotExist(OutputPath);
            aviWriter = new AVIWriter(OutputPath, FPS, Size.Width, Size.Height, ShowOptions);
            imageQueue = new BlockingCollection<Image>();
        }
コード例 #20
0
ファイル: INDForm.cs プロジェクト: sergeyit105/indivoop
        private void button2_Click(object sender, EventArgs e)
        {
            writer = new AVIWriter("DIB ");
            writer.Open("video.avi", 160, 120);
            Bitmap image = new Bitmap(160, 120);

            videoSource           = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
            videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
#pragma warning disable CS0612
            videoSource.DesiredFrameSize = new Size(160, 120);
#pragma warning restore CS0612
            videoSource.Start();
        }
コード例 #21
0
        public void startSave(string fid = "", int max_frames = 1000, int max_size_mb = 1000)
        // buffer size is only required if compress is true
        {
            writeFileName = fileName;
            if (fid.Length > 0)
            {
                writeFileName = fid;
            }
            frameCount = 0;
            if (writeFileName.EndsWith(".avi"))
            {
                aviWriter           = new AVIWriter("MRLE");
                aviWriter.FrameRate = 30;
                Console.WriteLine("Codec:" + aviWriter.Codec);
                if (File.Exists(writeFileName))
                {
                    File.Delete(writeFileName);  // otherwise it will not run
                }
                aviWriter.Open(writeFileName, Convert.ToInt32(640), Convert.ToInt32(480));
                // always crashes here anyway - something to do with Windows7 I think
                // found some advice at http://code.google.com/p/aforge/issues/detail?id=312

                /*
                 * Type     Name              Format Binary             Version
                 * ICM  Microsoft RLE     MRLE  msrle32.dll     6.1.7600.16490
                 * ICM  Microsoft Video 1 MSVC  msvidc32.dll    6.1.7600.16490
                 * ICM  Microsoft YUV     UYVY  msyuv.dll   6.1.7600.16490
                 * ICM  Intel IYUV codec  IYUV  iyuv_32.dll     6.1.7600.16490
                 * ICM  Toshiba YUV Codec   Y411    tsbyuv.dll  6.1.7600.16490
                 * ICM  Cinepak Codec by Radius     cvid    iccvid.dll  1.10.0.13
                 * DMO  Mpeg4s Decoder DMO  mp4s, MP4S, m4s2, M4S2, MP4V, mp4v, XVID, xvid, DIVX, DX50  mp4sdecd.dll    6.1.7600.16385
                 * DMO  WMV Screen decoder DMO  MSS1, MSS2  wmvsdecd.dll    6.1.7600.16385
                 * DMO  WMVideo Decoder DMO     WMV1, WMV2, WMV3, WMVA, WVC1, WMVP, WVP2    wmvdecod.dll    6.1.7600.16385
                 * DMO  Mpeg43 Decoder DMO  mp43, MP43  mp43decd.dll    6.1.7600.16385
                 * DMO  Mpeg4 Decoder DMO   MPG4, mpg4, mp42, MP42  mpg4decd.dll    6.1.7600.16385
                 * */
            }
            else
            {
                toCompress  = !writeFileName.EndsWith(".vid");
                writePos    = 0;
                maxFrames   = max_frames;
                maxSizeMb   = max_size_mb;
                frameWriter = new BinaryWriter(File.Open(writeFileName, FileMode.Create));
                if (toCompress)
                {
                    writeFramePosList = new List <Int32>();
                }
                saveMode = true;
            }
        }
コード例 #22
0
        public void sendFrame(Bitmap frame, string Name)
        {
            if (alarmInterval > 0)
            {
                if (!audioPlayed && options.EnableAlertSound)
                {
                    try
                    {
                        Log.debug(String.Format("Playing audio file {0} for camera {1}", options.AlertSoundFile, options.Name));
                        audioPlayed = true;
                        SoundPlayer simpleSound = new SoundPlayer(options.AlertSoundFile);
                        simpleSound.Play();
                    }
                    catch (Exception e)
                    {
                        Log.error(String.Format("Unable to play audio file for {0}. Error: {1}", options.Name, e.Message));
                    }
                }
                if (recording && options.EnableRecording && frameDropThreshold <= MAX_FRAME_DROP)
                {
                    try
                    {
                        if (videoWriter == null)
                        {
                            DateTime now      = DateTime.Now;
                            string   file     = String.Format("{0}-{1:D4}.{2:D2}.{3:D2}-{4:D2}.{5:D2}.{6:D2}.avi", options.Name, now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
                            string   fullpath = Path.Combine(options.RecordFolder, file);

                            Log.debug(String.Format("Creating new Video Writer {0} with codec {1}",
                                                    fullpath, options.Codec));

                            videoWriter = new AVIWriter(options.Codec.Code);
                            videoWriter.Open(fullpath, frame.Width, frame.Height);
                        }

                        videoWriter.AddFrame(frame);
                    }
                    catch (Exception io)
                    {
                        frameDropThreshold++;
                        videoWriter = null;
                        Log.warn(String.Format("Error writing video frame for {0}. Record Folder: {1}. Message: {2}", options.Name, options.RecordFolder, io.Message));
                        if (frameDropThreshold == MAX_FRAME_DROP)
                        {
                            Log.error(String.Format("Maximum ({0}) frames failed for {1}. Dropping all frames until next motion alert", MAX_FRAME_DROP, options.Name));
                        }
                    }
                }
            }
        }
コード例 #23
0
ファイル: Form1.cs プロジェクト: bladimirbalbin/PruebaCamara
        private void btnRecord_Click(object sender, EventArgs e)
        {
            AVIWriter writer = new AVIWriter("wmv3");

            writer.Open("test.avi", 320, 240);
            Bitmap image = new Bitmap(320, 240);

            for (int i = 0; i < 240; i++)
            {
                image.SetPixel(i, i, Color.Red);
                writer.AddFrame(image);
            }
            writer.Close();
        }
コード例 #24
0
            public SaveVideo(Stegonography steg)
            {
                stegonography = steg;
                //Saving into new AVI
                // create instance of video writer

                //Uncommented till VideoFileWriter is compressing the data!
                //writer = new VideoFileWriter();
                //writer.Open("test.avi", stegonography.Width + 1, stegonography.Height + 1, stegonography.FPS, VideoCodec.MPEG4);

                //Empty constructor is creating writer with DIB codec which means no compression
                writer           = new AVIWriter();
                writer.FrameRate = steg.FPS;
                writer.Open("test.avi", steg.Width + 1, steg.Height + 1);
            }
コード例 #25
0
 private void button5_Click(object sender, EventArgs e)
 {
     if (toggleRec == false)
     {
         SaveFileDialog saveAVI = new SaveFileDialog();
         saveAVI.Filter = "AVI Files (*.avi)|*.avi";
         if (saveAVI.ShowDialog() == DialogResult.OK)
         {
             writer = new AVIWriter("XVID");
             writer.Open(saveAVI.FileName, 480, 640);
             toggleRec = true;
             Label lblRec = new Label();
         }
     }
 }
コード例 #26
0
 public AviWriter(String path, int width = 0, int height = 0)
 {
     if (width == 0 || height == 0)
     {
         path       += ".stream";
         videoStream = File.Create(path, 1392640);
     }
     else
     {
         path                 += ".avi";
         videoWriter           = new AVIWriter("ffds");
         videoWriter.FrameRate = 12;
         videoWriter.Open(path, width, height);
     }
 }
コード例 #27
0
 private void Form1_Load(object sender, EventArgs e)
 {
     contBtn.Enabled     = false;
     pauseBtn.Enabled    = false;
     statusTxt.Text      = "";
     aviWriter           = new AVIWriter();
     aviWriter.FrameRate = 1000 / timer1.Interval;
     foreach (FilterInfo info in videoDevices)
     {
         listBox1.Items.Add(info.Name);
     }
     if (listBox1.Items.Count > 0)
     {
         listBox1.SelectedIndex = 0;
     }
 }
コード例 #28
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (this.toggleButton.Text == "Start Rec.")
     {
         this.toggleButton.Text      = "STOP Rec.";
         this.toggleButton.BackColor = Color.Black;
         toggleButton.ForeColor      = Color.White;
         saveVideo           = new AVIWriter("wmv3");
         saveVideo.FrameRate = 15;
         saveVideo.Open("video.avi", 640, 480);
     }
     else
     {
         this.toggleButton.Text = "Start Rec.";
         toggleButton.ForeColor = Color.Black;
         toggleButton.BackColor = Color.White;
         saveVideo.Close();
     }
 }
コード例 #29
0
        // On timer event - gather statistic
        private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Camera camera = cameraWindow.Camera;

            if (camera != null)
            {
                // get number of frames for the last second
                statCount[statIndex] = camera.FramesReceived;

                // increment indexes
                if (++statIndex >= statLength)
                {
                    statIndex = 0;
                }
                if (statReady < statLength)
                {
                    statReady++;
                }

                float fps = 0;

                // calculate average value
                for (int i = 0; i < statReady; i++)
                {
                    fps += statCount[i];
                }
                fps /= statReady;

                statCount[statIndex] = 0;

                fpsPanel.Text = fps.ToString("F2") + " fps";
            }

            // descrease save counter
            if (intervalsToSave > 0)
            {
                if ((--intervalsToSave == 0) && (writer != null))
                {
                    writer.Dispose( );
                    writer = null;
                }
            }
        }
コード例 #30
0
        public Video(String input, String output, int length, String extension, int LSB, String password)
        {
            Length       = length;
            Extension    = extension;
            this.LSB     = LSB;
            Password     = ToPasswordSeed(password);
            SumPNSRFrame = 0;
            SumPNSR      = 0;
            PNSR         = 0;

            reader = new AVIReader();
            writer = new AVIWriter();

            reader.Open(input);
            writer.Open(output, reader.Width, reader.Height);
            ResetWriteByte();

            HideHeader();
        }
コード例 #31
0
        static void Main(string[] args)
        {
            foreach (FilterInfo videoDevice in new FilterInfoCollection(FilterCategory.VideoInputDevice))
            {
                Console.WriteLine(videoDevice.Name);
            }

            FilterInfo codec = null;

            foreach (FilterInfo videoDevice in new FilterInfoCollection(FilterCategory.VideoCompressorCategory))
            {
                codec = videoDevice;
                Console.WriteLine(videoDevice.Name);
            }

            // instantiate AVI writer, use WMV3 codec
            AVIWriter writer = new AVIWriter(codec.MonikerString);

            // create new AVI file and open it
            writer.Open("test.avi", 320, 240);
            // create frame image
            Bitmap image = new Bitmap(320, 240);

            int j = 1;

            for (int i = 0; i < 240; i++)
            {
                // update image
                image.SetPixel(i, i, Color.Red);
                // add the image as a new frame of video file
                writer.AddFrame(image);

                j = j == 1 ? -1 : 1;
            }

            //Bitmap bitmap = Image.FromFile("Files/grab.mjpeg");
            //writer.AddFrame(bitmap);



            writer.Close();
        }
コード例 #32
0
ファイル: AVICache.cs プロジェクト: petronas/ShareX
 public AVICache(ScreencastOptions options)
 {
     Options = options;
     Helpers.CreateDirectoryIfNotExist(Options.OutputPath);
     aviWriter = new AVIWriter(options);
 }
コード例 #33
0
ファイル: AVICache.cs プロジェクト: TreeSeed/ShareX
        private void StartConsumerThread()
        {
            if (!IsWorking)
            {
                IsWorking = true;

                Helpers.CreateDirectoryIfNotExist(OutputPath);

                AVIWriter aviWriter = new AVIWriter(OutputPath, FPS, Size.Width, Size.Height, ShowOptions);

                task = TaskEx.Run(() =>
                {
                    try
                    {
                        position = 0;

                        while (!imageQueue.IsCompleted)
                        {
                            Image img = null;

                            try
                            {
                                img = imageQueue.Take();

                                if (img != null)
                                {
                                    //img.Save("Test\\" + position + ".bmp", ImageFormat.Bmp);
                                    aviWriter.AddFrame((Bitmap)img);
                                    position++;
                                }
                            }
                            catch (InvalidOperationException)
                            {
                            }
                            finally
                            {
                                if (img != null) img.Dispose();
                            }
                        }
                    }
                    finally
                    {
                        IsWorking = false;

                        if (aviWriter != null)
                        {
                            aviWriter.Dispose();
                        }
                    }
                });
            }
        }
コード例 #34
0
        public void Start(int framesPerSecond)
        {
            string filename;
            if (recordingWindow != null) {
                string windowTitle = Regex.Replace(recordingWindow.Text, @"[^\x20\d\w]", "");
                if (string.IsNullOrEmpty(windowTitle)) {
                    windowTitle = "greenshot-recording";
                }
                filename = Path.Combine(conf.OutputFilePath, windowTitle + ".avi");

            } else {
                filename = Path.Combine(conf.OutputFilePath, "greenshot-recording.avi");
            }
            if (File.Exists(filename)) {
                try {
                    File.Delete(filename);
                } catch {}
            }
            LOG.InfoFormat("Capturing to {0}", filename);

            if (recordingWindow != null) {
                LOG.InfoFormat("Starting recording Window '{0}', {1}", recordingWindow.Text, recordingWindow.ClientRectangle);
                recordingSize = recordingWindow.ClientRectangle.Size;
            } else {
                LOG.InfoFormat("Starting recording rectangle {0}", recordingRectangle);
                recordingSize = recordingRectangle.Size;
            }
            if (recordingSize.Width % 8 > 0) {
                LOG.InfoFormat("Correcting width to be factor 8, {0} => {1}", recordingSize.Width, recordingSize.Width + (8-(recordingSize.Width % 8)));
                recordingSize = new Size(recordingSize.Width + (8-(recordingSize.Width % 8)), recordingSize.Height);
            }
            if (recordingSize.Height % 8 > 0) {
                LOG.InfoFormat("Correcting Height to be factor 8, {0} => {1}", recordingSize.Height, recordingSize.Height + (8-(recordingSize.Height % 8)));
                recordingSize = new Size(recordingSize.Width, recordingSize.Height + (8-(recordingSize.Height % 8)));
            }
            this.framesPerSecond = framesPerSecond;
            // "P/Invoke" Solution for capturing the screen
            hWndDesktop = User32.GetDesktopWindow();
            // get te hDC of the target window
            hDCDesktop = User32.GetWindowDC(hWndDesktop);
            // Make sure the last error is set to 0
            Win32.SetLastError(0);

            // create a device context we can copy to
            hDCDest = GDI32.CreateCompatibleDC(hDCDesktop);
            // Check if the device context is there, if not throw an error with as much info as possible!
            if (hDCDest == IntPtr.Zero) {
                // Get Exception before the error is lost
                Exception exceptionToThrow = CreateCaptureException("CreateCompatibleDC", recordingSize);
                // Cleanup
                User32.ReleaseDC(hWndDesktop, hDCDesktop);
                // throw exception
                throw exceptionToThrow;
            }

            // Create BitmapInfoHeader for CreateDIBSection
            BitmapInfoHeader bitmapInfoHeader = new BitmapInfoHeader(recordingSize.Width, recordingSize.Height, 32);

            // Make sure the last error is set to 0
            Win32.SetLastError(0);

            // create a bitmap we can copy it to, using GetDeviceCaps to get the width/height
            hDIBSection = GDI32.CreateDIBSection(hDCDesktop, ref bitmapInfoHeader, BitmapInfoHeader.DIB_RGB_COLORS, out bits0, IntPtr.Zero, 0);

            if (hDIBSection == IntPtr.Zero) {
                // Get Exception before the error is lost
                Exception exceptionToThrow = CreateCaptureException("CreateDIBSection", recordingSize);
                exceptionToThrow.Data.Add("hdcDest", hDCDest.ToInt32());
                exceptionToThrow.Data.Add("hdcSrc", hDCDesktop.ToInt32());

                // clean up
                GDI32.DeleteDC(hDCDest);
                User32.ReleaseDC(hWndDesktop, hDCDesktop);

                // Throw so people can report the problem
                throw exceptionToThrow;
            }
            // Create a GDI Bitmap so we can use GDI and GDI+ operations on the same memory
            GDIBitmap = new Bitmap(recordingSize.Width, recordingSize.Height, 32, PixelFormat.Format32bppArgb, bits0);
            // select the bitmap object and store the old handle
            hOldObject = GDI32.SelectObject(hDCDest, hDIBSection);
            stop = false;

            aviWriter = new AVIWriter();
            // Comment the following 2 lines to make the user select it's own codec
            //aviWriter.Codec = "msvc";
            //aviWriter.Quality = 99;

            aviWriter.FrameRate = framesPerSecond;
            aviWriter.Open(filename, recordingSize.Width, recordingSize.Height);

            // Start update check in the background
            backgroundTask = new Thread (new ThreadStart(CaptureFrame));
            backgroundTask.IsBackground = true;
            backgroundTask.Start();
        }
コード例 #35
0
 /// <summary>
 ///  Free resources
 /// </summary>
 private void Cleanup()
 {
     if (hOldObject != IntPtr.Zero && hDCDest != IntPtr.Zero) {
         // restore selection (old handle)
         GDI32.SelectObject(hDCDest, hOldObject);
         GDI32.DeleteDC(hDCDest);
     }
     if (hDCDesktop != IntPtr.Zero) {
         User32.ReleaseDC(hWndDesktop, hDCDesktop);
     }
     if (hDIBSection != IntPtr.Zero) {
         // free up the Bitmap object
         GDI32.DeleteObject(hDIBSection);
     }
     if (aviWriter != null) {
         aviWriter.Dispose();
         aviWriter = null;
     }
 }