54 const kvz_api *
const api =
ctx->api = kvz_api_get(8);
56 kvz_encoder *enc =
NULL;
61 "Video dimensions are not a multiple of 8 (%dx%d).\n",
66 ctx->config =
cfg = api->config_alloc();
69 "Could not allocate kvazaar config structure.\n");
73 if (!api->config_init(
cfg)) {
75 "Could not initialize kvazaar config structure.\n");
93 cfg->rc_algorithm = KVZ_LAMBDA;
103 if (
ctx->kvz_params) {
117 ctx->encoder = enc = api->encoder_open(
cfg);
124 kvz_data_chunk *data_out =
NULL;
125 kvz_data_chunk *chunk =
NULL;
129 if (!api->encoder_headers(enc, &data_out, &len_out))
134 ctx->api->chunk_free(data_out);
140 for (chunk = data_out; chunk !=
NULL; chunk = chunk->next) {
141 memcpy(p, chunk->data, chunk->len);
145 ctx->api->chunk_free(data_out);
156 ctx->api->encoder_close(
ctx->encoder);
157 ctx->api->config_destroy(
ctx->config);
169 kvz_picture *input_pic =
NULL;
170 kvz_picture *recon_pic =
NULL;
172 kvz_data_chunk *data_out =
NULL;
173 uint32_t len_out = 0;
179 if (
frame->width !=
ctx->config->width ||
180 frame->height !=
ctx->config->height) {
182 "Changing video dimensions during encoding is not supported. "
183 "(changed from %dx%d to %dx%d)\n",
184 ctx->config->width,
ctx->config->height,
192 "Changing pixel format during encoding is not supported. "
193 "(changed from %s to %s)\n",
201 input_pic =
ctx->api->picture_alloc(
frame->width,
frame->height);
216 int dst_linesizes[4] = {
227 input_pic->pts =
frame->pts;
230 retval =
ctx->api->encoder_encode(
ctx->encoder,
243 kvz_data_chunk *chunk =
NULL;
244 uint64_t written = 0;
252 for (chunk = data_out; chunk !=
NULL; chunk = chunk->next) {
254 memcpy(avpkt->
data + written, chunk->data, chunk->len);
255 written += chunk->len;
258 avpkt->
pts = recon_pic->pts;
259 avpkt->
dts = recon_pic->dts;
263 if (
frame_info.nal_unit_type >= KVZ_NAL_BLA_W_LP &&
264 frame_info.nal_unit_type <= KVZ_NAL_RSV_IRAP_VCL23) {
290 ctx->api->picture_free(input_pic);
291 ctx->api->picture_free(recon_pic);
292 ctx->api->chunk_free(data_out);
301#define OFFSET(x) offsetof(LibkvazaarContext, x)
302#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
304 {
"kvazaar-params",
"Set kvazaar parameters as a comma-separated list of key=value pairs.",
322 .p.name =
"libkvazaar",
331 .p.priv_class = &
class,
342 .p.wrapper_name =
"libkvazaar",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_libkvazaar_encoder
static const FFCodecDefault defaults[]
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.
static int FUNC frame_info(CodedBitstreamContext *ctx, RWContext *rw, APVRawFrameInfo *current)
#define CODEC_PIXFMTS_ARRAY(array)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#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.
int(* init)(AVBSFContext *ctx)
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
static CheckasmConfig cfg
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#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_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#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.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
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.
#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.
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
#define LIBAVUTIL_VERSION_INT
Macro definitions for various function/variable attributes.
static av_cold int libkvazaar_init(AVCodecContext *avctx)
static av_cold int libkvazaar_close(AVCodecContext *avctx)
static enum AVPixelFormat pix_fmts[]
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.
@ AVCHROMA_LOC_UNSPECIFIED
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_JPEG
Full range content.
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.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
int64_t bit_rate
the average bitrate
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
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
Out-of-band global headers that may be used by some codecs.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
This structure describes decoded (raw) audio or video data.
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.
static AVFormatContext * ctx