Go to the documentation of this file.
65 av_log(avctx,
AV_LOG_ERROR,
"Invalid minimum required packet size %"PRId64
" (max allowed is %d)\n",
91 if (avpkt->
data || avpkt->
buf) {
92 av_log(avctx,
AV_LOG_ERROR,
"avpkt->{data,buf} != NULL in avcodec_default_get_encode_buffer()\n");
120 if (!avpkt->
data || !avpkt->
buf) {
162 frame->nb_samples = out_samples;
175 src->nb_samples,
s->ch_layout.nb_channels,
179 frame->nb_samples -
src->nb_samples,
180 s->ch_layout.nb_channels,
s->sample_fmt)) < 0)
219 if (
frame->key_frame)
223 #if FF_API_INTERLACED_FRAME
225 if (
frame->interlaced_frame)
227 if (
frame->top_field_first)
258 if (!
ret && *got_packet) {
323 if (!
frame->buf[0]) {
424 if (!avci->icc.avctx) {
473 int out_samples = (
src->nb_samples + pad_samples - 1) / pad_samples * pad_samples;
475 if (out_samples !=
src->nb_samples) {
567 int ret,
i, num_pix_fmts;
576 0, (
const void **) &
pix_fmts, &num_pix_fmts);
581 for (
i = 0;
i < num_pix_fmts;
i++)
584 if (
i == num_pix_fmts) {
586 "Specified pixel format %s is not supported by the %s encoder.\n",
607 av_log(avctx,
AV_LOG_WARNING,
"Specified bit depth %d not possible with the specified pixel formats depth %d\n",
616 #if FF_API_TICKS_PER_FRAME
621 "ticks_per_frame %d too large for the timebase %d/%d.",
634 "Mismatching AVCodecContext.pix_fmt and AVHWFramesContext.format\n");
640 "Mismatching AVCodecContext.sw_pix_fmt (%s) "
641 "and AVHWFramesContext.sw_format (%s)\n",
656 const int *supported_samplerates;
658 int ret,
i, num_sample_fmts, num_samplerates, num_ch_layouts;
677 for (
i = 0;
i < num_sample_fmts;
i++) {
687 if (
i == num_sample_fmts) {
689 "Specified sample format %s is not supported by the %s encoder\n",
703 0, (
const void **) &supported_samplerates,
707 if (supported_samplerates) {
708 for (
i = 0;
i < num_samplerates;
i++)
711 if (
i == num_samplerates) {
713 "Specified sample rate %d is not supported by the %s encoder\n",
717 for (
int p = 0; supported_samplerates[p]; p++)
724 0, (
const void **) &
ch_layouts, &num_ch_layouts);
728 for (
i = 0;
i < num_ch_layouts;
i++) {
732 if (
i == num_ch_layouts) {
736 "Specified channel layout '%s' is not supported by the %s encoder\n",
737 ret > 0 ? buf :
"?",
c->name);
775 "encoder does not support it.\n");
806 "from an encoder not supporting it\n");
831 type_packet, sd_frame->
size, 0);
835 memcpy(sd_packet->
data, sd_frame->
data, sd_frame->
size);
838 if (CONFIG_FRAME_THREAD_ENCODER) {
854 if (
frame->width <= 0 ||
frame->height <= 0) {
863 if (!
frame->ch_layout.nb_channels) {
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
int ff_encode_reordered_opaque(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame)
Propagate user opaque values from the frame to avctx/pkt as needed.
int av_samples_copy(uint8_t *const *dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Copy samples from src to dst.
int frame_size
Number of samples per channel in an audio frame.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define FF_ENABLE_DEPRECATION_WARNINGS
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
@ FF_CODEC_CB_TYPE_RECEIVE_PACKET
AVColorTransferCharacteristic
Color Transfer Characteristic.
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
int sample_rate
samples per second
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
static enum AVSampleFormat sample_fmts[]
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AVERROR_EOF
End of file.
uint8_t * data
The data buffer.
@ AV_CODEC_CONFIG_SAMPLE_RATE
int, terminated by 0
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
#define FF_CODEC_CAP_EOF_FLUSH
The encoder has AV_CODEC_CAP_DELAY set, but does not actually have delay - it only wants to be flushe...
const struct AVCodecDescriptor * codec_descriptor
AVCodecDescriptor.
AVPacketSideData * coded_side_data
Additional data associated with the entire coded stream.
static int encode_make_refcounted(AVCodecContext *avctx, AVPacket *avpkt)
#define AV_CODEC_CAP_ENCODER_RECON_FRAME
The encoder is able to output reconstructed frame data, i.e.
int ff_encode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
avcodec_receive_frame() implementation for encoders.
This structure describes decoded (raw) audio or video data.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
int capabilities
Codec capabilities.
@ AVCOL_RANGE_JPEG
Full range content.
int av_samples_set_silence(uint8_t *const *audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
int depth
Number of bits in the component.
void * frame_thread_encoder
AVFrame * in_frame
The input frame is stored here for encoders implementing the simple encode API.
int(* encode)(struct AVCodecContext *avctx, struct AVPacket *avpkt, const struct AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt, AVFrame *frame, int *got_packet)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
AVColorPrimaries
Chromaticity coordinates of the source primaries.
@ AV_CODEC_CONFIG_PIX_FORMAT
AVPixelFormat, terminated by AV_PIX_FMT_NONE.
int avcodec_is_open(AVCodecContext *s)
int nb_channels
Number of channels in this layout.
int ff_icc_profile_attach(FFIccContext *s, cmsHPROFILE profile, AVFrame *frame)
Attach an ICC profile to a frame.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
#define AV_CODEC_FLAG_COPY_OPAQUE
const struct AVCodec * codec
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
#define AV_CODEC_FLAG_FRAME_DURATION
Signal to the encoder that the values of AVFrame.duration are valid and should be used (typically for...
AVChannelLayout ch_layout
Audio channel layout.
int ff_icc_context_init(FFIccContext *s, void *avctx)
Initializes an FFIccContext.
static int encode_receive_packet_internal(AVCodecContext *avctx, AVPacket *avpkt)
int flags
AV_CODEC_FLAG_*.
static int encode_preinit_video(AVCodecContext *avctx)
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int encode_send_frame_internal(AVCodecContext *avctx, const AVFrame *src)
static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
av_cold int ff_frame_thread_encoder_init(AVCodecContext *avctx)
Initialize frame thread encoder.
@ AV_CODEC_CONFIG_SAMPLE_FORMAT
AVSampleFormat, terminated by AV_SAMPLE_FMT_NONE.
AVPacket * buffer_pkt
Temporary buffers for newly received or not yet output packets/frames.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
@ AV_FRAME_DATA_AUDIO_SERVICE_TYPE
This side data must be associated with an audio frame and corresponds to enum AVAudioServiceType defi...
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static enum AVPixelFormat pix_fmts[]
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
@ FF_CODEC_CB_TYPE_ENCODE
int64_t max_pixels
The number of pixels per image to maximally accept.
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
int(* encode_sub)(struct AVCodecContext *avctx, uint8_t *buf, int buf_size, const struct AVSubtitle *sub)
Encode subtitles to a raw buffer.
void * opaque
for some private data of the user
This structure describes the bitrate properties of an encoded bitstream.
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, AVFrame *frame, int *got_packet_ptr)
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
int rc_buffer_size
decoder bitstream buffer size
#define AV_CODEC_PROP_INTRA_ONLY
Codec uses only intra compression.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
static av_always_inline int64_t ff_samples_to_time_base(const AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
struct AVCodecInternal * internal
Private context used for internal data.
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
int64_t bit_rate
the average bitrate
enum AVPacketSideDataType type
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
AVCodecInternal * ff_encode_internal_alloc(void)
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
#define AV_CODEC_FLAG2_ICC_PROFILES
Generate/parse ICC profiles on encode/decode, as appropriate for the type of file.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
const SideDataMap ff_sd_global_map[]
A map between packet and frame side data types.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
@ AV_PKT_DATA_NB
The number of side data types.
const AVPacketSideData * av_packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Get side information from a side data array.
int ff_icc_profile_generate(FFIccContext *s, enum AVColorPrimaries color_prim, enum AVColorTransferCharacteristic color_trc, cmsHPROFILE *out_profile)
Generate an ICC profile for a given combination of color primaries and transfer function.
#define attribute_align_arg
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
Allocate buffers for a frame.
int avcodec_get_supported_config(const AVCodecContext *avctx, const AVCodec *codec, enum AVCodecConfig config, unsigned flags, const void **out, int *out_num)
Retrieve a list of all supported values for a given configuration type.
@ AV_CODEC_CONFIG_CHANNEL_LAYOUT
AVChannelLayout, terminated by {0}.
char * stats_out
pass1 encoding statistics output buffer
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
static int pad_last_frame(AVCodecContext *s, AVFrame *frame, const AVFrame *src, int out_samples)
Pad last frame with silence.
int flags2
AV_CODEC_FLAG2_*.
enum AVPacketSideDataType packet
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
An AVChannelLayout holds information about the channel layout of audio data.
#define AV_CODEC_PROP_REORDER
Codec supports frame reordering.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
int(* receive_packet)(struct AVCodecContext *avctx, struct AVPacket *avpkt)
Encode API with decoupled frame/packet dataflow.
enum AVSampleFormat sample_fmt
audio sample format
int last_audio_frame
An audio frame with less than required samples has been submitted (and potentially padded with silenc...
#define AV_NOPTS_VALUE
Undefined timestamp value.
static const av_always_inline FFCodec * ffcodec(const AVCodec *codec)
uint8_t * byte_buffer
temporary buffer used for encoders to store their bitstream
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
enum AVFrameSideDataType frame
int flags
A combination of AV_PKT_FLAG values.
unsigned int byte_buffer_size
static EncodeContext * encode_ctx(AVCodecInternal *avci)
int ff_encode_preinit(AVCodecContext *avctx)
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
int av_codec_is_encoder(const AVCodec *codec)
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
unsigned caps_internal
Internal codec capabilities FF_CODEC_CAP_*.
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
#define AV_CODEC_FLAG_RECON_FRAME
Request the encoder to output reconstructed frames, i.e. frames that would be produced by decoding th...
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
int intra_only_flag
This is set to AV_PKT_FLAG_KEY for encoders that encode intra-only formats (i.e.
AVSampleFormat
Audio sample formats.
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
static const AVChannelLayout ch_layouts[]
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
int attribute_align_arg avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Supply a raw video or audio frame to the encoder.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
#define FF_CODEC_CAP_ICC_PROFILES
Codec supports embedded ICC profiles (AV_FRAME_DATA_ICC_PROFILE).
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
This struct describes a set or pool of "hardware" frames (i.e.
int64_t frame_num
Frame counter, set by libavcodec.
void ff_encode_flush_buffers(AVCodecContext *avctx)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
AVPacketSideData * av_packet_side_data_new(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, size_t size, int flags)
Allocate a new packet side data.
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
AVFrame * recon_frame
When the AV_CODEC_FLAG_RECON_FRAME flag is used.
#define AV_INPUT_BUFFER_PADDING_SIZE
main external API structure.
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
int pad_samples
Audio encoders can set this flag during init to indicate that they want the small last frame to be pa...
int(* get_encode_buffer)(struct AVCodecContext *s, AVPacket *pkt, int flags)
This callback is called at the beginning of each packet to get a data buffer for it.
static int encode_simple_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
attribute_deprecated int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
unsigned cb_type
This field determines the type of the codec (decoder/encoder) and also the exact callback cb implemen...
int av_buffer_realloc(AVBufferRef **pbuf, size_t size)
Reallocate a given buffer.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
int draining
decoding: AVERROR_EOF has been returned from ff_decode_get_packet(); must not be used by decoders tha...
#define FF_DISABLE_DEPRECATION_WARNINGS
int coded_width
Bitstream width / height, may be different from width/height e.g.
enum AVMediaType codec_type
static int encode_preinit_audio(AVCodecContext *avctx)
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Structure to hold side data for an AVFrame.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
This structure stores compressed data.
int avcodec_default_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int flags)
The default callback for AVCodecContext.get_encode_buffer().
static const AVFrameSideData * av_frame_side_data_get(AVFrameSideData *const *sd, const int nb_sd, enum AVFrameSideDataType type)
Wrapper around av_frame_side_data_get_c() to workaround the limitation that for any type T the conver...
int width
picture width / height.
static int encode_generate_icc_profile(av_unused AVCodecContext *c, av_unused AVFrame *f)
#define flags(name, subs,...)
AVCPBProperties * ff_encode_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
uint32_t start_display_time
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
AVCPBProperties * av_cpb_properties_alloc(size_t *size)
Allocate a CPB properties structure and initialize its fields to default values.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.