#[repr(C)]
pub struct AVCodecContext {
Show 194 fields pub av_class: *const AVClass, pub log_level_offset: c_int, pub codec_type: AVMediaType, pub codec: *const AVCodec, pub codec_id: AVCodecID, pub codec_tag: c_uint, pub priv_data: *mut c_void, pub internal: *mut AVCodecInternal, pub opaque: *mut c_void, pub bit_rate: i64, pub bit_rate_tolerance: c_int, pub global_quality: c_int, pub compression_level: c_int, pub flags: c_int, pub flags2: c_int, pub extradata: *mut u8, pub extradata_size: c_int, pub time_base: AVRational, pub ticks_per_frame: c_int, pub delay: c_int, pub width: c_int, pub height: c_int, pub coded_width: c_int, pub coded_height: c_int, pub gop_size: c_int, pub pix_fmt: AVPixelFormat, pub draw_horiz_band: Option<unsafe extern "C" fn(s: *mut AVCodecContext, src: *const AVFrame, offset: *mut c_int, y: c_int, type_: c_int, height: c_int)>, pub get_format: Option<unsafe extern "C" fn(s: *mut AVCodecContext, fmt: *const AVPixelFormat) -> AVPixelFormat>, pub max_b_frames: c_int, pub b_quant_factor: f32, pub b_frame_strategy: c_int, pub b_quant_offset: f32, pub has_b_frames: c_int, pub mpeg_quant: c_int, 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 slice_count: c_int, pub prediction_method: c_int, pub slice_offset: *mut c_int, pub sample_aspect_ratio: AVRational, pub me_cmp: c_int, pub me_sub_cmp: c_int, pub mb_cmp: c_int, pub ildct_cmp: c_int, pub dia_size: c_int, pub last_predictor_count: c_int, pub pre_me: c_int, pub me_pre_cmp: c_int, pub pre_dia_size: c_int, pub me_subpel_quality: c_int, pub me_range: c_int, pub slice_flags: c_int, pub mb_decision: c_int, pub intra_matrix: *mut u16, pub inter_matrix: *mut u16, pub scenechange_threshold: c_int, pub noise_reduction: c_int, pub intra_dc_precision: c_int, pub skip_top: c_int, pub skip_bottom: c_int, pub mb_lmin: c_int, pub mb_lmax: c_int, pub me_penalty_compensation: c_int, pub bidir_refine: c_int, pub brd_scale: c_int, pub keyint_min: c_int, pub refs: c_int, pub chromaoffset: c_int, pub mv0_threshold: c_int, pub b_sensitivity: c_int, pub color_primaries: AVColorPrimaries, pub color_trc: AVColorTransferCharacteristic, pub colorspace: AVColorSpace, pub color_range: AVColorRange, pub chroma_sample_location: AVChromaLocation, pub slices: c_int, pub field_order: AVFieldOrder, pub sample_rate: c_int, pub channels: c_int, pub sample_fmt: AVSampleFormat, pub frame_size: c_int, pub frame_number: c_int, pub block_align: c_int, pub cutoff: c_int, pub channel_layout: u64, pub request_channel_layout: u64, pub audio_service_type: AVAudioServiceType, pub request_sample_fmt: AVSampleFormat, pub get_buffer2: Option<unsafe extern "C" fn(s: *mut AVCodecContext, frame: *mut AVFrame, flags: c_int) -> c_int>, pub refcounted_frames: c_int, pub qcompress: f32, pub qblur: f32, pub qmin: c_int, pub qmax: c_int, pub max_qdiff: c_int, pub rc_buffer_size: c_int, pub rc_override_count: c_int, 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: c_int, pub coder_type: c_int, pub context_model: c_int, pub frame_skip_threshold: c_int, pub frame_skip_factor: c_int, pub frame_skip_exp: c_int, pub frame_skip_cmp: c_int, pub trellis: c_int, pub min_prediction_order: c_int, pub max_prediction_order: c_int, pub timecode_frame_start: i64, pub rtp_callback: Option<unsafe extern "C" fn(avctx: *mut AVCodecContext, data: *mut c_void, size: c_int, mb_nb: c_int)>, pub rtp_payload_size: c_int, pub mv_bits: c_int, pub header_bits: c_int, pub i_tex_bits: c_int, pub p_tex_bits: c_int, pub i_count: c_int, pub p_count: c_int, pub skip_count: c_int, pub misc_bits: c_int, pub frame_bits: c_int, pub stats_out: *mut c_char, pub stats_in: *mut c_char, pub workaround_bugs: c_int, pub strict_std_compliance: c_int, pub error_concealment: c_int, pub debug: c_int, pub err_recognition: c_int, pub reordered_opaque: i64, pub hwaccel: *const AVHWAccel, pub hwaccel_context: *mut c_void, pub error: [u64; 8], pub dct_algo: c_int, pub idct_algo: c_int, pub bits_per_coded_sample: c_int, pub bits_per_raw_sample: c_int, pub lowres: c_int, pub coded_frame: *mut AVFrame, pub thread_count: c_int, pub thread_type: c_int, pub active_thread_type: c_int, pub thread_safe_callbacks: c_int, pub execute: Option<unsafe extern "C" fn(c: *mut AVCodecContext, func: Option<unsafe extern "C" fn(c2: *mut AVCodecContext, arg: *mut c_void) -> c_int>, arg2: *mut c_void, ret: *mut c_int, count: c_int, size: c_int) -> c_int>, pub execute2: Option<unsafe extern "C" fn(c: *mut AVCodecContext, func: Option<unsafe extern "C" fn(c2: *mut AVCodecContext, arg: *mut c_void, jobnr: c_int, threadnr: c_int) -> c_int>, arg2: *mut c_void, ret: *mut c_int, count: c_int) -> c_int>, pub nsse_weight: c_int, pub profile: c_int, pub level: c_int, pub skip_loop_filter: AVDiscard, pub skip_idct: AVDiscard, pub skip_frame: AVDiscard, pub subtitle_header: *mut u8, pub subtitle_header_size: c_int, pub vbv_delay: u64, pub side_data_only_packets: c_int, pub initial_padding: c_int, pub framerate: AVRational, pub sw_pix_fmt: AVPixelFormat, pub pkt_timebase: AVRational, pub codec_descriptor: *const AVCodecDescriptor, pub pts_correction_num_faulty_pts: i64, pub pts_correction_num_faulty_dts: i64, pub pts_correction_last_pts: i64, pub pts_correction_last_dts: i64, pub sub_charenc: *mut c_char, pub sub_charenc_mode: c_int, pub skip_alpha: c_int, pub seek_preroll: c_int, pub debug_mv: c_int, pub chroma_intra_matrix: *mut u16, pub dump_separator: *mut u8, pub codec_whitelist: *mut c_char, pub properties: c_uint, pub coded_side_data: *mut AVPacketSideData, pub nb_coded_side_data: c_int, pub hw_frames_ctx: *mut AVBufferRef, pub sub_text_format: c_int, pub trailing_padding: c_int, pub max_pixels: i64, pub hw_device_ctx: *mut AVBufferRef, pub hwaccel_flags: c_int, pub apply_cropping: c_int, pub extra_hw_frames: c_int, pub discard_damaged_percentage: c_int, pub max_samples: i64, pub export_side_data: c_int, pub get_encode_buffer: Option<unsafe extern "C" fn(s: *mut AVCodecContext, pkt: *mut AVPacket, flags: c_int) -> c_int>,
}
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: c_int§codec_type: AVMediaType§codec: *const AVCodec§codec_id: AVCodecID§codec_tag: c_uint

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
§bit_rate_tolerance: c_int

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: c_int

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: c_int
  • encoding: Set by user.
  • decoding: unused
§flags: c_int

AV_CODEC_FLAG_*.

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

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: c_int§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: the use of this field for decoding is deprecated. Use framerate instead.
§ticks_per_frame: c_int

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.

§delay: c_int

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: c_int

picture width / height.

@note Those fields may not match the values of the last AVFrame output by avcodec_decode_video2 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: c_int

picture width / height.

@note Those fields may not match the values of the last AVFrame output by avcodec_decode_video2 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: c_int

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: c_int

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.
§gop_size: c_int

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

  • encoding: Set by user.
  • decoding: unused
§pix_fmt: AVPixelFormat

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.
§draw_horiz_band: Option<unsafe extern "C" fn(s: *mut AVCodecContext, src: *const AVFrame, offset: *mut c_int, y: c_int, type_: c_int, height: c_int)>

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(s: *mut AVCodecContext, fmt: *const AVPixelFormat) -> AVPixelFormat>

callback to negotiate the pixelFormat @param fmt is the list of formats which are supported by the codec, it is terminated by -1 as 0 is a valid format, the formats are ordered by quality. The first is always the native one. @note The callback may be called again immediately if initialization for the selected (hardware-accelerated) pixel format failed. @warning Behavior is undefined if the callback returns a value not in the fmt list of formats. @return the chosen format

  • encoding: unused
  • decoding: Set by user, if not set the native format will be chosen.
§max_b_frames: c_int

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_frame_strategy: c_int

@deprecated use encoder private options instead

§b_quant_offset: f32

qscale offset between IP and B-frames

  • encoding: Set by user.
  • decoding: unused
§has_b_frames: c_int

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.
§mpeg_quant: c_int

@deprecated use encoder private options instead

§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
§slice_count: c_int

slice count

  • encoding: Set by libavcodec.
  • decoding: Set by user (or 0).
§prediction_method: c_int

@deprecated use encoder private options instead

§slice_offset: *mut c_int

slice offsets in the frame in bytes

  • encoding: Set/allocated by libavcodec.
  • decoding: Set/allocated by user (or NULL).
§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.
§me_cmp: c_int

motion estimation comparison function

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

subpixel motion estimation comparison function

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

macroblock comparison function (not supported yet)

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

interlaced DCT comparison function

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

ME diamond size & shape

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

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

  • encoding: Set by user.
  • decoding: unused
§pre_me: c_int

@deprecated use encoder private options instead

§me_pre_cmp: c_int

motion estimation prepass comparison function

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

ME prepass diamond size & shape

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

subpel ME quality

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

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

  • encoding: Set by user.
  • decoding: unused
§slice_flags: c_int

slice flags

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

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.
§scenechange_threshold: c_int

@deprecated use encoder private options instead

§noise_reduction: c_int

@deprecated use encoder private options instead

§intra_dc_precision: c_int

precision of the intra DC coefficient - 8

  • encoding: Set by user.
  • decoding: Set by libavcodec
§skip_top: c_int

Number of macroblock rows at the top which are skipped.

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

Number of macroblock rows at the bottom which are skipped.

  • encoding: unused
  • decoding: Set by user.
§mb_lmin: c_int

minimum MB Lagrange multiplier

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

maximum MB Lagrange multiplier

  • encoding: Set by user.
  • decoding: unused
§me_penalty_compensation: c_int

@deprecated use encoder private options instead

§bidir_refine: c_int
  • encoding: Set by user.
  • decoding: unused
§brd_scale: c_int

@deprecated use encoder private options instead

§keyint_min: c_int

minimum GOP size

  • encoding: Set by user.
  • decoding: unused
§refs: c_int

number of reference frames

  • encoding: Set by user.
  • decoding: Set by lavc.
§chromaoffset: c_int

@deprecated use encoder private options instead

§mv0_threshold: c_int

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

  • encoding: Set by user.
  • decoding: unused
§b_sensitivity: c_int

@deprecated use encoder private options instead

§color_primaries: AVColorPrimaries

Chromaticity coordinates of the source primaries.

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

Color Transfer Characteristic.

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

YUV colorspace type.

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

MPEG vs JPEG YUV range.

  • encoding: Set by user
  • decoding: Set by libavcodec
§chroma_sample_location: AVChromaLocation

This defines the location of chroma samples.

  • encoding: Set by user
  • decoding: Set by libavcodec
§slices: c_int

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

  • encoding: Set by user
  • decoding: unused
§field_order: AVFieldOrder

Field order

  • encoding: set by libavcodec
  • decoding: Set by user.
§sample_rate: c_int

< samples per second

§channels: c_int

< number of audio channels

§sample_fmt: AVSampleFormat

< sample format

§frame_size: c_int

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
§frame_number: c_int

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.

§block_align: c_int

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

§cutoff: c_int

Audio cutoff bandwidth (0 means “automatic”)

  • encoding: Set by user.
  • decoding: unused
§channel_layout: u64

Audio channel layout.

  • encoding: set by user.
  • decoding: set by user, may be overwritten by libavcodec.
§request_channel_layout: u64

Request decoder to use this channel layout if it can (0 for default)

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

Type of service that the audio stream conveys.

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

desired sample format

  • encoding: Not used.
  • decoding: Set by user. Decoder will decode to this format if it can.
§get_buffer2: Option<unsafe extern "C" fn(s: *mut AVCodecContext, frame: *mut AVFrame, flags: c_int) -> c_int>

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().

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.
§refcounted_frames: c_int

If non-zero, the decoded audio and video frames returned from avcodec_decode_video2() and avcodec_decode_audio4() are reference-counted and are valid indefinitely. The caller must free them with av_frame_unref() when they are not needed anymore. Otherwise, the decoded frames must not be freed by the caller and are only valid until the next decode call.

This is always automatically enabled if avcodec_receive_frame() is used.

  • encoding: unused
  • decoding: set by the caller before avcodec_open2().
§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: c_int

minimum quantizer

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

maximum quantizer

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

maximum quantizer difference between frames

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

decoder bitstream buffer size

  • encoding: Set by user.
  • decoding: unused
§rc_override_count: c_int

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: c_int

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

  • encoding: Set by user.
  • decoding: unused
§coder_type: c_int

@deprecated use encoder private options instead

§context_model: c_int

@deprecated use encoder private options instead

§frame_skip_threshold: c_int

@deprecated use encoder private options instead

§frame_skip_factor: c_int

@deprecated use encoder private options instead

§frame_skip_exp: c_int

@deprecated use encoder private options instead

§frame_skip_cmp: c_int

@deprecated use encoder private options instead

§trellis: c_int

trellis RD quantization

  • encoding: Set by user.
  • decoding: unused
§min_prediction_order: c_int

@deprecated use encoder private options instead

§max_prediction_order: c_int

@deprecated use encoder private options instead

§timecode_frame_start: i64

@deprecated use encoder private options instead

§rtp_callback: Option<unsafe extern "C" fn(avctx: *mut AVCodecContext, data: *mut c_void, size: c_int, mb_nb: c_int)>

@deprecated unused

§rtp_payload_size: c_int

@deprecated use encoder private options instead

§mv_bits: c_int§header_bits: c_int§i_tex_bits: c_int§p_tex_bits: c_int§i_count: c_int§p_count: c_int§skip_count: c_int§misc_bits: c_int§frame_bits: c_int

@deprecated this field is unused

§stats_out: *mut c_char

pass1 encoding statistics output buffer

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

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: c_int

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

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

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)
§error_concealment: c_int

error concealment flags

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

debug

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

Error recognition; may misdetect some more or less valid parts as errors.

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

opaque 64-bit number (generally a PTS) that will be reordered and output in AVFrame.reordered_opaque

  • encoding: Set by libavcodec to the reordered_opaque of the input frame corresponding to the last returned packet. Only supported by encoders with the AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE capability.
  • decoding: Set by user.
§hwaccel: *const AVHWAccel

Hardware accelerator in use

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

Hardware accelerator context. For some hardware accelerators, a global context needs to be provided by the user. In that case, this holds display-dependent data FFmpeg cannot instantiate itself. Please refer to the FFmpeg HW accelerator documentation to know how to fill this is. e.g. for VA API, this is a struct vaapi_context.

  • encoding: unused
  • decoding: Set by user
§error: [u64; 8]

error

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

DCT algorithm, see FF_DCT_* below

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

IDCT algorithm, see FF_IDCT_* below.

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

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

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

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

  • encoding: set by user.
  • decoding: set by libavcodec.
§lowres: c_int

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

  • encoding: unused
  • decoding: Set by user.
§coded_frame: *mut AVFrame

the picture in the bitstream

  • encoding: Set by libavcodec.
  • decoding: unused

@deprecated use the quality factor packet side data instead

§thread_count: c_int

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: c_int

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: c_int

Which multithreading methods are in use by the codec.

  • encoding: Set by libavcodec.
  • decoding: Set by libavcodec.
§thread_safe_callbacks: c_int

Set by the client if its custom get_buffer() callback can be called synchronously from another thread, which allows faster multithreaded decoding. draw_horiz_band() will be called from other threads regardless of this setting. Ignored if the default get_buffer() is used.

  • encoding: Set by user.
  • decoding: Set by user.

@deprecated the custom get_buffer2() callback should always be thread-safe. Thread-unsafe get_buffer2() implementations will be invalid starting with LIBAVCODEC_VERSION_MAJOR=60; in other words, libavcodec will behave as if this field was always set to 1. Callers that want to be forward compatible with future libavcodec versions should wrap access to this field in #if LIBAVCODEC_VERSION_MAJOR < 60

§execute: Option<unsafe extern "C" fn(c: *mut AVCodecContext, func: Option<unsafe extern "C" fn(c2: *mut AVCodecContext, arg: *mut c_void) -> c_int>, arg2: *mut c_void, ret: *mut c_int, count: c_int, size: c_int) -> c_int>

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(c: *mut AVCodecContext, func: Option<unsafe extern "C" fn(c2: *mut AVCodecContext, arg: *mut c_void, jobnr: c_int, threadnr: c_int) -> c_int>, arg2: *mut c_void, ret: *mut c_int, count: c_int) -> c_int>

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. Also see avcodec_thread_init and e.g. the –enable-pthread configure option. @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.
§nsse_weight: c_int

noise vs. sse weight for the nsse comparison function

  • encoding: Set by user.
  • decoding: unused
§profile: c_int

profile

  • encoding: Set by user.
  • decoding: Set by libavcodec.
§level: c_int

level

  • encoding: Set by user.
  • decoding: Set by libavcodec.
§skip_loop_filter: AVDiscard

Skip loop filtering for selected frames.

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

Skip IDCT/dequantization for selected frames.

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

Skip decoding for selected frames.

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

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_size: c_int§vbv_delay: u64

VBV delay coded in the last frame (in periods of a 27 MHz clock). Used for compliant TS muxing.

  • encoding: Set by libavcodec.
  • decoding: unused. @deprecated this value is now exported as a part of AV_PKT_DATA_CPB_PROPERTIES packet side data
§side_data_only_packets: c_int

Encoding only and set by default. Allow encoders to output packets that do not contain any encoded data, only side data.

Some encoders need to output such packets, e.g. to update some stream parameters at the end of encoding.

@deprecated this field disables the default behaviour and it is kept only for compatibility.

§initial_padding: c_int

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.
§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.
§sw_pix_fmt: AVPixelFormat

Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.

  • encoding: unused.
  • decoding: Set by libavcodec before calling get_format()
§pkt_timebase: AVRational

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

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

AVCodecDescriptor

  • encoding: unused.
  • decoding: set by libavcodec.
§pts_correction_num_faulty_pts: i64

Current statistics for PTS correction.

  • decoding: maintained and used by libavcodec, not intended to be used by user apps
  • encoding: unused
§pts_correction_num_faulty_dts: i64

Number of incorrect PTS values so far

§pts_correction_last_pts: i64

Number of incorrect DTS values so far

§pts_correction_last_dts: i64

PTS of the last frame

§sub_charenc: *mut c_char

Character encoding of the input subtitles file.

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

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
§skip_alpha: c_int

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
§seek_preroll: c_int

Number of samples to skip after a discontinuity

  • decoding: unused
  • encoding: set by libavcodec
§debug_mv: c_int

@deprecated unused

§chroma_intra_matrix: *mut u16

custom intra quantization matrix

  • encoding: Set by user, can be NULL.
  • decoding: unused.
§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 c_char

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

  • encoding: unused
  • decoding: set by user
§properties: c_uint

Properties of the stream that gets decoded

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

Additional data associated with the entire coded stream.

  • decoding: unused
  • encoding: may be set by libavcodec after avcodec_open2().
§nb_coded_side_data: c_int§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.
§sub_text_format: c_int

Control the form of AVSubtitle.rects[N]->ass

  • decoding: set by user
  • encoding: unused
§trailing_padding: c_int

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
§max_pixels: i64

The number of pixels per image to maximally accept.

  • decoding: set by user
  • encoding: set by user
§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: c_int

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)
§apply_cropping: c_int

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).

§extra_hw_frames: c_int§discard_damaged_percentage: c_int

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
§export_side_data: c_int

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
§get_encode_buffer: Option<unsafe extern "C" fn(s: *mut AVCodecContext, pkt: *mut AVPacket, flags: c_int) -> c_int>

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.

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

Trait Implementations§

source§

impl Clone for AVCodecContext

source§

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
source§

impl Debug for AVCodecContext

source§

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

Formats the value using the given formatter. Read more
source§

impl PartialEq for AVCodecContext

source§

fn eq(&self, other: &AVCodecContext) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for AVCodecContext

source§

impl StructuralPartialEq 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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

§

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>,

§

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>,

§

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.