FFmpeg
Loading...
Searching...
No Matches
encode.c File Reference
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/emms.h"
#include "libavutil/frame.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/samplefmt.h"
#include "avcodec.h"
#include "avcodec_internal.h"
#include "codec_desc.h"
#include "codec_internal.h"
#include "encode.h"
#include "frame_thread_encoder.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  EncodeContext
 

Functions

static EncodeContextencode_ctx (AVCodecInternal *avci)
 
int ff_alloc_packet (AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
 Check AVPacket size and allocate data.
 
int avcodec_default_get_encode_buffer (AVCodecContext *avctx, AVPacket *avpkt, int flags)
 The default callback for AVCodecContext.get_encode_buffer().
 
int ff_get_encode_buffer (AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
 Get a buffer for a packet.
 
static int encode_make_refcounted (AVCodecContext *avctx, AVPacket *avpkt)
 
static int pad_last_frame (AVCodecContext *s, AVFrame *frame, const AVFrame *src, int out_samples)
 Pad last frame with silence.
 
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.
 
static int encode_set_packet_props (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame)
 
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 ff_encode_encode_cb (AVCodecContext *avctx, AVPacket *avpkt, AVFrame *frame, int *got_packet)
 
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_generate_icc_profile (av_unused AVCodecContext *c, av_unused AVFrame *f)
 
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.
 
int attribute_align_arg avcodec_receive_packet (AVCodecContext *avctx, AVPacket *avpkt)
 Read encoded data from the encoder.
 
av_cold int ff_encode_reconf_parse_dict (AVCodecContext *avctx, AVDictionary **dict)
 
av_cold int avcodec_encode_reconfigure (AVCodecContext *avctx, AVDictionary **dict)
 Try to reconfigure the encoder with the provided dictionary.
 
static int encode_preinit_video (AVCodecContext *avctx)
 
static int encode_preinit_audio (AVCodecContext *avctx)
 
int ff_encode_preinit (AVCodecContext *avctx)
 
int ff_encode_alloc_frame (AVCodecContext *avctx, AVFrame *frame)
 Allocate buffers for a frame.
 
int ff_encode_receive_frame (AVCodecContext *avctx, AVFrame *frame)
 avcodec_receive_frame() implementation for encoders.
 
void ff_encode_flush_buffers (AVCodecContext *avctx)
 
AVCodecInternalff_encode_internal_alloc (void)
 
AVCPBPropertiesff_encode_add_cpb_side_data (AVCodecContext *avctx)
 Add a CPB properties side data to an encoding context.
 
int ff_encode_add_stats_side_data (AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
 
int ff_check_codec_matrices (AVCodecContext *avctx, unsigned types, uint16_t min, uint16_t max)
 

Function Documentation

◆ encode_ctx()

◆ ff_alloc_packet()

int ff_alloc_packet ( AVCodecContext * avctx,
AVPacket * avpkt,
int64_t size )

Check AVPacket size and allocate data.

Encoders of type FF_CODEC_CB_TYPE_ENCODE can use this as a convenience to obtain a big enough buffer for the encoded bitstream.

Parameters
avctxthe AVCodecContext of the encoder
avpktThe AVPacket: on success, avpkt->data will point to a buffer of size at least size; the packet will not be refcounted. This packet must be initially blank.
sizean upper bound of the size of the packet to encode
Returns
non negative on success, negative error code on failure

Definition at line 62 of file encode.c.

Referenced by aac_encode_frame(), aac_encode_frame(), alac_encode_frame(), amr_wb_encode_frame(), cfhd_encode_frame(), cinepak_encode_frame(), dxv_encode(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_png(), encode_superframe(), ff_mpv_encode_picture(), ffat_encode(), flashsv2_encode_frame(), flashsv_encode_frame(), gif_encode_frame(), hap_encode(), ilbc_encode_frame(), libopenjpeg_encode_frame(), libopus_encode(), ljpeg_encode_frame(), mlp_encode_frame(), msrle_encode_frame(), opus_encode_frame(), pcx_encode_frame(), prores_encode_frame(), qoi_encode_frame(), qtrle_encode_frame(), roq_encode_frame(), rpza_encode_frame(), smc_encode_frame(), sunrast_encode_frame(), svq1_encode_frame(), targa_encode_frame(), tta_encode_frame(), twolame_encode_frame(), utvideo_encode_frame(), vorbis_encode_frame(), wavpack_encode_frame(), xbm_encode_frame(), and xvid_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 106 of file encode.c.

Referenced by a64multi_encode_frame(), adx_encode_frame(), amf_copy_buffer(), aptx_encode_frame(), avui_encode_frame(), bmp_encode_frame(), cng_encode_frame(), d3d12va_encode_av1_get_coded_data(), d3d12va_encode_get_coded_data(), d3d12va_encode_output(), dfpwm_enc_frame(), dnxhd_encode_picture(), dvvideo_encode_frame(), encode_apng(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_frame(), encode_make_refcounted(), encode_nals(), encode_nals(), encode_picture_ls(), encode_yuv422p10(), ff_ac3_encode_frame(), fits_encode_frame(), flac_encode_frame(), g723_1_encode_frame(), hdr_encode_frame(), libcodec2_encode(), libgsm_encode_frame(), libjxl_anim_encode_frame(), libjxl_encode_frame(), libkvazaar_encode(), liblc3_encode(), liboapve_encode(), librav1e_receive_packet(), libshine_encode_frame(), libvorbis_encode_frame(), libwebp_anim_encode_frame(), libwebp_encode_frame(), libx265_encode_frame(), libxeve_encode(), magy_encode_frame(), mediacodec_receive(), mf_sample_to_avpacket(), mp3lame_encode_frame(), mpa_encode_frame(), oh_encode_output_packet(), pam_encode_frame(), pcm_bluray_encode_frame(), pcm_dvd_encode_frame(), pcm_encode_frame(), pnm_encode_frame(), process_output_surface(), ra144_encode_frame(), raw_encode(), rkmpp_output_pkt(), roq_dpcm_encode_frame(), s302m_encode2_frame(), sbc_encode_frame(), storeframe(), storeframe(), svc_encode_frame(), svt_jpegxs_enc_encode(), vaapi_encode_get_coded_data(), vaapi_encode_output(), vbn_encode(), vtenc_cm_to_avpacket(), vulkan_encode_output(), vvenc_frame(), wbmp_encode_frame(), xavs2_encode_frame(), XAVS_frame(), xface_encode_frame(), xwd_encode_frame(), y41p_encode_frame(), and yuv4_encode_frame().

◆ encode_make_refcounted()

static int encode_make_refcounted ( AVCodecContext * avctx,
AVPacket * avpkt )
static

Definition at line 137 of file encode.c.

Referenced by ff_encode_encode_cb().

◆ pad_last_frame()

static int pad_last_frame ( AVCodecContext * s,
AVFrame * frame,
const AVFrame * src,
int out_samples )
static

Pad last frame with silence.

Definition at line 157 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.

Parameters
frameAn empty frame to be filled with data.
Returns
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 218 of file encode.c.

Referenced by eb_receive_packet(), encode_simple_internal(), ff_amf_receive_packet(), ff_hw_base_encode_receive_packet(), ff_nvenc_receive_packet(), libjxl_anim_encode_frame(), librav1e_receive_packet(), mediacodec_encode(), mf_receive_packet(), oh_encode_receive(), rkmpp_receive(), v4l2_receive_packet(), vulkan_encode_apv_receive_packet(), vulkan_encode_ffv1_receive_packet(), and vulkan_encode_prores_receive_packet().

◆ encode_set_packet_props()

static int encode_set_packet_props ( AVCodecContext * avctx,
AVPacket * avpkt,
const AVFrame * frame )
static

Definition at line 233 of file encode.c.

Referenced by ff_encode_encode_cb().

◆ ff_encode_reordered_opaque()

int ff_encode_reordered_opaque ( AVCodecContext * avctx,
AVPacket * pkt,
const AVFrame * frame )

Propagate user opaque values from the frame to avctx/pkt as needed.

Definition at line 280 of file encode.c.

Referenced by encode_apng(), encode_frame(), ff_encode_encode_cb(), and ff_mpv_encode_picture().

◆ ff_encode_encode_cb()

int ff_encode_encode_cb ( AVCodecContext * avctx,
AVPacket * avpkt,
AVFrame * frame,
int * got_packet )

Definition at line 293 of file encode.c.

Referenced by encode_simple_internal(), and worker().

◆ encode_simple_internal()

static int encode_simple_internal ( AVCodecContext * avctx,
AVPacket * avpkt )
static

Definition at line 342 of file encode.c.

Referenced by encode_simple_receive_packet().

◆ encode_simple_receive_packet()

static int encode_simple_receive_packet ( AVCodecContext * avctx,
AVPacket * avpkt )
static

Definition at line 387 of file encode.c.

Referenced by encode_receive_packet_internal().

◆ encode_receive_packet_internal()

static int encode_receive_packet_internal ( AVCodecContext * avctx,
AVPacket * avpkt )
static

Definition at line 400 of file encode.c.

Referenced by avcodec_receive_packet(), and avcodec_send_frame().

◆ encode_generate_icc_profile()

static int encode_generate_icc_profile ( av_unused AVCodecContext * c,
av_unused AVFrame * f )
static

Definition at line 475 of file encode.c.

Referenced by encode_send_frame_internal().

◆ encode_send_frame_internal()

static int encode_send_frame_internal ( AVCodecContext * avctx,
const AVFrame * src )
static

Definition at line 481 of file encode.c.

Referenced by avcodec_send_frame().

◆ ff_encode_reconf_parse_dict()

av_cold int ff_encode_reconf_parse_dict ( AVCodecContext * avctx,
AVDictionary ** dict )

Definition at line 599 of file encode.c.

Referenced by av1_reconf(), avcodec_encode_reconfigure(), and X264_reconf().

◆ encode_preinit_video()

static int encode_preinit_video ( AVCodecContext * avctx)
static

Definition at line 696 of file encode.c.

Referenced by ff_encode_preinit().

◆ encode_preinit_audio()

static int encode_preinit_audio ( AVCodecContext * avctx)
static

Definition at line 799 of file encode.c.

Referenced by ff_encode_preinit().

◆ ff_encode_preinit()

int ff_encode_preinit ( AVCodecContext * avctx)

Definition at line 898 of file encode.c.

Referenced by avcodec_open2().

◆ ff_encode_alloc_frame()

int ff_encode_alloc_frame ( AVCodecContext * avctx,
AVFrame * frame )

Allocate buffers for a frame.

Encoder equivalent to ff_get_buffer().

Definition at line 989 of file encode.c.

Referenced by get_encode_buffer(), librav1e_receive_packet(), prepare_picture(), roq_encode_frame(), and svq1_encode_init().

◆ ff_encode_receive_frame()

int ff_encode_receive_frame ( AVCodecContext * avctx,
AVFrame * frame )

avcodec_receive_frame() implementation for encoders.

Definition at line 1011 of file encode.c.

Referenced by avcodec_receive_frame_flags().

◆ ff_encode_flush_buffers()

void ff_encode_flush_buffers ( AVCodecContext * avctx)

Definition at line 1024 of file encode.c.

Referenced by avcodec_flush_buffers().

◆ ff_encode_internal_alloc()

AVCodecInternal * ff_encode_internal_alloc ( void )

Definition at line 1034 of file encode.c.

Referenced by avcodec_open2().

◆ ff_encode_add_cpb_side_data()

AVCPBProperties * ff_encode_add_cpb_side_data ( AVCodecContext * avctx)

Add a CPB properties side data to an encoding context.

Definition at line 1039 of file encode.c.

Referenced by aac_encode_init(), aom_init(), config_enc_params(), ff_mpv_encode_init(), libx265_encode_init(), nvenc_setup_encoder(), qsv_retrieve_enc_params(), svc_encode_init(), vpx_init(), and X264_init().

◆ ff_encode_add_stats_side_data()

◆ ff_check_codec_matrices()

int ff_check_codec_matrices ( AVCodecContext * avctx,
unsigned types,
uint16_t min,
uint16_t max )

Definition at line 1095 of file encode.c.

Referenced by encode_picture(), init_matrices(), and xvid_encode_init().