Show / Hide Table of Contents

Class MuxerContext

Represents an output media container used for muxing encoded packets into a media file or stream.

Inheritance
object
OptionQueryableBase
FormatContext
MuxerContext
Implements
IOptionQueryable
ILoggingContext
IDisposable
IAVPointer<_AVFormatContext>
Inherited Members
FormatContext.SetContext(IOContext, IOOptions, int)
FormatContext.Free()
FormatContext.Dispose()
FormatContext.GetOutputTimestamp(int, out TimeSpan, out TimeSpan)
FormatContext.FindBestStream(MediaType)
FormatContext.Flags
FormatContext.StreamCount
FormatContext.Pointer
FormatContext.Streams
FormatContext.Chapters
FormatContext.Seekable
FormatContext.Url
FormatContext.Metadata
FormatContext.StartTimeRealTime
FormatContext.IsDisposed
OptionQueryableBase.ResetOptions()
OptionQueryableBase.GetOptions(bool)
OptionQueryableBase.FindOption(string, bool)
OptionQueryableBase.SetOption(string, string, bool)
OptionQueryableBase.SetOption(string, long, bool)
OptionQueryableBase.SetOption(string, bool, bool)
OptionQueryableBase.SetOption(string, double, bool)
OptionQueryableBase.SetOption(string, Rational, bool)
OptionQueryableBase.SetOption(string, ReadOnlySpan<byte>, bool)
OptionQueryableBase.SetOption(string, ReadOnlyMemory<byte>, bool)
OptionQueryableBase.SetOption(string, int, int, bool)
OptionQueryableBase.SetOption(string, (int Width, int Height), bool)
OptionQueryableBase.SetOption(string, PixelFormat, bool)
OptionQueryableBase.SetOption(string, SampleFormat, bool)
OptionQueryableBase.SetOption(string, IDictionary<string, string>, bool)
OptionQueryableBase.SetOption(string, ILookup<string, string>, bool)
OptionQueryableBase.SetOption(IDictionary<string, string>, bool)
OptionQueryableBase.SetOption(string, ref ILookup<string, string>, bool)
OptionQueryableBase.SetOption<T>(string, T, bool)
OptionQueryableBase.SetOption(string, object, bool)
OptionQueryableBase.SetOption(Option, string, bool)
OptionQueryableBase.SetOption(Option, bool, bool)
OptionQueryableBase.SetOption(Option, long, bool)
OptionQueryableBase.SetOption(Option, double, bool)
OptionQueryableBase.SetOption(Option, Rational, bool)
OptionQueryableBase.SetOption(Option, ReadOnlySpan<byte>, bool)
OptionQueryableBase.SetOption(Option, ReadOnlyMemory<byte>, bool)
OptionQueryableBase.SetOption(Option, int, int, bool)
OptionQueryableBase.SetOption(Option, (int Width, int Height), bool)
OptionQueryableBase.SetOption(Option, PixelFormat, bool)
OptionQueryableBase.SetOption(Option, SampleFormat, bool)
OptionQueryableBase.SetOption(Option, IDictionary<string, string>, bool)
OptionQueryableBase.SetOption(Option, ILookup<string, string>, bool)
OptionQueryableBase.SetOption<T>(Option, T, bool)
OptionQueryableBase.SetOption(Option, object, bool)
OptionQueryableBase.TryGetOption(string, out string, bool)
OptionQueryableBase.TryGetOption(string, out long, bool)
OptionQueryableBase.TryGetOption<T>(string, out T, bool)
OptionQueryableBase.TryGetOption(string, out ulong, bool)
OptionQueryableBase.TryGetOption(string, out int, bool)
OptionQueryableBase.TryGetOption(string, out bool, bool)
OptionQueryableBase.TryGetOption(string, out uint, bool)
OptionQueryableBase.TryGetOption(string, out double, bool)
OptionQueryableBase.TryGetOption(string, out Rational, bool)
OptionQueryableBase.TryGetOption(string, out PixelFormat, bool)
OptionQueryableBase.TryGetOption(string, out SampleFormat, bool)
OptionQueryableBase.TryGetOption(string, out IDictionary<string, string>, bool)
OptionQueryableBase.TryGetOption(string, out Dictionary<string, string>, bool)
OptionQueryableBase.TryGetOption(string, out AVDictionary, bool)
OptionQueryableBase.TryGetOption(string, out ILookup<string, string>, bool)
OptionQueryableBase.TryGetOption(string, out AVMultiDictionary, bool)
OptionQueryableBase.TryGetOption(string, out int, out int, bool)
OptionQueryableBase.TryGetOption(string, out (int Width, int Height), bool)
OptionQueryableBase.TryGetOption(string, Span<byte>, bool)
OptionQueryableBase.TryGetOption(string, out byte[], bool)
OptionQueryableBase.TryGetOption(string, out Memory<byte>, bool)
OptionQueryableBase.TryGetOption(string, out ReadOnlyMemory<byte>, bool)
OptionQueryableBase.TryGetOption(string, out object, bool)
OptionQueryableBase.TryGetOption(Option, out string, bool)
OptionQueryableBase.TryGetOption(Option, out long, bool)
OptionQueryableBase.TryGetOption<T>(Option, out T, bool)
OptionQueryableBase.TryGetOption(Option, out ulong, bool)
OptionQueryableBase.TryGetOption(Option, out int, bool)
OptionQueryableBase.TryGetOption(Option, out bool, bool)
OptionQueryableBase.TryGetOption(Option, out uint, bool)
OptionQueryableBase.TryGetOption(Option, out double, bool)
OptionQueryableBase.TryGetOption(Option, out Rational, bool)
OptionQueryableBase.TryGetOption(Option, out PixelFormat, bool)
OptionQueryableBase.TryGetOption(Option, out SampleFormat, bool)
OptionQueryableBase.TryGetOption(Option, out IDictionary<string, string>, bool)
OptionQueryableBase.TryGetOption(Option, out Dictionary<string, string>, bool)
OptionQueryableBase.TryGetOption(Option, out AVDictionary, bool)
OptionQueryableBase.TryGetOption(Option, out ILookup<string, string>, bool)
OptionQueryableBase.TryGetOption(Option, out AVMultiDictionary, bool)
OptionQueryableBase.TryGetOption(Option, out int, out int, bool)
OptionQueryableBase.TryGetOption(Option, out (int Width, int Height), bool)
OptionQueryableBase.TryGetOption(Option, out byte[], bool)
OptionQueryableBase.TryGetOption(Option, out Memory<byte>, bool)
OptionQueryableBase.TryGetOption(Option, out ReadOnlyMemory<byte>, bool)
OptionQueryableBase.TryGetOption(Option, Span<byte>, bool)
OptionQueryableBase.TryGetOption(Option, out object, bool)
OptionQueryableBase.SetOption(string, ChannelLayout, bool)
OptionQueryableBase.SetOption(Option, ChannelLayout, bool)
OptionQueryableBase.TryGetOption(string, out ChannelLayout, bool)
OptionQueryableBase.TryGetOption(Option, out ChannelLayout, bool)
object.GetType()
object.MemberwiseClone()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: FFmpeg.Formats
Assembly: FFmpeg.dll
Syntax
public class MuxerContext : FormatContext, IOptionQueryable, ILoggingContext, IDisposable, IAVPointer<_AVFormatContext>
Remarks

MuxerContext is the output counterpart to DemuxerContext. It provides functionality for creating media containers, adding streams, writing container headers, writing encoded packets, and finalizing the output.

A muxer can write to a file, a Stream, or a custom IOContext. After opening a muxer, one or more streams should be added and configured before calling WriteHeader(). Encoded packets can then be written using WritePacket(IPacket?) or WritePacketInterleaved(IPacket?). Once all packets have been written, WriteTrailer() should be called to finalize the container.

This class wraps FFmpeg's AVFormatContext for output operations and corresponds to the FFmpeg muxing API.

Constructors

View Source

MuxerContext(_AVFormatContext*)

Creates a muxer context that wraps around the provided ffmpeg ibject

Declaration
protected MuxerContext(_AVFormatContext* context)
Parameters
Type Name Description
_AVFormatContext* context

The pointer to the _AVFormatContext

Properties

View Source

OutputFormat

Gets the output format associated with this context, if available.

Declaration
public OutputFormat? OutputFormat { get; }
Property Value
Type Description
OutputFormat?

Methods

View Source

AddStream(Codec)

Adds a new stream to the output container.

Declaration
public AVStream AddStream(Codec codec)
Parameters
Type Name Description
Codec codec

The codec associated with the new stream.

Returns
Type Description
AVStream

An AVStream representing the newly created stream.

Remarks

This method creates a new AVStream using FFmpeg.AutoGen.ffmpeg.avformat_new_stream(FFmpeg.AutoGen._AVFormatContext*, FFmpeg.AutoGen._AVCodec*) and initializes its codec identifier and media type.

The returned stream should be configured before calling WriteHeader().

Exceptions
Type Condition
OutOfMemoryException

Thrown if FFmpeg fails to allocate the new stream.

View Source

AddStream(Codec, ICodecParameters)

Adds a new stream to the output container and copies codec parameters from an existing source.

Declaration
public AVStream AddStream(Codec codec, ICodecParameters codecParameters)
Parameters
Type Name Description
Codec codec

The codec associated with the new stream.

ICodecParameters codecParameters

The codec parameters to copy into the stream.

Returns
Type Description
AVStream

An AVStream representing the newly created stream.

Remarks

The codec parameters are copied using FFmpeg.AutoGen.ffmpeg.avcodec_parameters_copy(FFmpeg.AutoGen._AVCodecParameters*, FFmpeg.AutoGen._AVCodecParameters*). This overload is useful when remuxing existing streams or when codec parameters are already available.

Exceptions
Type Condition
OutOfMemoryException

Thrown if FFmpeg fails to allocate the new stream.

View Source

AddStream(CodecContext)

Adds a new stream to the output container using an existing codec context.

Declaration
public AVStream AddStream(CodecContext codec)
Parameters
Type Name Description
CodecContext codec

The codec context whose parameters are copied to the new stream.

Returns
Type Description
AVStream

An AVStream representing the newly created stream.

Remarks

The codec parameters and time base are copied from the supplied CodecContext.

If the selected output format requires global headers, the GlobalHeader flag is automatically enabled on the codec context before encoding begins.

Exceptions
Type Condition
OutOfMemoryException

Thrown if FFmpeg fails to allocate the new stream.

View Source

AddStream(AVStream)

Adds a stream based on the codec parameters of the

Declaration
public AVStream AddStream(AVStream copyStream)
Parameters
Type Name Description
AVStream copyStream

The stream that contains the codec parameters we want to copy

Returns
Type Description
AVStream

The added stream.

View Source

Dispose(bool)

Releases the resources used by the current format context.

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

Indicates whether the method is being called from the Dispose() method or a finalizer.

Overrides
FormatContext.Dispose(bool)
View Source

Flush()

Flushes the underlying output I/O context, if one exists.

Declaration
public void Flush()
Remarks

This forces any buffered data to be written to the underlying stream or file. It does not finalize the media container; call WriteTrailer() to properly finish the output.

View Source

Open(IOContext, OutputFormat)

Opens an output media file using an I/O context for writing.

Declaration
public static MuxerContext? Open(IOContext context, OutputFormat format)
Parameters
Type Name Description
IOContext context

The I/O context for output media.

OutputFormat format

The output format.

Returns
Type Description
MuxerContext

An instance of MuxerContext or null if the operation fails.

View Source

Open(Stream, OutputFormat, bool)

Opens an output stream for writing.

Declaration
public static MuxerContext? Open(Stream stream, OutputFormat format, bool closeOnDispose = true)
Parameters
Type Name Description
Stream stream

The stream for output media.

OutputFormat format

The output format.

bool closeOnDispose

If true, when the MuxerContext is closed the stream will be too.

Returns
Type Description
MuxerContext

An instance of MuxerContext or null if the operation fails.

View Source

Open(string)

Opens an output media file for writing.

Declaration
public static MuxerContext? Open(string filename)
Parameters
Type Name Description
string filename

The filename for the output media.

Returns
Type Description
MuxerContext

An instance of MuxerContext or null if the operation fails.

View Source

Open(string?, OutputFormat?)

Opens an output media file for writing. For Output fomats of the no file type, filename may be null.

Declaration
public static MuxerContext? Open(string? filename, OutputFormat? format)
Parameters
Type Name Description
string filename

The filename for the output media.

OutputFormat? format

The output format.

Returns
Type Description
MuxerContext

An instance of MuxerContext or null if the operation fails.

View Source

ToString()

Returns the long name of the output format.

Declaration
public override string ToString()
Returns
Type Description
string

The long name of the output format, or "Unknown" if no output format is associated with this context.

Overrides
object.ToString()
View Source

WriteFrame(IPacket?)

Writes a frame to the output media file.

Declaration
[Obsolete("Renamed to WritePacket")]
public AVResult32 WriteFrame(IPacket? packet)
Parameters
Type Name Description
IPacket packet

The packet to write. If null, writes a null packet.

Returns
Type Description
AVResult32

An AVResult32 indicating the result of the operation.

View Source

WriteFrameInterleaved(IPacket?)

Writes an interleaved frame to the output media file.

Declaration
[Obsolete("Renamed to WritePacketInterleaved")]
public AVResult32 WriteFrameInterleaved(IPacket? packet)
Parameters
Type Name Description
IPacket packet

The packet to write. If null, writes a null packet.

Returns
Type Description
AVResult32

An AVResult32 indicating the result of the operation.

View Source

WriteHeader()

Writes the header of the output media file.

Declaration
public AVResult32 WriteHeader()
Returns
Type Description
AVResult32

An AVResult32 indicating the result of the operation.

View Source

WriteHeader(AVDictionary)

Writes the header of the output media file using a specified dictionary.

Declaration
public AVResult32 WriteHeader(AVDictionary dictionary)
Parameters
Type Name Description
AVDictionary dictionary

A dictionary of options.

Returns
Type Description
AVResult32

An AVResult32 indicating the result of the operation.

View Source

WriteHeader(AVMultiDictionary)

Writes the header of the output media file using a multi-dictionary.

Declaration
public AVResult32 WriteHeader(AVMultiDictionary dictionary)
Parameters
Type Name Description
AVMultiDictionary dictionary

A multi-dictionary of options.

Returns
Type Description
AVResult32

An AVResult32 indicating the result of the operation.

View Source

WriteHeader(IDictionary<string, string>)

Writes the header of the output media file using a dictionary represented as IDictionary<TKey, TValue>.

Declaration
public AVResult32 WriteHeader(IDictionary<string, string> dictionary)
Parameters
Type Name Description
IDictionary<string, string> dictionary

A dictionary of options.

Returns
Type Description
AVResult32

An AVResult32 indicating the result of the operation.

View Source

WritePacket(IPacket?)

Writes a frame to the output media file.

Declaration
public AVResult32 WritePacket(IPacket? packet)
Parameters
Type Name Description
IPacket packet

The packet to write. If null, writes a null packet.

Returns
Type Description
AVResult32

An AVResult32 indicating the result of the operation.

View Source

WritePacketInterleaved(IPacket?)

Writes an interleaved frame to the output media file.

Declaration
public AVResult32 WritePacketInterleaved(IPacket? packet)
Parameters
Type Name Description
IPacket packet

The packet to write. If null, writes a null packet.

Returns
Type Description
AVResult32

An AVResult32 indicating the result of the operation.

View Source

WriteTrailer()

Writes the trailer of the output media file and finalizes the container.

Declaration
public AVResult32 WriteTrailer()
Returns
Type Description
AVResult32

An AVResult32 indicating the result of the operation.

Remarks

This method must be called after all packets have been written. It writes any remaining buffered data, updates container metadata such as indexes, and releases internal muxing state maintained by FFmpeg.

Implements

IOptionQueryable
ILoggingContext
IDisposable
IAVPointer<T>

Extension Methods

LoggingContextExtensions.Debug(ILoggingContext, string)
LoggingContextExtensions.Error(ILoggingContext, string)
LoggingContextExtensions.Fatal(ILoggingContext, string)
LoggingContextExtensions.Info(ILoggingContext, string)
LoggingContextExtensions.Log(ILoggingContext, LogLevel, string)
LoggingContextExtensions.Panic(ILoggingContext, string)
LoggingContextExtensions.Trace(ILoggingContext, string)
LoggingContextExtensions.Verbose(ILoggingContext, string)
LoggingContextExtensions.Warning(ILoggingContext, string)
  • View Source
In this article
Back to top Generated by DocFX