2 * generic encoding-related code
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21#ifndef AVCODEC_ENCODE_H
22#define AVCODEC_ENCODE_H
31 * Used by some encoders as upper bound for the length of headers.
32 * TODO: Use proper codec-specific upper bounds.
34 #define FF_INPUT_BUFFER_MIN_SIZE 16384
37 * Called by encoders to get the next frame for encoding.
39 * @param frame An empty frame to be filled with data.
40 * @return 0 if a new reference has been successfully written to frame
41 * AVERROR(EAGAIN) if no data is currently available
42 * AVERROR_EOF if end of stream has been reached, so no more data
48 * Get a buffer for a packet. This is a wrapper around
49 * AVCodecContext.get_encode_buffer() and should be used instead calling get_encode_buffer()
55 * Allocate buffers for a frame. Encoder equivalent to ff_get_buffer().
60 * Check AVPacket size and allocate data.
62 * Encoders of type FF_CODEC_CB_TYPE_ENCODE can use this as a convenience to
63 * obtain a big enough buffer for the encoded bitstream.
65 * @param avctx the AVCodecContext of the encoder
66 * @param avpkt The AVPacket: on success, avpkt->data will point to a buffer
67 * of size at least `size`; the packet will not be refcounted.
68 * This packet must be initially blank.
69 * @param size an upper bound of the size of the packet to encode
70 * @return non negative on success, negative error code on failure
75 * Propagate user opaque values from the frame to avctx/pkt as needed.
86 * Add a CPB properties side data to an encoding context.
94 * Rescale from sample rate to AVCodecContext.time_base.
106 * Rescale from time base to AVCodecContext.sample_rate.
118 * Check if the elements of codec context matrices (intra_matrix, inter_matrix or
119 * chroma_intra_matrix) are within the specified range.
121 #define FF_MATRIX_TYPE_INTRA (1U << 0)
122 #define FF_MATRIX_TYPE_INTER (1U << 1)
123 #define FF_MATRIX_TYPE_CHROMA_INTRA (1U << 2)
126#endif /* AVCODEC_ENCODE_H */
Libavcodec external API header.
#define flags(name, subs,...)
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
AVCPBProperties * ff_encode_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt, AVFrame *frame, int *got_packet)
int ff_encode_reconf_parse_dict(AVCodecContext *avctx, AVDictionary **dict)
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
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_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
Allocate buffers for a frame.
int ff_check_codec_matrices(AVCodecContext *avctx, unsigned types, uint16_t min, uint16_t max)
static av_always_inline int64_t ff_samples_from_time_base(const AVCodecContext *avctx, int64_t duration)
Rescale from time base to AVCodecContext.sample_rate.
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.
reference-counted frame API
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define AV_NOPTS_VALUE
Undefined timestamp value.
This structure describes the bitrate properties of an encoded bitstream.
main external API structure.
int sample_rate
samples per second
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
static void error(const char *err)
static const uint8_t quality[]