Class VideoFrameReader
- Namespace
- SharpConsoleUI.Video
- Assembly
- SharpConsoleUI.dll
Reads video frames as raw RGB24 byte arrays by piping from an FFmpeg subprocess. Each frame is width * height * 3 bytes (R, G, B per pixel, row-major).
public sealed class VideoFrameReader : IDisposable
- Inheritance
-
VideoFrameReader
- Implements
- Inherited Members
- Extension Methods
Properties
DurationSeconds
Video duration in seconds, or 0 if unknown.
public double DurationSeconds { get; }
Property Value
Fps
Video frame rate.
public double Fps { get; }
Property Value
FrameSize
Bytes per frame (Width * Height * 3).
public int FrameSize { get; }
Property Value
Height
Video height in pixels.
public int Height { get; }
Property Value
Width
Video width in pixels.
public int Width { get; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
IsFfmpegAvailable()
Checks if the FFmpeg executable is available on the system PATH.
public static bool IsFfmpegAvailable()
Returns
Open(string, int, int, double)
Opens a video source and starts the FFmpeg decode process. Accepts any source FFmpeg understands: local file paths, HTTP/HTTPS URLs, RTSP streams, HLS playlists (m3u8), RTMP, FTP, or any other FFmpeg-supported protocol. Probes metadata first, then launches the raw frame pipe.
public static VideoFrameReader Open(string source, int targetWidth, int targetHeight, double startTime = 0)
Parameters
sourcestringFile path or URL. Anything FFmpeg's -i accepts.
targetWidthintTarget output width in pixels. FFmpeg scales to this.
targetHeightintTarget output height in pixels. FFmpeg scales to this.
startTimedoubleOptional start time in seconds for seeking. Ignored for live streams.
Returns
- VideoFrameReader
A VideoFrameReader ready to read frames.
Exceptions
- InvalidOperationException
If FFmpeg is not found or fails to start.
ReadFrame(byte[])
Reads the next frame into the provided buffer.
public bool ReadFrame(byte[] buffer)
Parameters
bufferbyte[]Must be at least FrameSize bytes.
Returns
- bool
True if a full frame was read; false if end-of-stream.
ReadFrameAsync(byte[], CancellationToken)
Reads the next frame into the provided buffer asynchronously.
public Task<bool> ReadFrameAsync(byte[] buffer, CancellationToken ct = default)
Parameters
bufferbyte[]Must be at least FrameSize bytes.
ctCancellationTokenCancellation token.