MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::IO::FFmpegMuxContext Class Reference

RAII owner of a single AVFormatContext on the write path. More...

#include <FFmpegMuxContext.hpp>

+ Collaboration diagram for MayaFlux::IO::FFmpegMuxContext:

Public Member Functions

AVStream * add_stream ()
 Allocate a new AVStream inside this context.
 
void close ()
 Write the container trailer, flush avio, and release all resources.
 
 FFmpegMuxContext ()=default
 
 FFmpegMuxContext (const FFmpegMuxContext &)=delete
 
 FFmpegMuxContext (FFmpegMuxContext &&)=delete
 
bool is_header_written () const
 True if write_header() completed successfully.
 
bool is_open () const
 True if the context is open and ready to accept streams / packets.
 
const std::string & last_error () const
 
bool open (const std::string &filepath, const std::string &explicit_format={})
 Allocate an output context and open the avio layer for writing.
 
FFmpegMuxContextoperator= (const FFmpegMuxContext &)=delete
 
FFmpegMuxContextoperator= (FFmpegMuxContext &&)=delete
 
bool write_header ()
 Write the container header to the output file.
 
bool write_packet (AVPacket *pkt)
 Submit one encoded packet for interleaved writing.
 
 ~FFmpegMuxContext ()
 

Public Attributes

AVFormatContext * format_context = nullptr
 Owned; freed in close().
 

Private Attributes

bool m_header_written {}
 
std::string m_last_error
 

Detailed Description

RAII owner of a single AVFormatContext on the write path.

Encapsulates all format-level (container) FFmpeg mux operations:

  • Allocating an output context and opening the I/O layer (avio)
  • Writing the container header after all streams have been added
  • Writing interleaved encoded packets
  • Writing the container trailer and releasing all resources

Does NOT own any codec context, resampler, scaler, or stream — those are domain-specific and belong to AudioEncodeContext / VideoEncodeContext, which each call avformat_new_stream() on this context during their own open().

Stream contexts must be opened and fully configured before write_header() is called. Packets submitted via write_packet() must have stream_index and PTS/DTS set by the originating encode context.

Not copyable or movable; always stack- or member-allocated inside the owner (SoundFileWriter worker thread, future VideoFileWriter worker thread).

FFmpeg global initialisation is shared with FFmpegDemuxContext via the static FFmpegDemuxContext::init_ffmpeg() call.

Definition at line 35 of file FFmpegMuxContext.hpp.


The documentation for this class was generated from the following files: