Ejemplo n.º 1
0
        public void SaveAvi(string input_wav_filename, string output_avi_filename, double start_time, double end_time,
                            int dest_width, int dest_height, bool is_compress, RunningDelegate dlg)
        {
            int f_rate = frame_rate_ / 256;

            VfwAviWriter avi_writer = new VfwAviWriter(output_avi_filename, frame_rate_ / 256, 1);

            bool is_success = false;

            try
            {
                int start_frame = (start_time >= 0.0 ? (int)(start_time * f_rate) : 0);
                int end_frame   = (end_time >= 0.0 ? (int)(Math.Ceiling(end_time * f_rate)) : frame_count_) - 1;
                if (end_frame >= frame_count_)
                {
                    end_frame = frame_count_ - 1;
                }

                for (int i = start_frame; i <= end_frame; ++i)
                {
                    Bitmap bitmap = GetFrame(i, dest_width, dest_height);
                    avi_writer.AddFrame(bitmap);
                    bitmap.Dispose();
                }
                if (input_wav_filename != "")
                {
                    avi_writer.AddWave(input_wav_filename);
                }
                is_success = true;
            }
            finally
            {
                avi_writer.Close();
                if (!is_success)
                {
                    if (File.Exists(output_avi_filename))
                    {
                        try
                        {
                            File.Delete(output_avi_filename);
                        }
                        catch (Exception) { }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void RecThread()
        {
            bool is_first_time = true;

            AppendInfo("録画待機\r\n");
            int last_reced_frame = -1;
            int start            = System.Environment.TickCount + (int)(start_sec_ * 1000.0);
            int counter          = 0;

            using (Bitmap temp_bmp = new Bitmap(swf_width_, swf_height_))
                using (Graphics temp_graphics = Graphics.FromImage(temp_bmp))
                {
                    while (true)
                    {
                        if (is_stopping_)
                        {
                            AppendInfo("録画を中止しました\r\n");
                            SetStartButtonText("スタート");
                            main_form_.SetTitle(old_title_);
                            is_rec_      = false;
                            is_stopping_ = false;
                            return;
                        }
                        int time = Environment.TickCount - start;
                        if (is_first_time) // start_sec_ 秒だけ飛ばす
                        {
                            if (time >= 0)
                            {
                                is_first_time = false;
                                AppendInfo("録画開始\r\n");
                            }
                            else
                            {
                                continue;
                            }
                        }
                        if (time * frame_rate_ >= (last_reced_frame + 1) * 1000.0)
                        {
                            if (time >= duration_ * 1000) // duration_ 秒を超えると終了
                            {
                                break;
                            }
                            if (time > counter)
                            {
                                AppendInfo(".");
                                counter += 1000;
                            }

                            int frame = (int)(time * frame_rate_ / 1000.0);
                            temp_graphics.CopyFromScreen(flash_left_top_, new Point(0, 0), new Size(swf_width_, swf_height_));
                            Bitmap bmp = new Bitmap(output_width_, output_height_, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                            using (Graphics g = Graphics.FromImage(bmp))
                            {
                                g.DrawImage(temp_bmp, new Rectangle(0, 0, output_width_, output_height_), new Rectangle(0, 0, swf_width_, swf_height_), GraphicsUnit.Pixel);
                            }
                            while (frame - last_reced_frame > 1)
                            {
                                bmp_list_.Add(null); // コマ落ち
                                ++last_reced_frame;
                            }
                            bmp_list_.Add(bmp);
                            last_reced_frame = frame;
                            if (frame >= end_frame_ - 1)
                            {
                                break;
                            }
                        }
                        Thread.Sleep(1);
                    }
                }
            is_stopping_ = false;
            AppendInfo("\r\nファイルに保存しています\r\n");
            VfwAviWriter avi_writer = new VfwAviWriter(output_avi_filename_, (int)frame_rate_, 1);

            int last_pic_index;

            for (last_pic_index = 0; last_pic_index < bmp_list_.Count; ++last_pic_index)
            {
                if (bmp_list_[last_pic_index] != null)
                {
                    break;
                }
            }
            for (int i = last_pic_index; i < bmp_list_.Count; ++i)
            {
                if (bmp_list_[i] != null)
                {
                    avi_writer.AddFrame(bmp_list_[i]);
                    last_pic_index = i;
                }
                else
                {
                    avi_writer.AddFrame(bmp_list_[last_pic_index]);
                }
            }
            avi_writer.Close();

            main_form_.SetTitle(old_title_);
            AppendInfo("保存しました\r\n");
            AppendInfo("終了しました\r\n");
            SetStartButtonText("スタート");
            is_rec_ = false;
        }