Show / Hide Table of Contents

Class SKVideo

Provides asynchronous video playback for SkiaSharp applications. This class has no audio support. Use FFmpeg.MediaPlayer.PlaybackEngine.

Inheritance
object
SKVideo
Implements
IDisposable
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
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 Source

SKVideo(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

io or codecOptions is null.

ArgumentException

No suitable video stream was found, or info specifies an unsupported SKColorType.

FFmpegException

The media could not be opened.

View Source

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

io or codecOptions is null.

ArgumentException

No suitable video stream was found, or info specifies an unsupported SKColorType.

FFmpegException

The media could not be opened.

View Source

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

io or codecOptions is null.

ArgumentException

No suitable video stream was found, or info specifies an unsupported SKColorType.

FFmpegException

The media could not be opened.

View Source

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

io or codecOptions is null.

ArgumentException

No suitable video stream was found, or info specifies an unsupported SKColorType.

FFmpegException

The media could not be opened.

View Source

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.

View Source

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

stream or codecOptions is null.

ArgumentException

No suitable video stream was found, or info specifies an unsupported SKColorType.

FFmpegException

The media could not be opened.

View Source

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

stream or codecOptions is null.

ArgumentException

No suitable video stream was found, or info specifies an unsupported SKColorType.

FFmpegException

The media could not be opened.

View Source

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

stream or codecOptions is null.

ArgumentException

No suitable video stream was found, or info specifies an unsupported SKColorType.

FFmpegException

The media could not be opened.

View Source

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

stream or codecOptions is null.

ArgumentException

No suitable video stream was found, or info specifies an unsupported SKColorType.

FFmpegException

The media could not be opened.

View Source

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.

View Source

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
View Source

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.

View Source

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 Source

CurrentFrameInfo

Gets timing information for the most recently decoded frame.

Declaration
public FFCodecFrameInfo CurrentFrameInfo { get; }
Property Value
Type Description
FFCodecFrameInfo
View Source

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
View Source

Disposed

Gets whether this instance has been disposed.

Declaration
public bool Disposed { get; }
Property Value
Type Description
bool
View Source

Duration

Gets the duration of the video.

Declaration
public TimeSpan Duration { get; }
Property Value
Type Description
TimeSpan
View Source

FrameRate

Gets the nominal frame rate of the video.

Declaration
public Rational FrameRate { get; }
Property Value
Type Description
Rational
View Source

Frames

Gets the total number of frames in the video stream.

Declaration
public long Frames { get; }
Property Value
Type Description
long
View Source

Info

Gets the image information of decoded video frames.

Declaration
public SKImageInfo Info { get; }
Property Value
Type Description
SKImageInfo
View Source

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?).

View Source

Running

Gets whether the decoding thread is currently running.

Declaration
public bool Running { get; }
Property Value
Type Description
bool
View Source

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 Source

Dispose()

Releases all resources used by the current SKVideo.

Declaration
public void Dispose()
View Source

Dispose(bool)

Releases the resources used by the SKVideo instance.

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
bool disposing

true to release managed resources; otherwise, false.

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.

View Source

Pause()

Pauses playback.

Declaration
public void Pause()
Remarks

Playback can later be resumed by calling Resume().

View Source

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.

View Source

Resume()

Resumes playback after it has been paused.

Declaration
public void Resume()
View Source

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.

View Source

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.

View Source

Start()

Starts playback from the beginning of the video.

Declaration
public void Start()
Remarks

If playback is already running, this method has no effect.

View Source

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 Source

Ended

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.

View Source

Faulted

Occurs when decoding fails. Playback stops.

Declaration
public event EventHandler<Exception>? Faulted
Event Type
Type Description
EventHandler<Exception>
View Source

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.

View Source

Paused

Occurs when playback is paused.

Declaration
public event EventHandler? Paused
Event Type
Type Description
EventHandler
View Source

Resumed

Occurs when playback resumes after being paused.

Declaration
public event EventHandler? Resumed
Event Type
Type Description
EventHandler
View Source

Started

Occurs when playback starts.

Declaration
public event EventHandler? Started
Event Type
Type Description
EventHandler
View Source

Stopped

Occurs when playback stops.

Declaration
public event EventHandler? Stopped
Event Type
Type Description
EventHandler

Implements

IDisposable
  • View Source
In this article
Back to top Generated by DocFX