Go to the documentation of this file.
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;
182 if (
frame->width !=
ctx->config->width ||
183 frame->height !=
ctx->config->height) {
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",
204 input_pic =
ctx->api->picture_alloc(
frame->width,
frame->height);
219 int dst_linesizes[4] = {
230 input_pic->pts =
frame->pts;
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",
#define FF_ENABLE_DEPRECATION_WARNINGS
#define AV_LOG_WARNING
Something somehow does not look correct.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
AVPixelFormat
Pixel format.
static av_cold int init(AVCodecContext *avctx)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
static const AVOption options[]
This structure describes decoded (raw) audio or video data.
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
static av_cold int libkvazaar_init(AVCodecContext *avctx)
int flags
AV_CODEC_FLAG_*.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static enum AVPixelFormat pix_fmts[]
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
int64_t bit_rate
the average bitrate
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
enum AVPictureType pict_type
Picture type of the frame.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
#define AVERROR_EXTERNAL
Generic error in an external library.
int flags
A combination of AV_PKT_FLAG values.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
AVCodec ff_libkvazaar_encoder
static const AVCodecDefault defaults[]
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
static av_cold int libkvazaar_close(AVCodecContext *avctx)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define AV_INPUT_BUFFER_PADDING_SIZE
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
main external API structure.
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_B
Bi-dir predicted.
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 AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define FF_DISABLE_DEPRECATION_WARNINGS
@ AV_PICTURE_TYPE_P
Predicted.
This structure stores compressed data.
int width
picture width / height.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
static int libkvazaar_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
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.