34 if (avpkt->
size < 0) {
39 av_log(avctx,
AV_LOG_ERROR,
"Invalid minimum required packet size %"PRId64
" (max allowed is %d)\n",
44 if (avctx && 2*min_size < size) {
46 if (!avpkt->
data || avpkt->
size < size) {
56 if (avpkt->
size < size) {
127 int needs_realloc = !user_pkt.
data;
132 av_log(avctx,
AV_LOG_ERROR,
"This encoder requires using the avcodec_send_frame() API.\n");
146 "with more than %d channels, but extended_data is not set.\n",
156 memcpy(extended_frame, frame,
sizeof(
AVFrame));
158 frame = extended_frame;
172 av_log(avctx,
AV_LOG_ERROR,
"more samples than frame size (avcodec_encode_audio2)\n");
183 frame = padded_frame;
197 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
199 if (*got_packet_ptr) {
222 avpkt->
buf = user_pkt.
buf;
224 }
else if (!avpkt->
buf) {
232 if (needs_realloc && avpkt->
data) {
241 if (ret < 0 || !*got_packet_ptr) {
265 int needs_realloc = !user_pkt.
data;
270 av_log(avctx,
AV_LOG_ERROR,
"This encoder requires using the avcodec_send_frame() API.\n");
274 if(CONFIG_FRAME_THREAD_ENCODER &&
291 if (frame && (frame->
width == 0 || frame->
height == 0))
296 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
311 avpkt->
buf = user_pkt.
buf;
313 }
else if (!avpkt->
buf) {
321 if (!*got_packet_ptr)
326 if (needs_realloc && avpkt->
data) {
336 if (ret < 0 || !*got_packet_ptr)
374 if (ret >= 0 && *got_packet) {
414 return do_encode(avctx, frame, &(
int){0});
440 if (ret >= 0 && !got_packet)
const struct AVCodec * codec
#define AV_NUM_DATA_POINTERS
int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet_ptr)
This structure describes decoded (raw) audio or video data.
This side data must be associated with an audio frame and corresponds to enum AVAudioServiceType defi...
#define AV_LOG_WARNING
Something somehow does not look correct.
int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of audio.
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...
static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
Pad last frame with silence.
Macro definitions for various function/variable attributes.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
int av_codec_is_encoder(const AVCodec *codec)
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
enum AVSampleFormat sample_fmt
audio sample format
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static av_cold int end(AVCodecContext *avctx)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
void * frame_thread_encoder
Structure to hold side data for an AVFrame.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
#define AVERROR_EOF
End of file.
char * stats_out
pass1 encoding statistics output buffer
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int(* send_frame)(AVCodecContext *avctx, const AVFrame *frame)
Encode API with decoupled packet/frame dataflow.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int active_thread_type
Which multithreading methods are in use by the codec.
int avcodec_is_open(AVCodecContext *s)
int capabilities
Codec capabilities.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
int flags
AV_CODEC_FLAG_*.
simple assert() macros that are a bit more flexible than ISO C assert().
int64_t max_pixels
The number of pixels per image to maximally accept.
int av_buffer_realloc(AVBufferRef **pbuf, int size)
Reallocate a given buffer.
int ff_alloc_packet(AVPacket *avpkt, int size)
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
int flags
A combination of AV_PKT_FLAG values.
reference-counted frame API
uint64_t channel_layout
Channel layout of the audio data.
int(* encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size, const struct AVSubtitle *sub)
common internal API header
int channels
number of audio channels, only used for audio.
#define FF_THREAD_FRAME
Decode more than one frame at once.
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
int width
picture width / height.
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
int draining
checks API usage: after codec draining, flush is required to resume operation
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
int frame_size
Number of samples per channel in an audio frame.
Libavcodec external API header.
enum AVMediaType codec_type
main external API structure.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
uint8_t * data
The data buffer.
int attribute_align_arg avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Supply a raw video or audio frame to the encoder.
int av_samples_copy(uint8_t **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 attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of video.
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVPacket * buffer_pkt
buffers for using new encode/decode API through legacy API
A reference to a data buffer.
common internal api header.
uint32_t start_display_time
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
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...
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int channels
number of audio channels
struct AVCodecInternal * internal
Private context used for internal data.
unsigned int byte_buffer_size
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int frame_number
Frame counter, set by libavcodec.
int(* receive_packet)(AVCodecContext *avctx, AVPacket *avpkt)
static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
static int do_encode(AVCodecContext *avctx, const AVFrame *frame, int *got_packet)
uint8_t ** extended_data
pointers to the data planes/channels.
This structure stores compressed data.
uint8_t * byte_buffer
temporary buffer used for encoders to store their bitstream
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
int(* encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_NOPTS_VALUE
Undefined timestamp value.
int last_audio_frame
An audio frame with less than required samples has been submitted and padded with silence...