Template Class Decoder

Class Documentation

template<MediaType media>
class Decoder

Media decoder for audio, video, or image data.

Decoder converts compressed packets into raw frames using FFmpeg codecs. It supports optional filtering of decoded frames.

Template Parameters:

media – The media type (Audio, Video, or Image).

Public Functions

Decoder(const Codec<media> &codec, const std::optional<DecodeConfig> &cfg, const std::optional<std::string> &filter_desc)

Construct a decoder.

Parameters:
  • codecCodec information for the decoder.

  • cfg – Optional decode configuration.

  • filter_desc – Optional FFmpeg filter description to apply to decoded frames.

Decoder(const Decoder&) = delete

Deleted copy constructor.

Decoder &operator=(const Decoder&) = delete

Deleted copy assignment operator.

Decoder(Decoder&&) = delete

Deleted move constructor.

Decoder &operator=(Decoder&&) = delete

Deleted move assignment operator.

~Decoder()

Destructor.

FramesPtr<media> decode_packets(PacketsPtr<media> packets, int num_frames = -1)

Decode all packets and flush the decoder in one operation.

Parameters:
  • packetsPackets to decode.

  • num_frames – Maximum number of frames to decode. Negative values decode all frames.

Returns:

Decoded frames.

void set_buffer_size(size_t num_frames)

Set the frame buffer size for streaming decode. Effective only for video streaming decoding.

Generator<FramesPtr<media>> streaming_decode_packets(PacketsPtr<media> packets)

Streaming decode packets and yield frames.

This method decodes packets and yields frames as they become ready.

Parameters:

packetsPackets to decode.

Returns:

Generator that yields decoded frames.

Generator<FramesPtr<media>> flush()

Flush the decoder and yield remaining frames.

Call this method at the end of stream to flush the decoder and retrieve any remaining buffered frames.

Returns:

Generator that yields remaining decoded frames.