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

RAII owner of one video stream's codec and pixel-format scaler state. More...

#include <VideoStreamContext.hpp>

+ Collaboration diagram for MayaFlux::IO::VideoStreamContext:

Public Member Functions

 VideoStreamContext ()=default
 
 ~VideoStreamContext ()
 
 VideoStreamContext (const VideoStreamContext &)=delete
 
VideoStreamContextoperator= (const VideoStreamContext &)=delete
 
 VideoStreamContext (VideoStreamContext &&)=delete
 
VideoStreamContextoperator= (VideoStreamContext &&)=delete
 
bool open (const FFmpegDemuxContext &demux, uint32_t target_width=0, uint32_t target_height=0, int target_format=-1)
 Open the video stream from an already-probed demux context.
 
bool open_device (const FFmpegDemuxContext &demux, uint32_t target_width=0, uint32_t target_height=0, int target_format=-1)
 Open codec only, without initialising the SwsContext scaler.
 
bool is_codec_valid () const
 True if the codec context is open and ready to receive packets.
 
void close ()
 Release codec and scaler resources.
 
bool is_valid () const
 True if the codec and scaler are ready for decoding.
 
bool rebuild_scaler_from_frame (const AVFrame *frame, uint32_t target_width=0, uint32_t target_height=0, int target_format=-1)
 Rebuild the SwsContext using the pixel format resolved from a live decoded frame.
 
void flush_codec ()
 Flush codec internal buffers (call after a seek).
 
void extract_stream_metadata (const FFmpegDemuxContext &demux, FileMetadata &out) const
 Populate stream-specific fields into an existing FileMetadata.
 
std::vector< FileRegionextract_keyframe_regions (const FFmpegDemuxContext &demux) const
 Extract keyframe positions as FileRegion entries.
 
const std::string & last_error () const
 

Public Attributes

AVCodecContext * codec_context = nullptr
 Owned; freed in destructor.
 
SwsContext * sws_context = nullptr
 Owned; freed in destructor.
 
int stream_index = -1
 
uint64_t total_frames {}
 
uint32_t width {}
 Source width in pixels.
 
uint32_t height {}
 Source height in pixels.
 
uint32_t out_width {}
 Output width after scaling.
 
uint32_t out_height {}
 Output height after scaling.
 
double frame_rate {}
 Average frame rate (fps).
 
int src_pixel_format = -1
 Source AVPixelFormat.
 
int out_pixel_format = -1
 Output AVPixelFormat.
 
uint32_t out_bytes_per_pixel = 4
 Bytes per pixel in output format.
 
int out_linesize {}
 Output row stride in bytes.
 
uint32_t target_width {}
 Requested output width (0 = source).
 
uint32_t target_height {}
 Requested output height (0 = source).
 
int target_format = -1
 Requested AVPixelFormat (negative = RGBA).
 

Private Member Functions

bool setup_scaler (uint32_t target_width, uint32_t target_height, int target_format)
 Allocate and initialise the SwsContext for pixel format conversion.
 

Private Attributes

std::string m_last_error
 

Detailed Description

RAII owner of one video stream's codec and pixel-format scaler state.

Encapsulates all video-stream-specific FFmpeg objects:

  • AVCodecContext for the selected video stream
  • SwsContext for pixel-format conversion and optional rescaling
  • Cached video parameters: width, height, frame_rate, total_frames, pixel_format

Does NOT own AVFormatContext — that belongs to FFmpegDemuxContext. Packet reading is always delegated to the demuxer's format_context; this context only decodes and converts packets it receives.

The default output pixel format is AV_PIX_FMT_RGBA (4 bytes per pixel), chosen for direct compatibility with Vulkan's VK_FORMAT_R8G8B8A8_UNORM and the MayaFlux TextureBuffer / VKImage pipeline. For HDR workflows or compute-shader ingestion, callers can request AV_PIX_FMT_RGBAF32 or other formats via the target_format parameter.

Destruction order (enforced in destructor): sws_context → codec_context The associated FFmpegDemuxContext must outlive this object.

Definition at line 36 of file VideoStreamContext.hpp.


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