AV module

av

Audio/video codecs, capture devices, packet types, and media helpers.

av

Audio/video codecs, capture devices, packet types, and media helpers.

Classes

NameDescription
AppleDeviceWatcherMonitors device add/remove events via AVFoundation notifications and CoreAudio property listeners.
AudioCaptureCross-platform audio capture device backed by FFmpeg input devices.
AudioPacketEncoderPacketProcessor that encodes raw audio samples (PlanarAudioPacket or AudioPacket) into compressed packets via AudioEncoder.
DeviceManagerEnumerates and manages system audio and video devices.
DeviceWatcherBase class for platform-specific device change monitors.
FormatRegistrySingleton registry of available media container formats for encoding and decoding.
FPSCounterFPS counter based on the simple moving average (SMA) algorithm.
FPSLimiterPacketStream processor that caps packet throughput to a maximum FPS.
ICaptureAbstract interface for audio and video capture devices.
IEncoderThis is the abstract class for all encoders.
LinuxDeviceWatcherMonitors device add/remove events via libudev.
MediaCaptureUnified capture and decode source for files and live media devices.
MultiplexEncoderMultiplexing encoder that writes synchronized audio and video streams.
MultiplexPacketEncoderEncodes and multiplexes a realtime video stream form audio / video capture sources. FFmpeg is used for encoding.
RealtimePacketQueueQueue that emits media packets in presentation-timestamp order relative to a realtime clock.
VideoCaptureCross-platform video device capturer backed by FFmpeg avdevice.
VideoPacketEncoderPacketProcessor that encodes raw video frames (PlanarVideoPacket or VideoPacket) into compressed packets via VideoEncoder.
WindowsDeviceWatcherMonitors device add/remove events via IMMNotificationClient (audio) and RegisterDeviceNotification (video).
AudioBufferFIFO buffer for queuing audio samples between encoding stages.
AudioCodecAudio codec parameters including channels, sample rate, and sample format.
AudioContextBase context for audio encoding and decoding via FFmpeg.
AudioDecoderDecodes compressed audio packets into raw sample frames.
AudioEncoderEncodes raw audio samples into a compressed format.
AudioPacketAudio packet for interleaved formats.
AudioResamplerConverts audio samples between different formats, sample rates, and channel layouts.
CodecCodec for encoding/decoding media.
DeleterRAII helpers for owning FFmpeg allocation types.
DeleterpDeleter adaptor for functions like av_freep that take a pointer to a pointer.
DeviceRepresents a system audio, video or render device.
EncoderOptionsConfiguration options for audio and video encoders.
EncoderStateState machine states for the encoder pipeline.
FormatDefines a media container format which is available through the FormatRegistry for encoding or decoding.
MediaPacketTimestamped media packet carrying raw audio or video data.
PlanarAudioPacketAudio packet for planar formats.
PlanarVideoPacketVideo packet for planar formats.
VideoCodecVideo codec parameters including resolution, frame rate, and pixel format.
VideoContextBase video context from which all video encoders and decoders derive.
VideoConverterConverts video frames between pixel formats and resolutions.
VideoDecoderDecodes compressed video packets into raw frames.
VideoEncoderEncodes raw video frames into a compressed format.
VideoPacketVideo packet for interleaved formats.

Enumerations

NameDescription
MediaCapabilitiesBitmask of media capabilities detected on this system.

MediaCapabilities

enum MediaCapabilities

Bitmask of media capabilities detected on this system.

ValueDescription
AUDIO_RECVAudio capture or decode is available.
AUDIO_SENDAudio playback or encode is available.
VIDEO_RECVVideo capture or decode is available.
VIDEO_SENDVideo render or encode is available.

Typedefs

ReturnNameDescription
std::list< Codec >CodecListList of codec value objects.
std::list< Codec * >CodecPListList of codec pointers.
std::unique_ptr< AVFrame, Deleterp< AVFrame, void, av_frame_free > >AVFrameHolderOwning AVFrame pointer released with av_frame_free().
std::unique_ptr< AVFormatContext, Deleter< AVFormatContext, void, avformat_free_context > >AVFormatContextHolderOwning AVFormatContext pointer released with avformat_free_context().
std::unique_ptr< AVCodecContext, Deleterp< AVCodecContext, void, avcodec_free_context > >AVCodecContextHolderOwning AVCodecContext pointer released with avcodec_free_context().
std::unique_ptr< AVDictionary *, Deleter< AVDictionary *, void, av_dict_free > >AVDictionaryCleanupCleanup wrapper for AVDictionary* values freed with av_dict_free().
std::unique_ptr< AVPacket, Deleterp< AVPacket, void, av_packet_free > >AVPacketHolderOwning AVPacket pointer released with av_packet_free().
std::vector< Format >FormatListList of container format value objects.
std::vector< Format * >FormatPListList of container format pointers.
IEncoderIPacketEncoderLegacy alias for IEncoder kept for 0.8.x compatibility.

CodecList

std::list< Codec > CodecList()

List of codec value objects.


CodecPList

std::list< Codec * > CodecPList()

List of codec pointers.


AVFrameHolder

std::unique_ptr< AVFrame, Deleterp< AVFrame, void, av_frame_free > > AVFrameHolder()

Owning AVFrame pointer released with av_frame_free().


AVFormatContextHolder

std::unique_ptr< AVFormatContext, Deleter< AVFormatContext, void, avformat_free_context > > AVFormatContextHolder()

Owning AVFormatContext pointer released with avformat_free_context().


AVCodecContextHolder

std::unique_ptr< AVCodecContext, Deleterp< AVCodecContext, void, avcodec_free_context > > AVCodecContextHolder()

Owning AVCodecContext pointer released with avcodec_free_context().


AVDictionaryCleanup

std::unique_ptr< AVDictionary *, Deleter< AVDictionary *, void, av_dict_free > > AVDictionaryCleanup()

Cleanup wrapper for AVDictionary* values freed with av_dict_free().


AVPacketHolder

std::unique_ptr< AVPacket, Deleterp< AVPacket, void, av_packet_free > > AVPacketHolder()

Owning AVPacket pointer released with av_packet_free().


FormatList

std::vector< Format > FormatList()

List of container format value objects.


FormatPList

std::vector< Format * > FormatPList()

List of container format pointers.


IPacketEncoder

IEncoder IPacketEncoder()

Legacy alias for IEncoder kept for 0.8.x compatibility.

Functions

ReturnNameDescription
voidinitAudioCodecFromContextPopulate an AudioCodec from an open AVCodecContext.
AVSampleFormatselectSampleFormatSelect the best supported sample format for a codec given the requested parameters. Returns the requested format if supported, otherwise the first format with the same planarity.
boolisSampleFormatSupportedCheck whether a specific sample format is in the codec's supported list.
boolformatIsPlanarReturn true if the named sample format is planar (e.g. "fltp", "s16p").
boolformatIsPlanarReturn true if the given AVSampleFormat is planar.
int64_tfpsToInterval inlineConvert a frame rate to a nanosecond frame interval.
intintervalToFps inlineConvert a nanosecond frame interval to a frame rate.
floatintervalToFpsFloat inlineConvert a nanosecond frame interval to a floating-point frame rate.
voidinitializeFFmpegInitialize the FFmpeg library.
voiduninitializeFFmpegUninitializes the FFmpeg library.
std::stringaverrorGet an error string for the given error code.
voidprintInputFormatsPrint all available FFmpeg demuxer (input) format names to the given stream.
voidprintOutputFormatsPrint all available FFmpeg muxer (output) format names to the given stream.
voidprintEncodersPrint all available FFmpeg encoder names to the given stream.
AVPacketHoldermakeOwnedPacketAllocate an owning AVPacket with FFmpeg-required padding and timestamp metadata. The packet payload is copied into FFmpeg-managed storage, which is required by decoders such as H.264 that may overread AV_INPUT_BUFFER_PADDING_SIZE bytes.
AVFrame *createVideoFrameAllocate a new AVFrame with the given pixel format and dimensions. Uses av_frame_get_buffer for reference-counted allocation with 16-byte alignment.
AVFrame *cloneVideoFramePerform a deep copy of an AVFrame including its buffer data and properties.
voidinitVideoCodecFromContextPopulate a VideoCodec from an open AVStream and AVCodecContext.
AVPixelFormatselectPixelFormatSelect the best supported pixel format for a codec given the requested parameters. Returns the requested format if supported, otherwise the first format with the same plane count.

initAudioCodecFromContext

void initAudioCodecFromContext(const AVCodecContext * ctx, AudioCodec & params)

Populate an AudioCodec from an open AVCodecContext.

Parameters

  • ctx The FFmpeg codec context to read from.

  • params The AudioCodec struct to fill with codec, channel, sample rate, and format info.


selectSampleFormat

AVSampleFormat selectSampleFormat(const AVCodec * codec, av::AudioCodec & params)

Select the best supported sample format for a codec given the requested parameters. Returns the requested format if supported, otherwise the first format with the same planarity.

Parameters

  • codec The FFmpeg codec whose supported formats are queried.

  • params The audio codec parameters specifying the desired sample format.

Returns

The chosen AVSampleFormat, or AV_SAMPLE_FMT_NONE if none is compatible.


isSampleFormatSupported

bool isSampleFormatSupported(const AVCodec * codec, enum AVSampleFormat sampleFormat)

Check whether a specific sample format is in the codec's supported list.

Parameters

  • codec The FFmpeg codec to query.

  • sampleFormat The AVSampleFormat to look up.

Returns

True if the format is supported.


formatIsPlanar

bool formatIsPlanar(const std::string & pixfmt)

Return true if the named sample format is planar (e.g. "fltp", "s16p").

Parameters

  • pixfmt The sample format name string.

formatIsPlanar

bool formatIsPlanar(AVSampleFormat format)

Return true if the given AVSampleFormat is planar.

Parameters

  • format The AVSampleFormat to check.

fpsToInterval

inline

inline int64_t fpsToInterval(int fps)

Convert a frame rate to a nanosecond frame interval.

Parameters

  • fps The frame rate in frames per second.

Returns

The interval in nanoseconds between frames, or the minimum interval if fps is zero.


intervalToFps

inline

inline int intervalToFps(int64_t interval)

Convert a nanosecond frame interval to a frame rate.

Parameters

  • interval The nanosecond interval between frames.

Returns

The frame rate in frames per second, or zero if interval is zero.


intervalToFpsFloat

inline

inline float intervalToFpsFloat(int64_t interval)

Convert a nanosecond frame interval to a floating-point frame rate.

Parameters

  • interval The nanosecond interval between frames.

Returns

The frame rate in frames per second as a float, or 0.0f if interval is zero.


initializeFFmpeg

void initializeFFmpeg()

Initialize the FFmpeg library.


uninitializeFFmpeg

void uninitializeFFmpeg()

Uninitializes the FFmpeg library.


averror

std::string averror(const int error)

Get an error string for the given error code.


printInputFormats

void printInputFormats(std::ostream & ost, const char * delim)

Print all available FFmpeg demuxer (input) format names to the given stream.

Parameters

  • ost The output stream to write to.

  • delim Delimiter inserted between each name.


printOutputFormats

void printOutputFormats(std::ostream & ost, const char * delim)

Print all available FFmpeg muxer (output) format names to the given stream.

Parameters

  • ost The output stream to write to.

  • delim Delimiter inserted between each name.


printEncoders

void printEncoders(std::ostream & ost, const char * delim)

Print all available FFmpeg encoder names to the given stream.

Parameters

  • ost The output stream to write to.

  • delim Delimiter inserted between each name.


makeOwnedPacket

AVPacketHolder makeOwnedPacket(const MediaPacket & packet, int streamIndex, AVRational timeBase)

Allocate an owning AVPacket with FFmpeg-required padding and timestamp metadata. The packet payload is copied into FFmpeg-managed storage, which is required by decoders such as H.264 that may overread AV_INPUT_BUFFER_PADDING_SIZE bytes.


createVideoFrame

AVFrame * createVideoFrame(AVPixelFormat pixelFmt, int width, int height)

Allocate a new AVFrame with the given pixel format and dimensions. Uses av_frame_get_buffer for reference-counted allocation with 16-byte alignment.

Parameters

  • pixelFmt The pixel format for the frame.

  • width The frame width in pixels.

  • height The frame height in pixels.

Returns

A newly allocated AVFrame, or nullptr on failure.


cloneVideoFrame

AVFrame * cloneVideoFrame(AVFrame * source)

Perform a deep copy of an AVFrame including its buffer data and properties.

Parameters

  • source The source frame to copy.

Returns

A newly allocated AVFrame with copied data. Caller owns the result.


initVideoCodecFromContext

void initVideoCodecFromContext(const AVStream * stream, const AVCodecContext * ctx, VideoCodec & params)

Populate a VideoCodec from an open AVStream and AVCodecContext.

Parameters

  • stream The AVStream for frame rate information (may be null).

  • ctx The FFmpeg codec context to read from.

  • params The VideoCodec struct to fill with codec, dimension, and format info.


selectPixelFormat

AVPixelFormat selectPixelFormat(const AVCodec * codec, VideoCodec & params)

Select the best supported pixel format for a codec given the requested parameters. Returns the requested format if supported, otherwise the first format with the same plane count.

Parameters

  • codec The FFmpeg codec whose supported formats are queried.

  • params The video codec parameters specifying the desired pixel format.

Returns

The chosen AVPixelFormat.