encode.c File Reference
#include "libavutil/attributes.h"
#include "libavutil/avassert.h"
#include "libavutil/frame.h"
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
#include "libavutil/samplefmt.h"
#include "avcodec.h"
#include "encode.h"
#include "frame_thread_encoder.h"
#include "internal.h"

Go to the source code of this file.


int ff_alloc_packet2 (AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
 Check AVPacket size and/or allocate data. More...
int avcodec_default_get_encode_buffer (AVCodecContext *avctx, AVPacket *avpkt, int flags)
 The default callback for AVCodecContext.get_encode_buffer(). More...
int ff_get_encode_buffer (AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
 Get a buffer for a packet. More...
static int pad_last_frame (AVCodecContext *s, AVFrame *frame, const AVFrame *src)
 Pad last frame with silence. More...
int avcodec_encode_subtitle (AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
int ff_encode_get_frame (AVCodecContext *avctx, AVFrame *frame)
 Called by encoders to get the next frame for encoding. More...
static int encode_simple_internal (AVCodecContext *avctx, AVPacket *avpkt)
static int encode_simple_receive_packet (AVCodecContext *avctx, AVPacket *avpkt)
static int encode_receive_packet_internal (AVCodecContext *avctx, AVPacket *avpkt)
static int encode_send_frame_internal (AVCodecContext *avctx, const AVFrame *src)
int attribute_align_arg avcodec_send_frame (AVCodecContext *avctx, const AVFrame *frame)
 Supply a raw video or audio frame to the encoder. More...
int attribute_align_arg avcodec_receive_packet (AVCodecContext *avctx, AVPacket *avpkt)
 Read encoded data from the encoder. More...
static int compat_encode (AVCodecContext *avctx, AVPacket *avpkt, int *got_packet, const AVFrame *frame)
int attribute_align_arg avcodec_encode_audio2 (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 Encode a frame of audio. More...
int attribute_align_arg avcodec_encode_video2 (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 Encode a frame of video. More...
int ff_encode_preinit (AVCodecContext *avctx)

Function Documentation

◆ ff_alloc_packet2()

int ff_alloc_packet2 ( AVCodecContext avctx,
AVPacket avpkt,
int64_t  size,
int64_t  min_size 

Check AVPacket size and/or allocate data.

Encoders supporting AVCodec.encode2() can use this as a convenience to ensure the output packet data is large enough, whether provided by the user or allocated in this function.

avctxthe AVCodecContext of the encoder
avpktthe AVPacket If avpkt->data is already set, avpkt->size is checked to ensure it is large enough. If avpkt->data is NULL, a new buffer is allocated. avpkt->size is set to the specified size. All other AVPacket fields will be reset with av_init_packet().
sizethe minimum required packet size
min_sizeThis is a hint to the allocation algorithm, which indicates to what minimal size the caller might later shrink the packet to. Encoders often allocate packets which are larger than the amount of data that is written into them as the exact amount is not known at the time of allocation. min_size represents the size a packet might be shrunk to by the caller. Can be set to 0. setting this roughly correctly allows the allocation code to choose between several allocation strategies to improve speed slightly.
non negative on success, negative error code on failure

Definition at line 33 of file encode.c.

Referenced by a64multi_encode_frame(), aac_encode_frame(), adx_encode_frame(), alac_encode_frame(), amr_wb_encode_frame(), aptx_encode_frame(), avui_encode_frame(), bmp_encode_frame(), cfhd_encode_frame(), cinepak_encode_frame(), cng_encode_frame(), dnxhd_encode_picture(), dvvideo_encode_frame(), encode_apng(), encode_frame(), encode_nals(), encode_picture_ls(), encode_png(), encode_superframe(), ff_ac3_encode_frame_common_end(), ff_mpv_encode_picture(), ffat_encode(), fits_encode_frame(), flac_encode_frame(), flashsv2_encode_frame(), flashsv_encode_frame(), g723_1_encode_frame(), gif_encode_frame(), hap_encode(), ilbc_encode_frame(), libcodec2_encode(), libgsm_encode_frame(), libkvazaar_encode(), libopenjpeg_encode_frame(), libopus_encode(), libshine_encode_frame(), libvorbis_encode_frame(), libwebp_anim_encode_frame(), libwebp_encode_frame(), libx265_encode_frame(), ljpeg_encode_frame(), magy_encode_frame(), mlp_encode_frame(), mp3lame_encode_frame(), MPA_encode_frame(), omx_encode_frame(), opus_encode_frame(), pam_encode_frame(), pcm_dvd_encode_frame(), pcm_encode_frame(), pcx_encode_frame(), pnm_encode_frame(), prores_encode_frame(), qtrle_encode_frame(), ra144_encode_frame(), raw_encode(), roq_dpcm_encode_frame(), roq_encode_frame(), rpza_encode_frame(), s302m_encode2_frame(), sbc_encode_frame(), storeframe(), sunrast_encode_frame(), svc_encode_frame(), svq1_encode_frame(), targa_encode_frame(), tta_encode_frame(), twolame_encode_frame(), utvideo_encode_frame(), v308_encode_frame(), v408_encode_frame(), v410_encode_frame(), vorbis_encode_frame(), vtenc_cm_to_avpacket(), wavpack_encode_frame(), XAVS_frame(), xbm_encode_frame(), xface_encode_frame(), xvid_encode_frame(), xwd_encode_frame(), y41p_encode_frame(), and yuv4_encode_frame().

◆ ff_get_encode_buffer()

int ff_get_encode_buffer ( AVCodecContext avctx,
AVPacket avpkt,
int64_t  size,
int  flags 

Get a buffer for a packet.

This is a wrapper around AVCodecContext.get_encode_buffer() and should be used instead calling get_encode_buffer() directly.

Definition at line 82 of file encode.c.

Referenced by amf_copy_buffer(), librav1e_receive_packet(), mf_sample_to_avpacket(), process_output_surface(), and vaapi_encode_output().

◆ pad_last_frame()

static int pad_last_frame ( AVCodecContext s,
AVFrame frame,
const AVFrame src 

Pad last frame with silence.

Definition at line 115 of file encode.c.

Referenced by encode_send_frame_internal().

◆ ff_encode_get_frame()

int ff_encode_get_frame ( AVCodecContext avctx,
AVFrame frame 

Called by encoders to get the next frame for encoding.

frameAn empty frame to be filled with data.
0 if a new reference has been successfully written to frame AVERROR(EAGAIN) if no data is currently available AVERROR_EOF if end of stream has been reached, so no more data will be available

Definition at line 160 of file encode.c.

Referenced by eb_receive_packet(), encode_simple_internal(), ff_amf_receive_packet(), ff_nvenc_receive_packet(), ff_vaapi_encode_receive_packet(), librav1e_receive_packet(), mf_receive_packet(), and v4l2_receive_packet().

◆ encode_simple_internal()

static int encode_simple_internal ( AVCodecContext avctx,
AVPacket avpkt 

Definition at line 175 of file encode.c.

Referenced by encode_simple_receive_packet().

◆ encode_simple_receive_packet()

static int encode_simple_receive_packet ( AVCodecContext avctx,
AVPacket avpkt 

Definition at line 270 of file encode.c.

Referenced by encode_receive_packet_internal().

◆ encode_receive_packet_internal()

static int encode_receive_packet_internal ( AVCodecContext avctx,
AVPacket avpkt 

Definition at line 283 of file encode.c.

Referenced by avcodec_receive_packet(), and avcodec_send_frame().

◆ encode_send_frame_internal()

static int encode_send_frame_internal ( AVCodecContext avctx,
const AVFrame src 

Definition at line 317 of file encode.c.

Referenced by avcodec_send_frame().

◆ compat_encode()

static int compat_encode ( AVCodecContext avctx,
AVPacket avpkt,
int got_packet,
const AVFrame frame 

Definition at line 417 of file encode.c.

Referenced by avcodec_encode_audio2(), and avcodec_encode_video2().

◆ ff_encode_preinit()

int ff_encode_preinit ( AVCodecContext avctx)

Definition at line 527 of file encode.c.

Referenced by avcodec_open2().