Пример #1
0
 private void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     if (vf == null)
     {
         return;
     }
     using (var bp = new System.Drawing.Bitmap(area.Width, area.Height))
         using (var gr = System.Drawing.Graphics.FromImage(bp))
         {
             gr.CopyFromScreen(area.X, area.Y, 0, 0, new System.Drawing.Size(area.Width, area.Height));
             try
             {
                 lock (vf)
                 {
                     if (_firstFrameTime != null)
                     {
                         vf.WriteVideoFrame(bp, DateTime.Now - _firstFrameTime.Value);
                     }
                     else
                     {
                         vf.WriteVideoFrame(bp);
                         _firstFrameTime = DateTime.Now;
                     }
                 }
             }
             catch (Exception)
             {
                 Stop();
                 throw;
             }
         }
 }
Пример #2
0
        private void encode()
        {
            Stopwatch stopwatch = new Stopwatch();

            updateData((float)encodedFrameCount / totalFrameCount,
                       false,
                       stopwatch.Elapsed.TotalSeconds * (totalFrameCount - encodedFrameCount));


            while (true)
            {
                if (imageQueue.Count > 0)
                {
                    stopwatch.Restart();

                    encoder.WriteVideoFrame(imageQueue.Dequeue());
                    encodedFrameCount++;
                    stopwatch.Stop();
                    updateData((float)encodedFrameCount / totalFrameCount,
                               false,
                               stopwatch.Elapsed.TotalSeconds * (totalFrameCount - encodedFrameCount));
                }

                if (lastFrame && imageQueue.Count == 0)
                {
                    finalize();
                    finished = true;
                    break;
                }
            }
        }
Пример #3
0
        private void Screen_NewFrame(object sender, Accord.Video.NewFrameEventArgs eventArgs)
        {
            if (_StartTime == DateTime.MinValue)
            {
                _StartTime = DateTime.Now;
            }
            _ScreenTotalFrames++;
            _Writer.WriteVideoFrame((Bitmap)eventArgs.Frame.Clone(), DateTime.Now - _StartTime);
            presentTime = DateTime.Now;

            if (_MicrophoneSignal != null && (presentTime - oldTime).TotalMilliseconds >= 77 * 2)
            {
                Trace.WriteLine("Time: " + _MicrophoneSignal.Duration.TotalMilliseconds);
                if (_RecordingMicrophone && _MicrophoneSignal != null)
                {
                    _Writer.WriteAudioFrame(_MicrophoneSignal);
                }

                if (_RecordingAudio && _SpeakerSignal != null)
                {
                    Trace.WriteLine("speaker");
                    _Writer.WriteAudioFrame(_SpeakerSignal);
                }
                oldTime = presentTime;
            }
        }
Пример #4
0
        public void thread_msc()
        {
            while (true)
            {
                //Thread.Sleep(1000);
                Thread.Sleep(10);
                for (int i = 0; i < videoOption.bps.Count; i++)
                {
                    VD vd = (VD)videoOption.bps[i];
                    writer.WriteVideoFrame(vd.bitmap, vd.timespan);
                }
                videoOption.bps.RemoveRange(0, videoOption.bps.Count);
                //GC.Collect();

                if (isRecording == false)
                {
                    //GC.Collect();
                    write_finish = true;
                    break;
                }
            }
        }
Пример #5
0
        private static void reencode(FileInfo fileInput, FileInfo fileOutput, VideoCodec outputCodec,
                                     AVPixelFormat format = AVPixelFormat.FormatYuv420P, double expectedFrameRate = 2997 / 100.0)
        {
            using (var videoFileReader = new Accord.Video.FFMPEG.VideoFileReader())
            {
                videoFileReader.Open(fileInput.FullName);

                using (var videoFileWriter = new Accord.Video.FFMPEG.VideoFileWriter())
                {
                    Assert.AreEqual(2997, videoFileReader.FrameRate.Numerator);
                    Assert.AreEqual(100, videoFileReader.FrameRate.Denominator);

                    videoFileWriter.Width      = videoFileReader.Width;
                    videoFileWriter.Height     = videoFileReader.Height;
                    videoFileWriter.FrameRate  = videoFileReader.FrameRate;
                    videoFileWriter.VideoCodec = outputCodec;
                    Assert.AreEqual(AVPixelFormat.FormatYuv420P, videoFileWriter.PixelFormat);
                    videoFileWriter.PixelFormat = format;

                    videoFileWriter.Open(fileOutput.FullName);

                    do
                    {
                        using (var bitmap = videoFileReader.ReadVideoFrame())
                        {
                            if (bitmap == null)
                            {
                                break;
                            }

                            videoFileWriter.WriteVideoFrame(bitmap);
                        }
                    }while (true);

                    videoFileWriter.Close();
                }

                videoFileReader.Close();
            }

            using (var videoFileReader = new Accord.Video.FFMPEG.VideoFileReader())
            {
                videoFileReader.Open(fileOutput.FullName);

                Assert.AreEqual(expectedFrameRate, videoFileReader.FrameRate.Value, 0.01);
            }
        }
Пример #6
0
        private static void reencode(FileInfo fileInput, FileInfo fileOutput, VideoCodec outputCodec)
        {
            using (var videoFileReader = new Accord.Video.FFMPEG.VideoFileReader())
            {
                videoFileReader.Open(fileInput.FullName);

                using (var videoFileWriter = new Accord.Video.FFMPEG.VideoFileWriter())
                {
                    Assert.AreEqual(2997, videoFileReader.FrameRate.Numerator);
                    Assert.AreEqual(100, videoFileReader.FrameRate.Denominator);

                    videoFileWriter.Open
                    (
                        fileOutput.FullName,
                        videoFileReader.Width,
                        videoFileReader.Height,
                        videoFileReader.FrameRate,
                        outputCodec
                    );

                    do
                    {
                        using (var bitmap = videoFileReader.ReadVideoFrame())
                        {
                            if (bitmap == null)
                            {
                                break;
                            }
                            videoFileWriter.WriteVideoFrame(bitmap);
                        }
                    }while (true);

                    videoFileWriter.Close();
                }

                videoFileReader.Close();
            }

            using (var videoFileReader = new Accord.Video.FFMPEG.VideoFileReader())
            {
                videoFileReader.Open(fileOutput.FullName);

                Assert.AreEqual(2997 / 100.0, videoFileReader.FrameRate.Value, 0.01);
            }
        }