55 const kvz_api *
const api =
ctx->api = kvz_api_get(8);
56 kvz_config *cfg =
NULL;
57 kvz_encoder *enc =
NULL;
62 "Video dimensions are not a multiple of 8 (%dx%d).\n",
67 ctx->config = cfg = api->config_alloc();
70 "Could not allocate kvazaar config structure.\n");
74 if (!api->config_init(cfg)) {
76 "Could not initialize kvazaar config structure.\n");
80 cfg->width = avctx->
width;
81 cfg->height = avctx->
height;
89 "Could not set framerate for kvazaar: integer overflow\n");
95 cfg->target_bitrate = avctx->
bit_rate;
99 cfg->rc_algorithm = KVZ_LAMBDA;
102 if (
ctx->kvz_params) {
107 if (!api->config_parse(cfg, entry->
key, entry->
value)) {
116 ctx->encoder = enc = api->encoder_open(cfg);
123 kvz_data_chunk *data_out =
NULL;
124 kvz_data_chunk *chunk =
NULL;
128 if (!api->encoder_headers(enc, &data_out, &len_out))
133 ctx->api->chunk_free(data_out);
139 for (chunk = data_out; chunk !=
NULL; chunk = chunk->next) {
140 memcpy(p, chunk->data, chunk->len);
144 ctx->api->chunk_free(data_out);
155 ctx->api->encoder_close(
ctx->encoder);
156 ctx->api->config_destroy(
ctx->config);
171 kvz_picture *input_pic =
NULL;
172 kvz_picture *recon_pic =
NULL;
173 kvz_frame_info frame_info;
174 kvz_data_chunk *data_out =
NULL;
175 uint32_t len_out = 0;
185 "Changing video dimensions during encoding is not supported. "
186 "(changed from %dx%d to %dx%d)\n",
187 ctx->config->width,
ctx->config->height,
195 "Changing pixel format during encoding is not supported. "
196 "(changed from %s to %s)\n",
219 int dst_linesizes[4] = {
233 retval =
ctx->api->encoder_encode(
ctx->encoder,
246 kvz_data_chunk *chunk =
NULL;
247 uint64_t written = 0;
255 for (chunk = data_out; chunk !=
NULL; chunk = chunk->next) {
257 memcpy(avpkt->
data + written, chunk->data, chunk->len);
258 written += chunk->len;
261 avpkt->
pts = recon_pic->pts;
262 avpkt->
dts = recon_pic->dts;
266 if (frame_info.nal_unit_type >= KVZ_NAL_BLA_W_LP &&
267 frame_info.nal_unit_type <= KVZ_NAL_RSV_IRAP_VCL23) {
271 switch (frame_info.slice_type) {
285 #if FF_API_CODED_FRAME
293 #if FF_API_CODED_FRAME
303 ctx->api->picture_free(input_pic);
304 ctx->api->picture_free(recon_pic);
305 ctx->api->chunk_free(data_out);
314 #define OFFSET(x) offsetof(LibkvazaarContext, x)
315 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
317 {
"kvazaar-params",
"Set kvazaar parameters as a comma-separated list of key=value pairs.",
335 .
name =
"libkvazaar",
342 .priv_class = &
class,
353 .wrapper_name =
"libkvazaar",
Macro definitions for various function/variable attributes.
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
static av_cold int init(AVCodecContext *avctx)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
#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_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add the parsed entries to a dictionary.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
#define LIBAVUTIL_VERSION_INT
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
static const AVCodecDefault defaults[]
static const AVOption options[]
static av_cold int libkvazaar_init(AVCodecContext *avctx)
static av_cold int libkvazaar_close(AVCodecContext *avctx)
static enum AVPixelFormat pix_fmts[]
AVCodec ff_libkvazaar_encoder
static int libkvazaar_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Memory handling functions.
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.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
int64_t bit_rate
the average bitrate
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.