コード例 #1
0
ファイル: FFmpegVideoWriter.cs プロジェクト: kahmed10/Captura
        /// <summary>
        /// Writes an Image frame.
        /// </summary>
        public void WriteFrame(IBitmapFrame Frame)
        {
            if (_ffmpegProcess.HasExited)
            {
                Frame.Dispose();
                throw new Exception($"An Error Occurred with FFmpeg, Exit Code: {_ffmpegProcess.ExitCode}");
            }

            if (_firstFrame)
            {
                if (!_ffmpegIn.WaitForConnection(5000))
                {
                    throw new Exception("Cannot connect Video pipe to FFmpeg");
                }

                _firstFrame = false;
            }

            _lastFrameTask?.Wait();

            if (Frame is RepeatFrame)
            {
                ++_framesSkipped;
                return;
            }
            _keyVector.WriteKeyOutputFile();
            ++frameCount;
            using (Frame)
            {
                Frame.CopyTo(_videoBuffer, _videoBuffer.Length);
            }

            //Debug.Print(frameCount.ToString());

            _lastFrameTask = _ffmpegIn.WriteAsync(_videoBuffer, 0, _videoBuffer.Length);
        }