AV module

AV module

Audio/video encoding, decoding, device capture, and media formats.

Namespaces

NameDescription
v4l2Linux V4L2 device enumeration helpers.
coreaudioApple CoreAudio device enumeration helpers.
legacyLegacy timing helpers kept for compatibility with older media pipelines.
avfoundationApple AVFoundation device enumeration helpers.
mediafoundationWindows Media Foundation device enumeration helpers.
wasapiWindows WASAPI device enumeration helpers.

Classes

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

Macros


MAX_VIDEO_PACKET_SIZE

#define MAX_VIDEO_PACKET_SIZE (3 * 1024 * 1024)

Defined in src/av/include/icy/av/av.h:20


MAX_AUDIO_PACKET_SIZE

#define MAX_AUDIO_PACKET_SIZE (128 * 1500)

Defined in src/av/include/icy/av/av.h:21

1 second of 48khz 32bit audio


MAX_ENCODE_DURATION

#define MAX_ENCODE_DURATION (3 * 60 * 60 * 1000)

Defined in src/av/include/icy/av/av.h:22

3 hours


INT64_C

#define INT64_C(c) (c##LL)

Defined in src/av/include/icy/av/av.h:32


UINT64_C

#define UINT64_C(c) (c##ULL)

Defined in src/av/include/icy/av/av.h:35


AV_API

#define AV_API ICY_IMPORT

Defined in src/av/include/icy/av/av.h:43


DEFAULT_AUDIO_SAMPLE_RATE

#define DEFAULT_AUDIO_SAMPLE_RATE 44100

Defined in src/av/include/icy/av/codec.h:95


DEFAULT_AUDIO_BIT_RATE

#define DEFAULT_AUDIO_BIT_RATE 64000

Defined in src/av/include/icy/av/codec.h:96


DEFAULT_AUDIO_CHANNELS

#define DEFAULT_AUDIO_CHANNELS 2

Defined in src/av/include/icy/av/codec.h:97


DEFAULT_AUDIO_SAMPLE_FMT

#define DEFAULT_AUDIO_SAMPLE_FMT "s16"

Defined in src/av/include/icy/av/codec.h:98


DEFAULT_VIDEO_SAMPLE_RATE

#define DEFAULT_VIDEO_SAMPLE_RATE 384000

Defined in src/av/include/icy/av/codec.h:163


DEFAULT_VIDEO_BIT_RATE

#define DEFAULT_VIDEO_BIT_RATE 400000

Defined in src/av/include/icy/av/codec.h:164


DEFAULT_VIDEO_PIXEL_FMT

#define DEFAULT_VIDEO_PIXEL_FMT "yuv420p"

Defined in src/av/include/icy/av/codec.h:165

Enumerations

NameDescription
MediaCapabilitiesBitmask of media capabilities detected on this system.

MediaCapabilities

enum MediaCapabilities

Defined in src/av/include/icy/av/devicemanager.h:177

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

using CodecList = std::list< Codec >

Type: std::list< Codec >

Defined in src/av/include/icy/av/codec.h:231

List of codec value objects.


CodecPList

using CodecPList = std::list< Codec * >

Type: std::list< Codec * >

Defined in src/av/include/icy/av/codec.h:232

List of codec pointers.


AVFrameHolder

using AVFrameHolder = std::unique_ptr< AVFrame, Deleterp< AVFrame, void, av_frame_free > >

Type: std::unique_ptr< AVFrame, Deleterp< AVFrame, void, av_frame_free > >

Defined in src/av/include/icy/av/ffmpeg.h:90

Owning AVFrame pointer released with av_frame_free().


AVFormatContextHolder

using AVFormatContextHolder = std::unique_ptr< AVFormatContext, Deleter< AVFormatContext, void, avformat_free_context > >

Type: std::unique_ptr< AVFormatContext, Deleter< AVFormatContext, void, avformat_free_context > >

Defined in src/av/include/icy/av/ffmpeg.h:94

Owning AVFormatContext pointer released with avformat_free_context().


AVCodecContextHolder

using AVCodecContextHolder = std::unique_ptr< AVCodecContext, Deleterp< AVCodecContext, void, avcodec_free_context > >

Type: std::unique_ptr< AVCodecContext, Deleterp< AVCodecContext, void, avcodec_free_context > >

Defined in src/av/include/icy/av/ffmpeg.h:98

Owning AVCodecContext pointer released with avcodec_free_context().


AVDictionaryCleanup

using AVDictionaryCleanup = std::unique_ptr< AVDictionary *, Deleter< AVDictionary *, void, av_dict_free > >

Type: std::unique_ptr< AVDictionary *, Deleter< AVDictionary *, void, av_dict_free > >

Defined in src/av/include/icy/av/ffmpeg.h:102

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


AVPacketHolder

using AVPacketHolder = std::unique_ptr< AVPacket, Deleterp< AVPacket, void, av_packet_free > >

Type: std::unique_ptr< AVPacket, Deleterp< AVPacket, void, av_packet_free > >

Defined in src/av/include/icy/av/ffmpeg.h:106

Owning AVPacket pointer released with av_packet_free().


FormatList

using FormatList = std::vector< Format >

Type: std::vector< Format >

Defined in src/av/include/icy/av/format.h:113

List of container format value objects.


FormatPList

using FormatPList = std::vector< Format * >

Type: std::vector< Format * >

Defined in src/av/include/icy/av/format.h:114

List of container format pointers.


IPacketEncoder

using IPacketEncoder = IEncoder

Type: IEncoder

Defined in src/av/include/icy/av/iencoder.h:144

Legacy alias for IEncoder kept for 0.8.x compatibility.

Functions

ReturnNameDescription
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.
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.
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.
std::optional< std::pair< const AVInputFormat *, std::string > >parseDeviceUrlParse a libavdevice URL scheme.

fpsToInterval

inline

inline int64_t fpsToInterval(int fps)

Defined in src/av/include/icy/av/codec.h:241

Convert a frame rate to a nanosecond frame interval.

Returns

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

Parameters

ParameterTypeDescription
fpsintThe frame rate in frames per second.

intervalToFps

inline

inline int intervalToFps(int64_t interval)

Defined in src/av/include/icy/av/codec.h:251

Convert a nanosecond frame interval to a frame rate.

Returns

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

Parameters

ParameterTypeDescription
intervalint64_tThe nanosecond interval between frames.

intervalToFpsFloat

inline

inline float intervalToFpsFloat(int64_t interval)

Defined in src/av/include/icy/av/codec.h:263

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

Returns

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

Parameters

ParameterTypeDescription
intervalint64_tThe nanosecond interval between frames.

initializeFFmpeg

void initializeFFmpeg()

Defined in src/av/include/icy/av/ffmpeg.h:39

Initialize the FFmpeg library.


uninitializeFFmpeg

void uninitializeFFmpeg()

Defined in src/av/include/icy/av/ffmpeg.h:42

Uninitializes the FFmpeg library.


averror

std::string averror(const int error)

Defined in src/av/include/icy/av/ffmpeg.h:45

Get an error string for the given error code.


printInputFormats

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

Defined in src/av/include/icy/av/ffmpeg.h:50

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

Parameters

ParameterTypeDescription
oststd::ostream &The output stream to write to.
delimconst char *Delimiter inserted between each name.

printOutputFormats

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

Defined in src/av/include/icy/av/ffmpeg.h:55

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

Parameters

ParameterTypeDescription
oststd::ostream &The output stream to write to.
delimconst char *Delimiter inserted between each name.

printEncoders

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

Defined in src/av/include/icy/av/ffmpeg.h:60

Print all available FFmpeg encoder names to the given stream.

Parameters

ParameterTypeDescription
oststd::ostream &The output stream to write to.
delimconst char *Delimiter inserted between each name.

makeOwnedPacket

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

Defined in src/av/include/icy/av/ffmpeg.h:113

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.


initAudioCodecFromContext

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

Defined in src/av/include/icy/av/audiocontext.h:112

Populate an AudioCodec from an open AVCodecContext.

Parameters

ParameterTypeDescription
ctxconst AVCodecContext *The FFmpeg codec context to read from.
paramsAudioCodec &The AudioCodec struct to fill with codec, channel, sample rate, and format info.

selectSampleFormat

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

Defined in src/av/include/icy/av/audiocontext.h:119

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.

Returns

The chosen AVSampleFormat, or AV_SAMPLE_FMT_NONE if none is compatible.

Parameters

ParameterTypeDescription
codecconst AVCodec *The FFmpeg codec whose supported formats are queried.
paramsav::AudioCodec &The audio codec parameters specifying the desired sample format.

isSampleFormatSupported

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

Defined in src/av/include/icy/av/audiocontext.h:125

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

Returns

True if the format is supported.

Parameters

ParameterTypeDescription
codecconst AVCodec *The FFmpeg codec to query.
sampleFormatenum AVSampleFormatThe AVSampleFormat to look up.

formatIsPlanar

bool formatIsPlanar(const std::string & pixfmt)

Defined in src/av/include/icy/av/audiocontext.h:129

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

Parameters

ParameterTypeDescription
pixfmtconst std::string &The sample format name string.

formatIsPlanar

bool formatIsPlanar(AVSampleFormat format)

Defined in src/av/include/icy/av/audiocontext.h:133

Return true if the given AVSampleFormat is planar.

Parameters

ParameterTypeDescription
formatAVSampleFormatThe AVSampleFormat to check.

createVideoFrame

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

Defined in src/av/include/icy/av/videocontext.h:130

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

Returns

A newly allocated AVFrame, or nullptr on failure.

Parameters

ParameterTypeDescription
pixelFmtAVPixelFormatThe pixel format for the frame.
widthintThe frame width in pixels.
heightintThe frame height in pixels.

cloneVideoFrame

AVFrame * cloneVideoFrame(AVFrame * source)

Defined in src/av/include/icy/av/videocontext.h:135

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

Returns

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

Parameters

ParameterTypeDescription
sourceAVFrame *The source frame to copy.

initVideoCodecFromContext

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

Defined in src/av/include/icy/av/videocontext.h:141

Populate a VideoCodec from an open AVStream and AVCodecContext.

Parameters

ParameterTypeDescription
streamconst AVStream *The AVStream for frame rate information (may be null).
ctxconst AVCodecContext *The FFmpeg codec context to read from.
paramsVideoCodec &The VideoCodec struct to fill with codec, dimension, and format info.

selectPixelFormat

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

Defined in src/av/include/icy/av/videocontext.h:148

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.

Returns

The chosen AVPixelFormat.

Parameters

ParameterTypeDescription
codecconst AVCodec *The FFmpeg codec whose supported formats are queried.
paramsVideoCodec &The video codec parameters specifying the desired pixel format.

parseDeviceUrl

std::optional< std::pair< const AVInputFormat *, std::string > > parseDeviceUrl(std::string_view source)

Defined in src/av/include/icy/av/devicemanager.h:358

Parse a libavdevice URL scheme.

Recognises: avfoundation: (macOS, e.g. "0:0", "0:none") v4l2: (Linux, e.g. "/dev/video0") dshow: (Windows, e.g. "video=Logitech HD WebCam")

On match returns the libavformat input format (looked up via av_find_input_format) and the portion of source after the scheme prefix. Returns std::nullopt for non-device sources (file paths, rtsp://, rtmp://, etc.), leaving the caller to use FFmpeg's auto-detection.

Throws std::runtime_error if a recognised scheme has no matching input format on this build (libavdevice not linked, or the backend is not compiled in on this platform).

Variables

ReturnNameDescription
constexpr intkMaxPlanarAudioPlanes static constexpr

kMaxPlanarAudioPlanes

static constexpr

constexpr int kMaxPlanarAudioPlanes = 8

Defined in src/av/include/icy/av/packet.h:26

Edit this page