Class FormatContext
Inherited Members
Namespace: FFmpeg.Formats
Assembly: FFmpeg.dll
Syntax
public abstract class FormatContext : OptionQueryableBase, IOptionQueryable, ILoggingContext, IDisposable, IAVPointer<_AVFormatContext>
Remarks
FormatContext provides the common functionality shared by demuxing and muxing format contexts. It wraps FFmpeg's native FFmpeg.AutoGen._AVFormatContext structure and exposes a managed, object-oriented API for working with media containers, streams, metadata, and format-specific options.
As a wrapper around unmanaged resources, this class implements IDisposable. Instances should be disposed when no longer needed to release the underlying FFmpeg resources.
Because this class derives from OptionQueryableBase, any FFmpeg options supported by FFmpeg.AutoGen._AVFormatContext can be queried and modified through the managed options API.
Constructors
View SourceFormatContext(_AVFormatContext*)
Initializes a new FormatContext from an existing native FFmpeg.AutoGen._AVFormatContext.
Declaration
protected FormatContext(_AVFormatContext* context)
Parameters
| Type | Name | Description |
|---|---|---|
| _AVFormatContext* | context | The native format context to wrap. |
Properties
View SourceChapters
Gets the chapters contained in the media.
Declaration
public virtual ChapterList Chapters { get; }
Property Value
| Type | Description |
|---|---|
| ChapterList |
Remarks
The returned collection provides access to the chapter entries stored in the underlying format context.
Flags
Gets the flags associated with this format context.
Declaration
public FormatContextFlags Flags { get; }
Property Value
| Type | Description |
|---|---|
| FormatContextFlags |
IsDisposed
Indicates whether the instance is disposed.
Declaration
public bool IsDisposed { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Metadata
Gets the metadata associated with the format context.
Declaration
public AVDictionary_ref Metadata { get; }
Property Value
| Type | Description |
|---|---|
| AVDictionary_ref |
Pointer
Abstract base class that provides access to a pointer for AVOptions retrieval.
Declaration
protected override void* Pointer { get; }
Property Value
| Type | Description |
|---|---|
| void* |
Overrides
View SourceSeekable
Gets the types of seeking supported by the underlying I/O context.
Declaration
public Seekable Seekable { get; }
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.
StartTimeRealTime
Gets the wall-clock time at which the media stream started.
Declaration
public DateTime? StartTimeRealTime { get; }
Property Value
| Type | Description |
|---|---|
| DateTime? |
Remarks
Returns null if the information is unavailable.
StreamCount
Gets the number of streams in this format context.
Declaration
public int StreamCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Streams
Cached managed wrappers for the native streams.
Declaration
public IReadOnlyList<AVStream> Streams { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<AVStream> |
Remarks
The collection is synchronized with the underlying native stream array on demand. If FFmpeg adds or replaces streams, the cached managed wrappers are recreated automatically.
Url
Gets the URL or filename associated with the format context.
Declaration
public string? Url { get; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Returns null if no URL has been assigned.
Methods
View SourceDispose()
Disposes of the resources used by the FormatContext and suppresses finalization.
Declaration
public void Dispose()
Dispose(bool)
Releases the resources used by the current format context.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | disposing | Indicates whether the method is being called from the Dispose() method or a finalizer. |
~FormatContext()
Finalizes the FormatContext.
Declaration
protected ~FormatContext()
FindBestStream(MediaType)
Finds the most appropriate stream of the specified media type.
Declaration
public int FindBestStream(MediaType type)
Parameters
| Type | Name | Description |
|---|---|---|
| MediaType | type | The media type to search for. |
Returns
| Type | Description |
|---|---|
| int | The zero-based stream index if a suitable stream is found; otherwise a negative FFmpeg error code. |
Remarks
This method calls FFmpeg's av_find_best_stream() using the default
stream selection behavior.
Free()
Releases the resources associated with this format context.
Declaration
public void Free()
Remarks
Equivalent to calling Dispose().
GetOutputTimestamp(int, out TimeSpan, out TimeSpan)
Retrieves the most recently output timestamp for a stream.
Declaration
public AVResult32 GetOutputTimestamp(int streamIndex, out TimeSpan timestamp, out TimeSpan wallTime)
Parameters
| Type | Name | Description |
|---|---|---|
| int | streamIndex | The index of the output stream. |
| TimeSpan | timestamp | Receives the output timestamp converted to the stream's time base. |
| TimeSpan | wallTime | Receives the corresponding wall-clock timestamp. |
Returns
| Type | Description |
|---|---|
| AVResult32 | The result returned by |
Remarks
This method is primarily intended for monitoring the progress of output devices or muxers that support timestamp reporting.
SetContext(IOContext, IOOptions, int)
Associates a custom IOContext with this format context.
Declaration
public void SetContext(IOContext context, IOOptions options, int bufferSize = 32768)
Parameters
| Type | Name | Description |
|---|---|---|
| IOContext | context | The IOContext to associate with the current format context. |
| IOOptions | options | The IOOptions specifying the operations (e.g., read or write) to be used with the context. |
| int | bufferSize | The size of the buffer to use for the I/O operations. Default is 32 KB. |
Remarks
Calling this method replaces any previously associated IOContext. The supplied context is initialized and attached to this format context.