Class IOContext
Represents a custom FFmpeg I/O context backed by managed code.
Inherited Members
Namespace: FFmpeg.IO
Assembly: FFmpeg.dll
Syntax
public abstract class IOContext : AVIOContext, IDisposable, IAVPointer<_AVIOContext>
Remarks
IOContext provides the callback implementations used by
FFmpeg's AVIOContext, allowing media data to be read from or written
to arbitrary managed sources such as Stream instances,
memory buffers, network transports, or custom storage.
Constructors
View SourceIOContext()
Initializes a new IOContext
Declaration
public IOContext()
IOContext(FormatContext, IOOptions, int)
Initializes a new IOContext and attaches it to the specified format context.
Declaration
protected IOContext(FormatContext formatContext, IOOptions options, int buffer_size = 32768)
Parameters
| Type | Name | Description |
|---|---|---|
| FormatContext | formatContext | The FormatContext to associate with this I/O context. |
| IOOptions | options | The I/O operations that this context will support, such as reading, writing, and seeking. |
| int | buffer_size | The size of the buffer to allocate for I/O operations. Defaults to 32,768 bytes. |
Properties
View SourceCanSeek
Gets a value indicating whether this I/O context supports seeking.
Declaration
public abstract bool CanSeek { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
If this property returns false, FFmpeg treats the stream as non-seekable.
FormatContext
Gets the FormatContext associated with this I/O context.
Declaration
public FormatContext FormatContext { get; }
Property Value
| Type | Description |
|---|---|
| FormatContext |
Remarks
This property is assigned when the I/O context is attached to a format context and remains valid until the context is disposed.
Seekable
Gets or sets the types of seeking supported by the underlying I/O context.
Declaration
public Seekable Seekable { get; protected set; }
Property Value
| Type | Description |
|---|---|
| Seekable |
Remarks
The value indicates which seeking operations are supported by the underlying AVIOContext. Derived classes can modify this value when creating or configuring a custom I/O context.
Methods
View SourceDispose(bool)
Releases the unmanaged resources used by the IOContext and optionally releases the managed resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | disposing | true to release both managed and unmanaged resources; false to release only unmanaged resources. |
Overrides
View Source~IOContext()
Declaration
protected ~IOContext()
InitContext(FormatContext, IOOptions, int)
Attaches this I/O context to the specified format context.
Declaration
public void InitContext(FormatContext formatContext, IOOptions options, int buffer_size = 32768)
Parameters
| Type | Name | Description |
|---|---|---|
| FormatContext | formatContext | The format context that will use this custom I/O implementation. |
| IOOptions | options | Specifies which callback operations should be enabled. |
| int | buffer_size | The size, in bytes, of the internal FFmpeg I/O buffer. |
Remarks
This method allocates a native AVIOContext and installs the managed
callback functions required by FFmpeg.
ReadPacket(Span<byte>)
Reads data into the provided buffer.
Declaration
protected abstract AVResult32 ReadPacket(Span<byte> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<byte> | buffer | The buffer to read data into. |
Returns
| Type | Description |
|---|---|
| AVResult32 | The number of bytes read, zero to indicate end-of-file, or a negative FFmpeg error code. |
Seek(long, AVSeek)
Seeks to the specified offset in the stream.
Declaration
protected abstract AVResult64 Seek(long offset, AVSeek whence)
Parameters
| Type | Name | Description |
|---|---|---|
| long | offset | The offset to seek to. |
| AVSeek | whence | The seek mode (e.g., from the start, from the current position, etc.). |
Returns
| Type | Description |
|---|---|
| AVResult64 | The new position within the stream, or a negative value on error. |
Remarks
View SourceWritePacket(Span<byte>)
Writes data from the provided buffer into the stream.
Declaration
protected abstract AVResult32 WritePacket(Span<byte> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<byte> | buffer | The buffer containing the data to write. |
Returns
| Type | Description |
|---|---|
| AVResult32 | The number of bytes written, or a negative value on error. |