AudioCodecParameters#
- class torchcodec.decoders.AudioCodecParameters(codec: str, *, time_base: Fraction, extradata: bytes | None = None, codec_tag: int | None = None, profile: int | None = None, level: int | None = None, bit_rate: int | None = None, bits_per_coded_sample: int | None = None, bits_per_raw_sample: int | None = None, coded_side_data: dict[str, bytes] | None = None, sample_format: str | None = None, sample_rate: int | None = None, channel_layout: str | None = None, block_align: int | None = None, frame_size: int | None = None, initial_padding: int | None = None, trailing_padding: int | None = None, seek_preroll: int | None = None)[source]#
What an
AudioPacketDecoderneeds to know to decode the packets of an audio stream.If you have a
Demuxer,AudioStream.codec_parametersgives you the parameters of a stream. They can be pickled, e.g. to build the decoder in another process. To decode packets that don’t come from aDemuxer, build them yourself:codec_parameters = AudioCodecParameters( "aac", time_base=Fraction(1, 48_000), sample_rate=48_000, channel_layout="stereo", extradata=extradata, ) decoder = AudioPacketDecoder(codec_parameters)
The fields mirror those of FFmpeg’s AVCodecParameters, with the same names and meanings. FFmpeg’s names stand for its enums, e.g.
sample_format="fltp".Which fields you need depends on the codec: printing the parameters a
Demuxerreports for a similar file shows what FFmpeg uses.Note
The parameters are meant to be passed to a decoder or stored, not read as metadata: use
AudioStream.metadatafor that. The values aDemuxerreports are FFmpeg’s, and can change across FFmpeg and TorchCodec versions. The fields’ names and meanings are stable.Examples using
AudioCodecParameters:- bits_per_coded_sample: int | None = None#
The number of bits per sample in the compressed data, for the codecs that need it (mostly uncompressed and PCM codecs).
- bits_per_raw_sample: int | None = None#
The number of bits per sample in the decoded data, when it’s not implied by the pixel or sample format, e.g. 10 for 10-bit video.
- block_align: int | None = None#
The number of bytes per coded audio frame, for the codecs that need it (e.g. PCM and ADPCM codecs).
- channel_layout: str | None = None#
FFmpeg’s description of the channel layout, e.g.
"stereo"or"5.1".ffmpeg -layoutslists them.
- codec_tag: int | None = None#
The container’s identifier of the codec, e.g. a FourCC in AVI or MP4. A few codecs read it to tell variants apart.
- coded_side_data: dict[str, bytes] | None = None#
Extra data about the stream, keyed by FFmpeg’s names for its types, e.g.
"Display Matrix"for video or"Replay Gain"for audio.If a video stream has a display matrix, it is under
"Display Matrix"on every FFmpeg version.
- extradata: bytes | None = None#
The codec’s setup data that isn’t in the packets, e.g. the
avcCbox of H.264 in MP4. Not all codecs and streams need it.
- frame_size: int | None = None#
The number of samples per channel in a frame, for the codecs whose frames all have the same size.
- initial_padding: int | None = None#
The number of samples the encoder added at the start of the audio, which aren’t part of the original audio.
- sample_format: str | None = None#
FFmpeg’s name of the decoded samples’ format, e.g.
"fltp".ffmpeg -sample_fmtslists them.