/// <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)) { using (Frame) { Frame.CopyTo(_videoBuffer, _videoBuffer.Length); } } _lastFrameTask = _ffmpegIn.WriteAsync(_videoBuffer, 0, _videoBuffer.Length); }
public void WriteFrame(IBitmapFrame Image) { if (Image is RepeatFrame) { return; } using (Image) { // TODO: Make independent of System.Drawing using (var bmp = new Bitmap(Image.Width, Image.Height)) { var data = bmp.LockBits(new Rectangle(Point.Empty, new Size(Image.Width, Image.Height)), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); try { Image.CopyTo(data.Scan0); } finally { bmp.UnlockBits(data); } var filePath = Path.Combine(_folderPath, $"{_index:D3}.png"); bmp.Save(filePath, ImageFormat.Png); } } ++_index; }
public void WriteFrame(IBitmapFrame Image) { if (Image is RepeatFrame) { return; } using (Image) { // HACK: Don't know why, this fixes Preview showing multiple mouse pointers Image.CopyTo(_dummyBuffer, _dummyBuffer.Length); } }
/// <summary> /// Writes an Image frame. /// </summary> public void WriteFrame(IBitmapFrame Frame) { if (!(Frame is RepeatFrame)) { using (Frame) { Frame.CopyTo(_videoBuffer, _videoBuffer.Length); } } lock (_writer) _videoStream.WriteFrame(true, _videoBuffer, 0, _videoBuffer.Length); }
/// <summary> /// Writes an Image frame. /// </summary> public void WriteFrame(IBitmapFrame frame) { if (!(frame is RepeatFrame)) { using (frame) { frame.CopyTo(_videoBuffer, _videoBuffer.Length); } } lock (_syncLock) _videoStream.WriteFrame(true, _videoBuffer, 0, _videoBuffer.Length); }
/// <summary> /// Writes an Image frame. /// </summary> public void WriteFrame(IBitmapFrame Frame) { if (!(Frame is RepeatFrame)) { using (Frame) { Frame.CopyTo(_videoBuffer); } } lock (_syncLock) { _connection.WriteFrame(_videoBuffer, _width, _height); } }
/// <summary> /// Writes an Image frame. /// </summary> public void WriteFrame(IBitmapFrame Frame) { if (_ffmpegProcess.HasExited) { Frame.Dispose(); throw new FFmpegException(_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)) { using (Frame) { if (Frame.Unwrap() is INV12Frame nv12Frame) { nv12Frame.CopyNV12To(_videoBuffer); } else { Frame.CopyTo(_videoBuffer); } } } try { _lastFrameTask = _ffmpegIn.WriteAsync(_videoBuffer, 0, _videoBuffer.Length); } catch (Exception e) when(_ffmpegProcess.HasExited) { throw new FFmpegException(_ffmpegProcess.ExitCode, e); } }
/// <summary> /// Writes an Image frame. /// </summary> public void WriteFrame(IBitmapFrame Frame) { if (!(Frame is RepeatFrame)) { using (Frame) { Frame.CopyTo(_videoBuffer); } } lock (_syncLock) { if (IsTransparentOrTruncatedFrame(_videoBuffer)) { // To avoid dropped frames, just repeat the previous one if (_hasOneGoodFrame) { // Use previous frame instead _videoStream.WriteFrame(true, _prevVideoBuffer, 0, _prevVideoBuffer.Length); } else { // Just need to make do with what we have _videoStream.WriteFrame(true, _videoBuffer, 0, _videoBuffer.Length); } return; } if (!_hasOneGoodFrame) { _hasOneGoodFrame = true; } _videoStream.WriteFrame(true, _videoBuffer, 0, _videoBuffer.Length); // Save frame in case we need it as stand-in for next one Buffer.BlockCopy(_videoBuffer, 0, _prevVideoBuffer, 0, _videoBuffer.Length); } }
/// <summary> /// Writes an Image frame. /// </summary> public void WriteFrame(IBitmapFrame Frame) { try { if (_ffmpegProcess.HasExited) { Frame.Dispose(); throw new Exception($"An Error Occurred with FFmpeg, Exit Code: {_ffmpegProcess.ExitCode}"); } if (_firstFrame) { if (!_ffmpegIn.WaitForConnection(waitTimeForPipeConnection)) { throw new Exception("Cannot connect Video pipe to FFmpeg"); } _firstFrame = false; } _lastFrameTask?.Wait(); if (!(Frame is RepeatFrame)) { using (Frame) { Frame.CopyTo(_videoBuffer, _videoBuffer.Length); } } _lastFrameTask = _ffmpegIn.WriteAsync(_videoBuffer, 0, _videoBuffer.Length); if (framesToBeWritten != null) { framesToBeWritten.Enqueue(_videoBuffer); } } catch (Exception e) { WriteLog("WriteFrame() - " + e.Message + " - " + e.StackTrace); throw e; } }
/// <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); }
public void Display(IBitmapFrame Frame) { if (Frame is RepeatFrame) { return; } if (!_visible || DateTime.Now - _timestamp < _minInterval) { Frame.Dispose(); return; } _timestamp = DateTime.Now; using (Frame) Frame.CopyTo(_buffer, _buffer.Length); _previewWindow.Dispatcher.Invoke(() => { _writeableBitmap.WritePixels(new Int32Rect(0, 0, Frame.Width, Frame.Height), _buffer, Frame.Width * 4, 0); }); }
/// <summary> /// Writes an Image frame. /// </summary> public void WriteFrame(IBitmapFrame Frame) { if (_ffmpegProcess.HasExited) { Frame.Dispose(); throw new FFmpegException(_ffmpegProcess.ExitCode); } if (_firstFrame) { if (!_ffmpegIn.WaitForConnection(5000)) { throw new Exception("Cannot connect Video pipe to FFmpeg"); } _firstFrame = false; } if (_lastFrameTask == null) { _lastFrameTask = Task.CompletedTask; } if (!(Frame is RepeatFrame)) { using (Frame) { if (Frame.Unwrap() is INV12Frame nv12Frame) { nv12Frame.CopyNV12To(_videoBuffer); } else { Frame.CopyTo(_videoBuffer); } } } // Drop frames if semaphore cannot be acquired soon enough. // Frames are dropped mostly in the beginning of recording till atleast one audio frame is received. if (!_spVideo.Wait(_spTimeout)) { ++_skippedFrames; _frameStreak = 0; return; } // Most of the drops happen in beginning of video, once that stops, sync can be done. if (!_initialStability) { ++_frameStreak; if (_frameStreak > FrameStreakThreshold) { _initialStability = true; } } try { // Check if last write failed. if (_lastFrameTask != null && _lastFrameTask.IsFaulted) { _lastFrameTask.Wait(); } _lastFrameTask = _lastFrameTask.ContinueWith(async M => { try { await _ffmpegIn.WriteAsync(_videoBuffer, 0, _videoBuffer.Length); } finally { _spVideo.Release(); } }); } catch (Exception e) when(_ffmpegProcess.HasExited) { throw new FFmpegException(_ffmpegProcess.ExitCode, e); } }
public void CopyTo(byte[] Buffer, int Length) { _frame.CopyTo(Buffer, Length); }