Struct AVCodecContext

#[repr(C)]
pub struct AVCodecContext {
Show 152 fields pub av_class: *const AVClass, pub log_level_offset: i32, pub codec_type: i32, pub codec: *const AVCodec, pub codec_id: u32, pub codec_tag: u32, pub priv_data: *mut c_void, pub internal: *mut AVCodecInternal, pub opaque: *mut c_void, pub bit_rate: i64, pub flags: i32, pub flags2: i32, pub extradata: *mut u8, pub extradata_size: i32, pub time_base: AVRational, pub pkt_timebase: AVRational, pub framerate: AVRational, pub ticks_per_frame: i32, pub delay: i32, pub width: i32, pub height: i32, pub coded_width: i32, pub coded_height: i32, pub sample_aspect_ratio: AVRational, pub pix_fmt: i32, pub sw_pix_fmt: i32, pub color_primaries: u32, pub color_trc: u32, pub colorspace: u32, pub color_range: u32, pub chroma_sample_location: u32, pub field_order: u32, pub refs: i32, pub has_b_frames: i32, pub slice_flags: i32, pub draw_horiz_band: Option<unsafe extern "C" fn(*mut AVCodecContext, *const AVFrame, *mut i32, i32, i32, i32)>, pub get_format: Option<unsafe extern "C" fn(*mut AVCodecContext, *const i32) -> i32>, pub max_b_frames: i32, pub b_quant_factor: f32, pub b_quant_offset: f32, pub i_quant_factor: f32, pub i_quant_offset: f32, pub lumi_masking: f32, pub temporal_cplx_masking: f32, pub spatial_cplx_masking: f32, pub p_masking: f32, pub dark_masking: f32, pub nsse_weight: i32, pub me_cmp: i32, pub me_sub_cmp: i32, pub mb_cmp: i32, pub ildct_cmp: i32, pub dia_size: i32, pub last_predictor_count: i32, pub me_pre_cmp: i32, pub pre_dia_size: i32, pub me_subpel_quality: i32, pub me_range: i32, pub mb_decision: i32, pub intra_matrix: *mut u16, pub inter_matrix: *mut u16, pub chroma_intra_matrix: *mut u16, pub intra_dc_precision: i32, pub mb_lmin: i32, pub mb_lmax: i32, pub bidir_refine: i32, pub keyint_min: i32, pub gop_size: i32, pub mv0_threshold: i32, pub slices: i32, pub sample_rate: i32, pub sample_fmt: i32, pub ch_layout: AVChannelLayout, pub frame_size: i32, pub block_align: i32, pub cutoff: i32, pub audio_service_type: u32, pub request_sample_fmt: i32, pub initial_padding: i32, pub trailing_padding: i32, pub seek_preroll: i32, pub get_buffer2: Option<unsafe extern "C" fn(*mut AVCodecContext, *mut AVFrame, i32) -> i32>, pub bit_rate_tolerance: i32, pub global_quality: i32, pub compression_level: i32, pub qcompress: f32, pub qblur: f32, pub qmin: i32, pub qmax: i32, pub max_qdiff: i32, pub rc_buffer_size: i32, pub rc_override_count: i32, pub rc_override: *mut RcOverride, pub rc_max_rate: i64, pub rc_min_rate: i64, pub rc_max_available_vbv_use: f32, pub rc_min_vbv_overflow_use: f32, pub rc_initial_buffer_occupancy: i32, pub trellis: i32, pub stats_out: *mut i8, pub stats_in: *mut i8, pub workaround_bugs: i32, pub strict_std_compliance: i32, pub error_concealment: i32, pub debug: i32, pub err_recognition: i32, pub hwaccel: *const AVHWAccel, pub hwaccel_context: *mut c_void, pub hw_frames_ctx: *mut AVBufferRef, pub hw_device_ctx: *mut AVBufferRef, pub hwaccel_flags: i32, pub extra_hw_frames: i32, pub error: [u64; 8], pub dct_algo: i32, pub idct_algo: i32, pub bits_per_coded_sample: i32, pub bits_per_raw_sample: i32, pub thread_count: i32, pub thread_type: i32, pub active_thread_type: i32, pub execute: Option<unsafe extern "C" fn(*mut AVCodecContext, Option<unsafe extern "C" fn(*mut AVCodecContext, *mut c_void) -> i32>, *mut c_void, *mut i32, i32, i32) -> i32>, pub execute2: Option<unsafe extern "C" fn(*mut AVCodecContext, Option<unsafe extern "C" fn(*mut AVCodecContext, *mut c_void, i32, i32) -> i32>, *mut c_void, *mut i32, i32) -> i32>, pub profile: i32, pub level: i32, pub properties: u32, pub skip_loop_filter: i32, pub skip_idct: i32, pub skip_frame: i32, pub skip_alpha: i32, pub skip_top: i32, pub skip_bottom: i32, pub lowres: i32, pub codec_descriptor: *const AVCodecDescriptor, pub sub_charenc: *mut i8, pub sub_charenc_mode: i32, pub subtitle_header_size: i32, pub subtitle_header: *mut u8, pub dump_separator: *mut u8, pub codec_whitelist: *mut i8, pub coded_side_data: *mut AVPacketSideData, pub nb_coded_side_data: i32, pub export_side_data: i32, pub max_pixels: i64, pub apply_cropping: i32, pub discard_damaged_percentage: i32, pub max_samples: i64, pub get_encode_buffer: Option<unsafe extern "C" fn(*mut AVCodecContext, *mut AVPacket, i32) -> i32>, pub frame_num: i64, pub side_data_prefer_packet: *mut i32, pub nb_side_data_prefer_packet: u32, pub decoded_side_data: *mut *mut AVFrameSideData, pub nb_decoded_side_data: i32,
}
Expand description

main external API structure. New fields can be added to the end with minor version bumps. Removal, reordering and changes to existing fields require a major version bump. You can use AVOptions (av_opt* / av_set/get*()) to access these fields from user applications. The name string for AVOptions options matches the associated command line parameter name and can be found in libavcodec/options_table.h The AVOption/command line parameter names differ in some cases from the C structure field names for historic reasons or brevity. sizeof(AVCodecContext) must not be used outside libav*.

Fields§

§av_class: *const AVClass

information on struct for av_log

  • set by avcodec_alloc_context3
§log_level_offset: i32§codec_type: i32§codec: *const AVCodec§codec_id: u32§codec_tag: u32

fourcc (LSB first, so “ABCD” -> (‘D’<<24) + (‘C’<<16) + (‘B’<<8) + ‘A’). This is used to work around some encoder bugs. A demuxer should set this to what is stored in the field used to identify the codec. If there are multiple such fields in a container then the demuxer should choose the one which maximizes the information about the used codec. If the codec tag field in a container is larger than 32 bits then the demuxer should remap the longer ID to 32 bits with a table or other structure. Alternatively a new extra_codec_tag + size could be added but for this a clear advantage must be demonstrated first.

  • encoding: Set by user, if not then the default based on codec_id will be used.
  • decoding: Set by user, will be converted to uppercase by libavcodec during init.
§priv_data: *mut c_void§internal: *mut AVCodecInternal

Private context used for internal data.

Unlike priv_data, this is not codec-specific. It is used in general libavcodec functions.

§opaque: *mut c_void

Private data of the user, can be used to carry app specific stuff.

  • encoding: Set by user.
  • decoding: Set by user.
§bit_rate: i64

the average bitrate

  • encoding: Set by user; unused for constant quantizer encoding.
  • decoding: Set by user, may be overwritten by libavcodec if this info is available in the stream
§flags: i32

AV_CODEC_FLAG_*.

  • encoding: Set by user.
  • decoding: Set by user.
§flags2: i32

AV_CODEC_FLAG2_*

  • encoding: Set by user.
  • decoding: Set by user.
§extradata: *mut u8

some codecs need / can use extradata like Huffman tables. MJPEG: Huffman tables rv10: additional flags MPEG-4: global headers (they can be in the bitstream or here) The allocated memory should be AV_INPUT_BUFFER_PADDING_SIZE bytes larger than extradata_size to avoid problems if it is read with the bitstream reader. The bytewise contents of extradata must not depend on the architecture or CPU endianness. Must be allocated with the av_malloc() family of functions.

  • encoding: Set/allocated/freed by libavcodec.
  • decoding: Set/allocated/freed by user.
§extradata_size: i32§time_base: AVRational

This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented. For fixed-fps content, timebase should be 1/framerate and timestamp increments should be identically 1. This often, but not always is the inverse of the frame rate or field rate for video. 1/time_base is not the average frame rate if the frame rate is not constant.

Like containers, elementary streams also can store timestamps, 1/time_base is the unit in which these timestamps are specified. As example of such codec time base see ISO/IEC 14496-2:2001(E) vop_time_increment_resolution and fixed_vop_rate (fixed_vop_rate == 0 implies that it is different from the framerate)

  • encoding: MUST be set by user.
  • decoding: unused.
§pkt_timebase: AVRational

Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.

  • encoding: unused.
  • decoding: set by user.
§framerate: AVRational
  • decoding: For codecs that store a framerate value in the compressed bitstream, the decoder may export it here. { 0, 1} when unknown.
  • encoding: May be used to signal the framerate of CFR content to an encoder.
§ticks_per_frame: i32

For some codecs, the time base is closer to the field rate than the frame rate. Most notably, H.264 and MPEG-2 specify time_base as half of frame duration if no telecine is used …

Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.

@deprecated

  • decoding: Use AVCodecDescriptor.props & AV_CODEC_PROP_FIELDS
  • encoding: Set AVCodecContext.framerate instead
§delay: i32

Codec delay.

Encoding: Number of frames delay there will be from the encoder input to the decoder output. (we assume the decoder matches the spec) Decoding: Number of frames delay in addition to what a standard decoder as specified in the spec would produce.

Video: Number of frames the decoded output will be delayed relative to the encoded input.

Audio: For encoding, this field is unused (see initial_padding).

For decoding, this is the number of samples the decoder needs to output before the decoder’s output is valid. When seeking, you should start decoding this many samples prior to your desired seek point.

  • encoding: Set by libavcodec.
  • decoding: Set by libavcodec.
§width: i32

picture width / height.

@note Those fields may not match the values of the last AVFrame output by avcodec_receive_frame() due frame reordering.

  • encoding: MUST be set by user.
  • decoding: May be set by the user before opening the decoder if known e.g. from the container. Some decoders will require the dimensions to be set by the caller. During decoding, the decoder may overwrite those values as required while parsing the data.
§height: i32

picture width / height.

@note Those fields may not match the values of the last AVFrame output by avcodec_receive_frame() due frame reordering.

  • encoding: MUST be set by user.
  • decoding: May be set by the user before opening the decoder if known e.g. from the container. Some decoders will require the dimensions to be set by the caller. During decoding, the decoder may overwrite those values as required while parsing the data.
§coded_width: i32

Bitstream width / height, may be different from width/height e.g. when the decoded frame is cropped before being output or lowres is enabled.

@note Those field may not match the value of the last AVFrame output by avcodec_receive_frame() due frame reordering.

  • encoding: unused
  • decoding: May be set by the user before opening the decoder if known e.g. from the container. During decoding, the decoder may overwrite those values as required while parsing the data.
§coded_height: i32

Bitstream width / height, may be different from width/height e.g. when the decoded frame is cropped before being output or lowres is enabled.

@note Those field may not match the value of the last AVFrame output by avcodec_receive_frame() due frame reordering.

  • encoding: unused
  • decoding: May be set by the user before opening the decoder if known e.g. from the container. During decoding, the decoder may overwrite those values as required while parsing the data.
§sample_aspect_ratio: AVRational

sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel. Numerator and denominator must be relatively prime and smaller than 256 for some video standards.

  • encoding: Set by user.
  • decoding: Set by libavcodec.
§pix_fmt: i32

Pixel format, see AV_PIX_FMT_xxx. May be set by the demuxer if known from headers. May be overridden by the decoder if it knows better.

@note This field may not match the value of the last AVFrame output by avcodec_receive_frame() due frame reordering.

  • encoding: Set by user.
  • decoding: Set by user if known, overridden by libavcodec while parsing the data.
§sw_pix_fmt: i32

Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.

  • encoding: unused.
  • decoding: Set by libavcodec before calling get_format()
§color_primaries: u32

Chromaticity coordinates of the source primaries.

  • encoding: Set by user
  • decoding: Set by libavcodec
§color_trc: u32

Color Transfer Characteristic.

  • encoding: Set by user
  • decoding: Set by libavcodec
§colorspace: u32

YUV colorspace type.

  • encoding: Set by user
  • decoding: Set by libavcodec
§color_range: u32

MPEG vs JPEG YUV range.

  • encoding: Set by user to override the default output color range value, If not specified, libavcodec sets the color range depending on the output format.
  • decoding: Set by libavcodec, can be set by the user to propagate the color range to components reading from the decoder context.
§chroma_sample_location: u32

This defines the location of chroma samples.

  • encoding: Set by user
  • decoding: Set by libavcodec
§field_order: u32

Field order

  • encoding: set by libavcodec
  • decoding: Set by user.
§refs: i32

number of reference frames

  • encoding: Set by user.
  • decoding: Set by lavc.
§has_b_frames: i32

Size of the frame reordering buffer in the decoder. For MPEG-2 it is 1 IPB or 0 low delay IP.

  • encoding: Set by libavcodec.
  • decoding: Set by libavcodec.
§slice_flags: i32

slice flags

  • encoding: unused
  • decoding: Set by user.
§draw_horiz_band: Option<unsafe extern "C" fn(*mut AVCodecContext, *const AVFrame, *mut i32, i32, i32, i32)>

If non NULL, ‘draw_horiz_band’ is called by the libavcodec decoder to draw a horizontal band. It improves cache usage. Not all codecs can do that. You must check the codec capabilities beforehand. When multithreading is used, it may be called from multiple threads at the same time; threads might draw different parts of the same AVFrame, or multiple AVFrames, and there is no guarantee that slices will be drawn in order. The function is also used by hardware acceleration APIs. It is called at least once during frame decoding to pass the data needed for hardware render. In that mode instead of pixel data, AVFrame points to a structure specific to the acceleration API. The application reads the structure and can change some fields to indicate progress or mark state.

  • encoding: unused
  • decoding: Set by user. @param height the height of the slice @param y the y position of the slice @param type 1->top field, 2->bottom field, 3->frame @param offset offset into the AVFrame.data from which the slice should be read
§get_format: Option<unsafe extern "C" fn(*mut AVCodecContext, *const i32) -> i32>

Callback to negotiate the pixel format. Decoding only, may be set by the caller before avcodec_open2().

Called by some decoders to select the pixel format that will be used for the output frames. This is mainly used to set up hardware acceleration, then the provided format list contains the corresponding hwaccel pixel formats alongside the “software” one. The software pixel format may also be retrieved from \ref sw_pix_fmt.

This callback will be called when the coded frame properties (such as resolution, pixel format, etc.) change and more than one output format is supported for those new properties. If a hardware pixel format is chosen and initialization for it fails, the callback may be called again immediately.

This callback may be called from different threads if the decoder is multi-threaded, but not from more than one thread simultaneously.

@param fmt list of formats which may be used in the current configuration, terminated by AV_PIX_FMT_NONE. @warning Behavior is undefined if the callback returns a value other than one of the formats in fmt or AV_PIX_FMT_NONE. @return the chosen format or AV_PIX_FMT_NONE

§max_b_frames: i32

maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 relative to the input.

  • encoding: Set by user.
  • decoding: unused
§b_quant_factor: f32

qscale factor between IP and B-frames If > 0 then the last P-frame quantizer will be used (q= lastp_qfactor+offset). If < 0 then normal ratecontrol will be done (q= -normal_qfactor+offset).

  • encoding: Set by user.
  • decoding: unused
§b_quant_offset: f32

qscale offset between IP and B-frames

  • encoding: Set by user.
  • decoding: unused
§i_quant_factor: f32

qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_q * factor + offset). If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).

  • encoding: Set by user.
  • decoding: unused
§i_quant_offset: f32

qscale offset between P and I-frames

  • encoding: Set by user.
  • decoding: unused
§lumi_masking: f32

luminance masking (0-> disabled)

  • encoding: Set by user.
  • decoding: unused
§temporal_cplx_masking: f32

temporary complexity masking (0-> disabled)

  • encoding: Set by user.
  • decoding: unused
§spatial_cplx_masking: f32

spatial complexity masking (0-> disabled)

  • encoding: Set by user.
  • decoding: unused
§p_masking: f32

p block masking (0-> disabled)

  • encoding: Set by user.
  • decoding: unused
§dark_masking: f32

darkness masking (0-> disabled)

  • encoding: Set by user.
  • decoding: unused
§nsse_weight: i32

noise vs. sse weight for the nsse comparison function

  • encoding: Set by user.
  • decoding: unused
§me_cmp: i32

motion estimation comparison function

  • encoding: Set by user.
  • decoding: unused
§me_sub_cmp: i32

subpixel motion estimation comparison function

  • encoding: Set by user.
  • decoding: unused
§mb_cmp: i32

macroblock comparison function (not supported yet)

  • encoding: Set by user.
  • decoding: unused
§ildct_cmp: i32

interlaced DCT comparison function

  • encoding: Set by user.
  • decoding: unused
§dia_size: i32

ME diamond size & shape

  • encoding: Set by user.
  • decoding: unused
§last_predictor_count: i32

amount of previous MV predictors (2a+1 x 2a+1 square)

  • encoding: Set by user.
  • decoding: unused
§me_pre_cmp: i32

motion estimation prepass comparison function

  • encoding: Set by user.
  • decoding: unused
§pre_dia_size: i32

ME prepass diamond size & shape

  • encoding: Set by user.
  • decoding: unused
§me_subpel_quality: i32

subpel ME quality

  • encoding: Set by user.
  • decoding: unused
§me_range: i32

maximum motion estimation search range in subpel units If 0 then no limit.

  • encoding: Set by user.
  • decoding: unused
§mb_decision: i32

macroblock decision mode

  • encoding: Set by user.
  • decoding: unused
§intra_matrix: *mut u16

custom intra quantization matrix Must be allocated with the av_malloc() family of functions, and will be freed in avcodec_free_context().

  • encoding: Set/allocated by user, freed by libavcodec. Can be NULL.
  • decoding: Set/allocated/freed by libavcodec.
§inter_matrix: *mut u16

custom inter quantization matrix Must be allocated with the av_malloc() family of functions, and will be freed in avcodec_free_context().

  • encoding: Set/allocated by user, freed by libavcodec. Can be NULL.
  • decoding: Set/allocated/freed by libavcodec.
§chroma_intra_matrix: *mut u16

custom intra quantization matrix

  • encoding: Set by user, can be NULL.
  • decoding: unused.
§intra_dc_precision: i32

precision of the intra DC coefficient - 8

  • encoding: Set by user.
  • decoding: Set by libavcodec
§mb_lmin: i32

minimum MB Lagrange multiplier

  • encoding: Set by user.
  • decoding: unused
§mb_lmax: i32

maximum MB Lagrange multiplier

  • encoding: Set by user.
  • decoding: unused
§bidir_refine: i32
  • encoding: Set by user.
  • decoding: unused
§keyint_min: i32

minimum GOP size

  • encoding: Set by user.
  • decoding: unused
§gop_size: i32

the number of pictures in a group of pictures, or 0 for intra_only

  • encoding: Set by user.
  • decoding: unused
§mv0_threshold: i32

Note: Value depends upon the compare function used for fullpel ME.

  • encoding: Set by user.
  • decoding: unused
§slices: i32

Number of slices. Indicates number of picture subdivisions. Used for parallelized decoding.

  • encoding: Set by user
  • decoding: unused
§sample_rate: i32

< samples per second

§sample_fmt: i32

< sample format

§ch_layout: AVChannelLayout

Audio channel layout.

  • encoding: must be set by the caller, to one of AVCodec.ch_layouts.
  • decoding: may be set by the caller if known e.g. from the container. The decoder can then override during decoding as needed.
§frame_size: i32

Number of samples per channel in an audio frame.

  • encoding: set by libavcodec in avcodec_open2(). Each submitted frame except the last must contain exactly frame_size samples per channel. May be 0 when the codec has AV_CODEC_CAP_VARIABLE_FRAME_SIZE set, then the frame size is not restricted.
  • decoding: may be set by some decoders to indicate constant frame size
§block_align: i32

number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.

§cutoff: i32

Audio cutoff bandwidth (0 means “automatic”)

  • encoding: Set by user.
  • decoding: unused
§audio_service_type: u32

Type of service that the audio stream conveys.

  • encoding: Set by user.
  • decoding: Set by libavcodec.
§request_sample_fmt: i32

desired sample format

  • encoding: Not used.
  • decoding: Set by user. Decoder will decode to this format if it can.
§initial_padding: i32

Audio only. The number of “priming” samples (padding) inserted by the encoder at the beginning of the audio. I.e. this number of leading decoded samples must be discarded by the caller to get the original audio without leading padding.

  • decoding: unused
  • encoding: Set by libavcodec. The timestamps on the output packets are adjusted by the encoder so that they always refer to the first sample of the data actually contained in the packet, including any added padding. E.g. if the timebase is 1/samplerate and the timestamp of the first input sample is 0, the timestamp of the first output packet will be -initial_padding.
§trailing_padding: i32

Audio only. The amount of padding (in samples) appended by the encoder to the end of the audio. I.e. this number of decoded samples must be discarded by the caller from the end of the stream to get the original audio without any trailing padding.

  • decoding: unused
  • encoding: unused
§seek_preroll: i32

Number of samples to skip after a discontinuity

  • decoding: unused
  • encoding: set by libavcodec
§get_buffer2: Option<unsafe extern "C" fn(*mut AVCodecContext, *mut AVFrame, i32) -> i32>

This callback is called at the beginning of each frame to get data buffer(s) for it. There may be one contiguous buffer for all the data or there may be a buffer per each data plane or anything in between. What this means is, you may set however many entries in buf[] you feel necessary. Each buffer must be reference-counted using the AVBuffer API (see description of buf[] below).

The following fields will be set in the frame before this callback is called:

  • format
  • width, height (video only)
  • sample_rate, channel_layout, nb_samples (audio only) Their values may differ from the corresponding values in AVCodecContext. This callback must use the frame values, not the codec context values, to calculate the required buffer size.

This callback must fill the following fields in the frame:

  • data[]
  • linesize[]
  • extended_data:
    • if the data is planar audio with more than 8 channels, then this callback must allocate and fill extended_data to contain all pointers to all data planes. data[] must hold as many pointers as it can. extended_data must be allocated with av_malloc() and will be freed in av_frame_unref().
    • otherwise extended_data must point to data
  • buf[] must contain one or more pointers to AVBufferRef structures. Each of the frame’s data and extended_data pointers must be contained in these. That is, one AVBufferRef for each allocated chunk of memory, not necessarily one AVBufferRef per data[] entry. See: av_buffer_create(), av_buffer_alloc(), and av_buffer_ref().
  • extended_buf and nb_extended_buf must be allocated with av_malloc() by this callback and filled with the extra buffers if there are more buffers than buf[] can hold. extended_buf will be freed in av_frame_unref(). Decoders will generally initialize the whole buffer before it is output but it can in rare error conditions happen that uninitialized data is passed through. \important The buffers returned by get_buffer* should thus not contain sensitive data.

If AV_CODEC_CAP_DR1 is not set then get_buffer2() must call avcodec_default_get_buffer2() instead of providing buffers allocated by some other means.

Each data plane must be aligned to the maximum required by the target CPU.

@see avcodec_default_get_buffer2()

Video:

If AV_GET_BUFFER_FLAG_REF is set in flags then the frame may be reused (read and/or written to if it is writable) later by libavcodec.

avcodec_align_dimensions2() should be used to find the required width and height, as they normally need to be rounded up to the next multiple of 16.

Some decoders do not support linesizes changing between frames.

If frame multithreading is used, this callback may be called from a different thread, but not from more than one at once. Does not need to be reentrant.

@see avcodec_align_dimensions2()

Audio:

Decoders request a buffer of a particular size by setting AVFrame.nb_samples prior to calling get_buffer2(). The decoder may, however, utilize only part of the buffer by setting AVFrame.nb_samples to a smaller value in the output frame.

As a convenience, av_samples_get_buffer_size() and av_samples_fill_arrays() in libavutil may be used by custom get_buffer2() functions to find the required data size and to fill data pointers and linesize. In AVFrame.linesize, only linesize[0] may be set for audio since all planes must be the same size.

@see av_samples_get_buffer_size(), av_samples_fill_arrays()

  • encoding: unused
  • decoding: Set by libavcodec, user can override.
§bit_rate_tolerance: i32

number of bits the bitstream is allowed to diverge from the reference. the reference can be CBR (for CBR pass1) or VBR (for pass2)

  • encoding: Set by user; unused for constant quantizer encoding.
  • decoding: unused
§global_quality: i32

Global quality for codecs which cannot change it per frame. This should be proportional to MPEG-1/2/4 qscale.

  • encoding: Set by user.
  • decoding: unused
§compression_level: i32
  • encoding: Set by user.
  • decoding: unused
§qcompress: f32

< amount of qscale change between easy & hard scenes (0.0-1.0)

§qblur: f32

< amount of qscale smoothing over time (0.0-1.0)

§qmin: i32

minimum quantizer

  • encoding: Set by user.
  • decoding: unused
§qmax: i32

maximum quantizer

  • encoding: Set by user.
  • decoding: unused
§max_qdiff: i32

maximum quantizer difference between frames

  • encoding: Set by user.
  • decoding: unused
§rc_buffer_size: i32

decoder bitstream buffer size

  • encoding: Set by user.
  • decoding: May be set by libavcodec.
§rc_override_count: i32

ratecontrol override, see RcOverride

  • encoding: Allocated/set/freed by user.
  • decoding: unused
§rc_override: *mut RcOverride§rc_max_rate: i64

maximum bitrate

  • encoding: Set by user.
  • decoding: Set by user, may be overwritten by libavcodec.
§rc_min_rate: i64

minimum bitrate

  • encoding: Set by user.
  • decoding: unused
§rc_max_available_vbv_use: f32

Ratecontrol attempt to use, at maximum, of what can be used without an underflow.

  • encoding: Set by user.
  • decoding: unused.
§rc_min_vbv_overflow_use: f32

Ratecontrol attempt to use, at least, times the amount needed to prevent a vbv overflow.

  • encoding: Set by user.
  • decoding: unused.
§rc_initial_buffer_occupancy: i32

Number of bits which should be loaded into the rc buffer before decoding starts.

  • encoding: Set by user.
  • decoding: unused
§trellis: i32

trellis RD quantization

  • encoding: Set by user.
  • decoding: unused
§stats_out: *mut i8

pass1 encoding statistics output buffer

  • encoding: Set by libavcodec.
  • decoding: unused
§stats_in: *mut i8

pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed here.

  • encoding: Allocated/set/freed by user.
  • decoding: unused
§workaround_bugs: i32

Work around bugs in encoders which sometimes cannot be detected automatically.

  • encoding: Set by user
  • decoding: Set by user
§strict_std_compliance: i32

strictly follow the standard (MPEG-4, …).

  • encoding: Set by user.
  • decoding: Set by user. Setting this to STRICT or higher means the encoder and decoder will generally do stupid things, whereas setting it to unofficial or lower will mean the encoder might produce output that is not supported by all spec-compliant decoders. Decoders don’t differentiate between normal, unofficial and experimental (that is, they always try to decode things when they can) unless they are explicitly asked to behave stupidly (=strictly conform to the specs) This may only be set to one of the FF_COMPLIANCE_* values in defs.h.
§error_concealment: i32

error concealment flags

  • encoding: unused
  • decoding: Set by user.
§debug: i32

debug

  • encoding: Set by user.
  • decoding: Set by user.
§err_recognition: i32

Error recognition; may misdetect some more or less valid parts as errors. This is a bitfield of the AV_EF_* values defined in defs.h.

  • encoding: Set by user.
  • decoding: Set by user.
§hwaccel: *const AVHWAccel

Hardware accelerator in use

  • encoding: unused.
  • decoding: Set by libavcodec
§hwaccel_context: *mut c_void

Legacy hardware accelerator context.

For some hardware acceleration methods, the caller may use this field to signal hwaccel-specific data to the codec. The struct pointed to by this pointer is hwaccel-dependent and defined in the respective header. Please refer to the FFmpeg HW accelerator documentation to know how to fill this.

In most cases this field is optional - the necessary information may also be provided to libavcodec through @ref hw_frames_ctx or @ref hw_device_ctx (see avcodec_get_hw_config()). However, in some cases it may be the only method of signalling some (optional) information.

The struct and its contents are owned by the caller.

  • encoding: May be set by the caller before avcodec_open2(). Must remain valid until avcodec_free_context().
  • decoding: May be set by the caller in the get_format() callback. Must remain valid until the next get_format() call, or avcodec_free_context() (whichever comes first).
§hw_frames_ctx: *mut AVBufferRef

A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames. The reference is set by the caller and afterwards owned (and freed) by libavcodec - it should never be read by the caller after being set.

  • decoding: This field should be set by the caller from the get_format() callback. The previous reference (if any) will always be unreffed by libavcodec before the get_format() call.

          If the default get_buffer2() is used with a hwaccel pixel
          format, then this AVHWFramesContext will be used for
          allocating the frame buffers.
  • encoding: For hardware encoders configured to use a hwaccel pixel format, this field should be set by the caller to a reference to the AVHWFramesContext describing input frames. AVHWFramesContext.format must be equal to AVCodecContext.pix_fmt.

          This field should be set before avcodec_open2() is called.
§hw_device_ctx: *mut AVBufferRef

A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/decoder. The reference is set by the caller and afterwards owned (and freed) by libavcodec.

This should be used if either the codec device does not require hardware frames or any that are used are to be allocated internally by libavcodec. If the user wishes to supply any of the frames used as encoder input or decoder output then hw_frames_ctx should be used instead. When hw_frames_ctx is set in get_format() for a decoder, this field will be ignored while decoding the associated stream segment, but may again be used on a following one after another get_format() call.

For both encoders and decoders this field should be set before avcodec_open2() is called and must not be written to thereafter.

Note that some decoders may require this field to be set initially in order to support hw_frames_ctx at all - in that case, all frames contexts used must be created on the same device.

§hwaccel_flags: i32

Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated decoding (if active).

  • encoding: unused
  • decoding: Set by user (either before avcodec_open2(), or in the AVCodecContext.get_format callback)
§extra_hw_frames: i32

Video decoding only. Sets the number of extra hardware frames which the decoder will allocate for use by the caller. This must be set before avcodec_open2() is called.

Some hardware decoders require all frames that they will use for output to be defined in advance before decoding starts. For such decoders, the hardware frame pool must therefore be of a fixed size. The extra frames set here are on top of any number that the decoder needs internally in order to operate normally (for example, frames used as reference pictures).

§error: [u64; 8]

error

  • encoding: Set by libavcodec if flags & AV_CODEC_FLAG_PSNR.
  • decoding: unused
§dct_algo: i32

DCT algorithm, see FF_DCT_* below

  • encoding: Set by user.
  • decoding: unused
§idct_algo: i32

IDCT algorithm, see FF_IDCT_* below.

  • encoding: Set by user.
  • decoding: Set by user.
§bits_per_coded_sample: i32

bits per sample/pixel from the demuxer (needed for huffyuv).

  • encoding: Set by libavcodec.
  • decoding: Set by user.
§bits_per_raw_sample: i32

Bits per sample/pixel of internal libavcodec pixel/sample format.

  • encoding: set by user.
  • decoding: set by libavcodec.
§thread_count: i32

thread count is used to decide how many independent tasks should be passed to execute()

  • encoding: Set by user.
  • decoding: Set by user.
§thread_type: i32

Which multithreading methods to use. Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread, so clients which cannot provide future frames should not use it.

  • encoding: Set by user, otherwise the default is used.
  • decoding: Set by user, otherwise the default is used.
§active_thread_type: i32

Which multithreading methods are in use by the codec.

  • encoding: Set by libavcodec.
  • decoding: Set by libavcodec.
§execute: Option<unsafe extern "C" fn(*mut AVCodecContext, Option<unsafe extern "C" fn(*mut AVCodecContext, *mut c_void) -> i32>, *mut c_void, *mut i32, i32, i32) -> i32>

The codec may call this to execute several independent things. It will return only after finishing all tasks. The user may replace this with some multithreaded implementation, the default implementation will execute the parts serially. @param count the number of things to execute

  • encoding: Set by libavcodec, user can override.
  • decoding: Set by libavcodec, user can override.
§execute2: Option<unsafe extern "C" fn(*mut AVCodecContext, Option<unsafe extern "C" fn(*mut AVCodecContext, *mut c_void, i32, i32) -> i32>, *mut c_void, *mut i32, i32) -> i32>

The codec may call this to execute several independent things. It will return only after finishing all tasks. The user may replace this with some multithreaded implementation, the default implementation will execute the parts serially. @param c context passed also to func @param count the number of things to execute @param arg2 argument passed unchanged to func @param ret return values of executed functions, must have space for “count” values. May be NULL. @param func function that will be called count times, with jobnr from 0 to count-1. threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no two instances of func executing at the same time will have the same threadnr. @return always 0 currently, but code should handle a future improvement where when any call to func returns < 0 no further calls to func may be done and < 0 is returned.

  • encoding: Set by libavcodec, user can override.
  • decoding: Set by libavcodec, user can override.
§profile: i32

profile

  • encoding: Set by user.
  • decoding: Set by libavcodec. See the AV_PROFILE_* defines in defs.h.
§level: i32

Encoding level descriptor.

  • encoding: Set by user, corresponds to a specific level defined by the codec, usually corresponding to the profile level, if not specified it is set to FF_LEVEL_UNKNOWN.
  • decoding: Set by libavcodec. See AV_LEVEL_* in defs.h.
§properties: u32

Properties of the stream that gets decoded

  • encoding: unused
  • decoding: set by libavcodec
§skip_loop_filter: i32

Skip loop filtering for selected frames.

  • encoding: unused
  • decoding: Set by user.
§skip_idct: i32

Skip IDCT/dequantization for selected frames.

  • encoding: unused
  • decoding: Set by user.
§skip_frame: i32

Skip decoding for selected frames.

  • encoding: unused
  • decoding: Set by user.
§skip_alpha: i32

Skip processing alpha if supported by codec. Note that if the format uses pre-multiplied alpha (common with VP6, and recommended due to better video quality/compression) the image will look as if alpha-blended onto a black background. However for formats that do not use pre-multiplied alpha there might be serious artefacts (though e.g. libswscale currently assumes pre-multiplied alpha anyway).

  • decoding: set by user
  • encoding: unused
§skip_top: i32

Number of macroblock rows at the top which are skipped.

  • encoding: unused
  • decoding: Set by user.
§skip_bottom: i32

Number of macroblock rows at the bottom which are skipped.

  • encoding: unused
  • decoding: Set by user.
§lowres: i32

low resolution decoding, 1-> 1/2 size, 2->1/4 size

  • encoding: unused
  • decoding: Set by user.
§codec_descriptor: *const AVCodecDescriptor

AVCodecDescriptor

  • encoding: unused.
  • decoding: set by libavcodec.
§sub_charenc: *mut i8

Character encoding of the input subtitles file.

  • decoding: set by user
  • encoding: unused
§sub_charenc_mode: i32

Subtitles character encoding mode. Formats or codecs might be adjusting this setting (if they are doing the conversion themselves for instance).

  • decoding: set by libavcodec
  • encoding: unused
§subtitle_header_size: i32

Header containing style information for text subtitles. For SUBTITLE_ASS subtitle type, it should contain the whole ASS [Script Info] and [V4+ Styles] section, plus the [Events] line and the Format line following. It shouldn’t include any Dialogue line.

  • encoding: Set/allocated/freed by user (before avcodec_open2())
  • decoding: Set/allocated/freed by libavcodec (by avcodec_open2())
§subtitle_header: *mut u8§dump_separator: *mut u8

dump format separator. can be “, “ or “\n “ or anything else

  • encoding: Set by user.
  • decoding: Set by user.
§codec_whitelist: *mut i8

‘,’ separated list of allowed decoders. If NULL then all are allowed

  • encoding: unused
  • decoding: set by user
§coded_side_data: *mut AVPacketSideData

Additional data associated with the entire coded stream.

  • decoding: may be set by user before calling avcodec_open2().
  • encoding: may be set by libavcodec after avcodec_open2().
§nb_coded_side_data: i32§export_side_data: i32

Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame, packet, or coded stream side data by decoders and encoders.

  • decoding: set by user
  • encoding: set by user
§max_pixels: i64

The number of pixels per image to maximally accept.

  • decoding: set by user
  • encoding: set by user
§apply_cropping: i32

Video decoding only. Certain video codecs support cropping, meaning that only a sub-rectangle of the decoded frame is intended for display. This option controls how cropping is handled by libavcodec.

When set to 1 (the default), libavcodec will apply cropping internally. I.e. it will modify the output frame width/height fields and offset the data pointers (only by as much as possible while preserving alignment, or by the full amount if the AV_CODEC_FLAG_UNALIGNED flag is set) so that the frames output by the decoder refer only to the cropped area. The crop_* fields of the output frames will be zero.

When set to 0, the width/height fields of the output frames will be set to the coded dimensions and the crop_* fields will describe the cropping rectangle. Applying the cropping is left to the caller.

@warning When hardware acceleration with opaque output frames is used, libavcodec is unable to apply cropping from the top/left border.

@note when this option is set to zero, the width/height fields of the AVCodecContext and output AVFrames have different meanings. The codec context fields store display dimensions (with the coded dimensions in coded_width/height), while the frame fields store the coded dimensions (with the display dimensions being determined by the crop_* fields).

§discard_damaged_percentage: i32

The percentage of damaged samples to discard a frame.

  • decoding: set by user
  • encoding: unused
§max_samples: i64

The number of samples per frame to maximally accept.

  • decoding: set by user
  • encoding: set by user
§get_encode_buffer: Option<unsafe extern "C" fn(*mut AVCodecContext, *mut AVPacket, i32) -> i32>

This callback is called at the beginning of each packet to get a data buffer for it.

The following field will be set in the packet before this callback is called:

  • size This callback must use the above value to calculate the required buffer size, which must padded by at least AV_INPUT_BUFFER_PADDING_SIZE bytes.

In some specific cases, the encoder may not use the entire buffer allocated by this callback. This will be reflected in the size value in the packet once returned by avcodec_receive_packet().

This callback must fill the following fields in the packet:

  • data: alignment requirements for AVPacket apply, if any. Some architectures and encoders may benefit from having aligned data.
  • buf: must contain a pointer to an AVBufferRef structure. The packet’s data pointer must be contained in it. See: av_buffer_create(), av_buffer_alloc(), and av_buffer_ref().

If AV_CODEC_CAP_DR1 is not set then get_encode_buffer() must call avcodec_default_get_encode_buffer() instead of providing a buffer allocated by some other means.

The flags field may contain a combination of AV_GET_ENCODE_BUFFER_FLAG_ flags. They may be used for example to hint what use the buffer may get after being created. Implementations of this callback may ignore flags they don’t understand. If AV_GET_ENCODE_BUFFER_FLAG_REF is set in flags then the packet may be reused (read and/or written to if it is writable) later by libavcodec.

This callback must be thread-safe, as when frame threading is used, it may be called from multiple threads simultaneously.

@see avcodec_default_get_encode_buffer()

  • encoding: Set by libavcodec, user can override.
  • decoding: unused
§frame_num: i64

Frame counter, set by libavcodec.

  • decoding: total number of frames returned from the decoder so far.

  • encoding: total number of frames passed to the encoder so far.

    @note the counter is not incremented if encoding/decoding resulted in an error.

§side_data_prefer_packet: *mut i32

Decoding only. May be set by the caller before avcodec_open2() to an av_malloc()’ed array (or via AVOptions). Owned and freed by the decoder afterwards.

Side data attached to decoded frames may come from several sources:

  1. coded_side_data, which the decoder will for certain types translate from packet-type to frame-type and attach to frames;
  2. side data attached to an AVPacket sent for decoding (same considerations as above);
  3. extracted from the coded bytestream. The first two cases are supplied by the caller and typically come from a container.

This array configures decoder behaviour in cases when side data of the same type is present both in the coded bytestream and in the user-supplied side data (items 1. and 2. above). In all cases, at most one instance of each side data type will be attached to output frames. By default it will be the bytestream side data. Adding an AVPacketSideDataType value to this array will flip the preference for this type, thus making the decoder prefer user-supplied side data over bytestream. In case side data of the same type is present both in coded_data and attacked to a packet, the packet instance always has priority.

The array may also contain a single -1, in which case the preference is switched for all side data types.

§nb_side_data_prefer_packet: u32

Number of entries in side_data_prefer_packet.

§decoded_side_data: *mut *mut AVFrameSideData

Array containing static side data, such as HDR10 CLL / MDCV structures. Side data entries should be allocated by usage of helpers defined in libavutil/frame.h.

  • encoding: may be set by user before calling avcodec_open2() for encoder configuration. Afterwards owned and freed by the encoder.
  • decoding: may be set by libavcodec in avcodec_open2().
§nb_decoded_side_data: i32

Trait Implementations§

§

impl Clone for AVCodecContext

§

fn clone(&self) -> AVCodecContext

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for AVCodecContext

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Copy for AVCodecContext

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more