Class SKVideo
Provides asynchronous video playback for SkiaSharp applications. This class has no audio support. Use FFmpeg.MediaPlayer.PlaybackEngine.
Implements
Inherited Members
Namespace: FFmpeg.Skia
Assembly: FFmpeg.Skia.dll
Syntax
public class SKVideo : IDisposable
Remarks
SKVideo decodes video frames using FFCodec2Skia on a background thread and raises FrameReadyToRender whenever a new frame should be displayed.
Decoded frames are reused internally to minimize memory allocations. Applications must not dispose or retain the SKBitmap instances provided by FrameReadyToRender, as ownership remains with the SKVideo instance.
This class performs video decoding only. It does not decode audio or provide audio/video synchronization.
Constructors
View SourceSKVideo(IOContext)
Initializes a new SKVideo instance that decodes video frames from the specified FFmpeg.IO.IOContext using the requested output image format and codec options.
Declaration
public SKVideo(IOContext io)
Parameters
| Type | Name | Description |
|---|---|---|
| IOContext | io | The custom FFmpeg I/O context used to read the media. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException | No suitable video stream was found, or
|
| FFmpegException | The media could not be opened. |
SKVideo(IOContext, SKImageInfo)
Initializes a new SKVideo instance that decodes video frames from the specified FFmpeg.IO.IOContext using the requested output image format and codec options.
Declaration
public SKVideo(IOContext io, SKImageInfo info)
Parameters
| Type | Name | Description |
|---|---|---|
| IOContext | io | The custom FFmpeg I/O context used to read the media. |
| SKImageInfo | info | The desired output image information. The decoded frames are converted to the specified dimensions and SKColorType when necessary. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException | No suitable video stream was found, or
|
| FFmpegException | The media could not be opened. |
SKVideo(IOContext, SKImageInfo, IDictionary<string, string>)
Initializes a new SKVideo instance that decodes video frames from the specified FFmpeg.IO.IOContext using the requested output image format and codec options.
Declaration
public SKVideo(IOContext io, SKImageInfo info, IDictionary<string, string> codecOptions)
Parameters
| Type | Name | Description |
|---|---|---|
| IOContext | io | The custom FFmpeg I/O context used to read the media. |
| SKImageInfo | info | The desired output image information. The decoded frames are converted to the specified dimensions and SKColorType when necessary. |
| IDictionary<string, string> | codecOptions | A collection of codec and format options passed to FFmpeg when opening the media source. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException | No suitable video stream was found, or
|
| FFmpegException | The media could not be opened. |
SKVideo(IOContext, IDictionary<string, string>)
Initializes a new SKVideo instance that decodes video frames from the specified FFmpeg.IO.IOContext using the requested output image format and codec options.
Declaration
public SKVideo(IOContext io, IDictionary<string, string> codecOptions)
Parameters
| Type | Name | Description |
|---|---|---|
| IOContext | io | The custom FFmpeg I/O context used to read the media. |
| IDictionary<string, string> | codecOptions | A collection of codec and format options passed to FFmpeg when opening the media source. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException | No suitable video stream was found, or
|
| FFmpegException | The media could not be opened. |
SKVideo(FFCodec2Skia)
Provides asynchronous video playback for SkiaSharp applications. This class has no audio support. Use FFmpeg.MediaPlayer.PlaybackEngine.
Declaration
public SKVideo(FFCodec2Skia video)
Parameters
| Type | Name | Description |
|---|---|---|
| FFCodec2Skia | video |
Remarks
SKVideo decodes video frames using FFCodec2Skia on a background thread and raises FrameReadyToRender whenever a new frame should be displayed.
Decoded frames are reused internally to minimize memory allocations. Applications must not dispose or retain the SKBitmap instances provided by FrameReadyToRender, as ownership remains with the SKVideo instance.
This class performs video decoding only. It does not decode audio or provide audio/video synchronization.
SKVideo(Stream)
Initializes a new SKVideo instance that decodes video frames from the specified Stream using the requested output image format and codec options.
Declaration
public SKVideo(Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The input stream containing the media to decode. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException | No suitable video stream was found, or
|
| FFmpegException | The media could not be opened. |
SKVideo(Stream, DeviceType)
Initializes a new SKVideo instance that decodes video frames from the specified Stream using the requested output image format and codec options.
Declaration
public SKVideo(Stream stream, DeviceType deviceType)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The input stream containing the media to decode. |
| DeviceType | deviceType |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException | No suitable video stream was found, or
|
| FFmpegException | The media could not be opened. |
SKVideo(Stream, SKImageInfo)
Initializes a new SKVideo instance that decodes video frames from the specified Stream using the requested output image format and codec options.
Declaration
public SKVideo(Stream stream, SKImageInfo info)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The input stream containing the media to decode. |
| SKImageInfo | info | The desired output image information. The decoded frames are converted to the specified dimensions and SKColorType when necessary. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException | No suitable video stream was found, or
|
| FFmpegException | The media could not be opened. |
SKVideo(Stream, SKImageInfo, IDictionary<string, string>)
Initializes a new SKVideo instance that decodes video frames from the specified Stream using the requested output image format and codec options.
Declaration
public SKVideo(Stream stream, SKImageInfo info, IDictionary<string, string> codecOptions)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The input stream containing the media to decode. |
| SKImageInfo | info | The desired output image information. The decoded frames are converted to the specified dimensions and SKColorType when necessary. |
| IDictionary<string, string> | codecOptions | A collection of codec and format options passed to FFmpeg when opening the media source. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException | No suitable video stream was found, or
|
| FFmpegException | The media could not be opened. |
SKVideo(string)
Opens a video from the specified path or URL using the specified decoding options.
Declaration
public SKVideo(string url)
Parameters
| Type | Name | Description |
|---|---|---|
| string | url | The path or URL of the video. |
SKVideo(string, DeviceType)
Opens a video from the specified path or URL using the specified decoding options.
Declaration
public SKVideo(string url, DeviceType deviceType)
Parameters
| Type | Name | Description |
|---|---|---|
| string | url | The path or URL of the video. |
| DeviceType | deviceType |
SKVideo(string, SKImageInfo)
Opens a video from the specified path or URL using the specified decoding options.
Declaration
public SKVideo(string url, SKImageInfo info)
Parameters
| Type | Name | Description |
|---|---|---|
| string | url | The path or URL of the video. |
| SKImageInfo | info | Specifies the dimensions and color type of decoded frames. |
SKVideo(string, SKImageInfo, IDictionary<string, string>)
Opens a video from the specified path or URL using the specified decoding options.
Declaration
public SKVideo(string url, SKImageInfo info, IDictionary<string, string> codecOptions)
Parameters
| Type | Name | Description |
|---|---|---|
| string | url | The path or URL of the video. |
| SKImageInfo | info | Specifies the dimensions and color type of decoded frames. |
| IDictionary<string, string> | codecOptions | A collection of codec and format options passed to FFmpeg. |
Properties
View SourceCurrentFrameInfo
Gets timing information for the most recently decoded frame.
Declaration
public FFCodecFrameInfo CurrentFrameInfo { get; }
Property Value
| Type | Description |
|---|---|
| FFCodecFrameInfo |
DisplaySize
Gets the size of the decoded images (Info) as displayed, i.e. with Rotation applied (width and height are swapped for 90 and 270 degrees).
Declaration
public SKSizeI DisplaySize { get; }
Property Value
| Type | Description |
|---|---|
| SKSizeI |
Disposed
Gets whether this instance has been disposed.
Declaration
public bool Disposed { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Duration
Gets the duration of the video.
Declaration
public TimeSpan Duration { get; }
Property Value
| Type | Description |
|---|---|
| TimeSpan |
FrameRate
Gets the nominal frame rate of the video.
Declaration
public Rational FrameRate { get; }
Property Value
| Type | Description |
|---|---|
| Rational |
Frames
Gets the total number of frames in the video stream.
Declaration
public long Frames { get; }
Property Value
| Type | Description |
|---|---|
| long |
Info
Gets the image information of decoded video frames.
Declaration
public SKImageInfo Info { get; }
Property Value
| Type | Description |
|---|---|
| SKImageInfo |
Rotation
Gets the clockwise rotation in degrees (0, 90, 180 or 270) the video must be displayed with, from the stream's display matrix (e.g. a video recorded with a phone held upright).
Declaration
public int Rotation { get; }
Property Value
| Type | Description |
|---|---|
| int |
Remarks
The decoded images are not rotated; draw them with DrawRotated(SKCanvas, SKBitmap, SKRect, int, SKSamplingOptions, SKPaint?).
Running
Gets whether the decoding thread is currently running.
Declaration
public bool Running { get; }
Property Value
| Type | Description |
|---|---|
| bool |
SampleAspectRatio
Gets the sample (pixel) aspect ratio of the video; 1:1 for square pixels.
Declaration
public Rational SampleAspectRatio { get; }
Property Value
| Type | Description |
|---|---|
| Rational |
Remarks
If no width was requested, Info already has the width of square pixels (e.g. 720x480 with 32:27 is decoded as 853x480).
Methods
View SourceDispose()
Releases all resources used by the current SKVideo.
Declaration
public void Dispose()
Dispose(bool)
Releases the resources used by the SKVideo instance.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | disposing |
Remarks
When disposing, playback is stopped and the decoder is released once the decoding thread has finished. The frame buffers are released once a running FrameReadyToRender handler has returned. Dispose may be called from any thread, including event handlers.
Pause()
Pauses playback.
Declaration
public void Pause()
Remarks
Playback can later be resumed by calling Resume().
Restart()
Restarts playback from the beginning of the video.
Declaration
public void Restart()
Remarks
If playback is running, it continues from the beginning; otherwise it is started.
Resume()
Resumes playback after it has been paused.
Declaration
public void Resume()
Seek(long)
Seeks to the specified frame number.
Declaration
public AVResult32 Seek(long frameIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| long | frameIndex | The zero-based frame index. |
Returns
| Type | Description |
|---|---|
| AVResult32 | An FFmpeg.Utils.AVResult32 indicating whether the seek operation succeeded. |
Remarks
See Seek(long). Seeking from an Ended handler continues playback from the new position.
Seek(TimeSpan)
Seeks to the specified playback position.
Declaration
public AVResult32 Seek(TimeSpan timeSpan)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeSpan | The position to seek to. |
Returns
| Type | Description |
|---|---|
| AVResult32 | An FFmpeg.Utils.AVResult32 indicating whether the seek operation succeeded. |
Remarks
Seeking from an Ended handler continues playback from the new position.
Start()
Starts playback from the beginning of the video.
Declaration
public void Start()
Remarks
If playback is already running, this method has no effect.
Stop()
Stops playback.
Declaration
public void Stop()
Remarks
Stopped is raised once the decoding thread has finished. Use Start() or Restart() to begin playback again.
Events
View SourceEnded
Occurs when playback reaches the end of the video.
Declaration
public event EventHandler? Ended
Event Type
| Type | Description |
|---|---|
| EventHandler |
Remarks
The event is raised on a thread-pool thread. If a handler seeks (Seek(TimeSpan), Seek(long) or Restart()), playback continues from the new position, e.g. to loop.
Faulted
Occurs when decoding fails. Playback stops.
Declaration
public event EventHandler<Exception>? Faulted
Event Type
| Type | Description |
|---|---|
| EventHandler<Exception> |
FrameReadyToRender
Occurs when the next video frame is ready to be rendered.
Declaration
public event EventHandler<(SKBitmap frame, FFCodecFrameInfo frameInfo)>? FrameReadyToRender
Event Type
| Type | Description |
|---|---|
| EventHandler<(SKBitmap frame, FFCodecFrameInfo frameInfo)> |
Remarks
The event is raised on a thread-pool thread. While a handler runs, newer frames are skipped. The supplied SKBitmap is owned and reused by the SKVideo instance. Event handlers must not dispose it or retain a reference after the event returns. Clone the bitmap if it needs to be stored.
Paused
Occurs when playback is paused.
Declaration
public event EventHandler? Paused
Event Type
| Type | Description |
|---|---|
| EventHandler |
Resumed
Occurs when playback resumes after being paused.
Declaration
public event EventHandler? Resumed
Event Type
| Type | Description |
|---|---|
| EventHandler |
Started
Occurs when playback starts.
Declaration
public event EventHandler? Started
Event Type
| Type | Description |
|---|---|
| EventHandler |
Stopped
Occurs when playback stops.
Declaration
public event EventHandler? Stopped
Event Type
| Type | Description |
|---|---|
| EventHandler |