54 const kvz_api *
const api = ctx->
api = kvz_api_get(8);
55 kvz_config *cfg =
NULL;
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");
79 cfg->width = avctx->
width;
80 cfg->height = avctx->
height;
84 "Could not set framerate for kvazaar: integer overflow\n");
89 cfg->target_bitrate = avctx->
bit_rate;
98 if (!api->config_parse(cfg, entry->
key, entry->
value)) {
107 ctx->
encoder = enc = api->encoder_open(cfg);
114 kvz_data_chunk *data_out =
NULL;
115 kvz_data_chunk *chunk =
NULL;
119 if (!api->encoder_headers(enc, &data_out, &len_out))
124 ctx->
api->chunk_free(data_out);
130 for (chunk = data_out; chunk !=
NULL; chunk = chunk->next) {
131 memcpy(p, chunk->data, chunk->len);
135 ctx->
api->chunk_free(data_out);
162 kvz_picture *input_pic =
NULL;
163 kvz_picture *recon_pic =
NULL;
164 kvz_frame_info frame_info;
165 kvz_data_chunk *data_out =
NULL;
166 uint32_t len_out = 0;
175 "Changing video dimensions during encoding is not supported. "
176 "(changed from %dx%d to %dx%d)\n",
185 "Changing pixel format during encoding is not supported. "
186 "(changed from %s to %s)\n",
203 int dst_linesizes[4] = {
214 input_pic->pts = frame->
pts;
217 retval = ctx->
api->encoder_encode(ctx->
encoder,
231 kvz_data_chunk *chunk =
NULL;
232 uint64_t written = 0;
240 for (chunk = data_out; chunk !=
NULL; chunk = chunk->next) {
242 memcpy(avpkt->
data + written, chunk->data, chunk->len);
243 written += chunk->len;
246 avpkt->
pts = recon_pic->pts;
247 avpkt->
dts = recon_pic->dts;
251 if (frame_info.nal_unit_type >= KVZ_NAL_BLA_W_LP &&
252 frame_info.nal_unit_type <= KVZ_NAL_RSV_IRAP_VCL23) {
260 ctx->
api->picture_free(input_pic);
261 ctx->
api->picture_free(recon_pic);
262 ctx->
api->chunk_free(data_out);
271 #define OFFSET(x) offsetof(LibkvazaarContext, x)
272 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
274 {
"kvazaar-params",
"Set kvazaar parameters as a comma-separated list of key=value pairs.",
292 .
name =
"libkvazaar",
299 .priv_class = &
class,
301 .defaults = defaults,
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
#define LIBAVUTIL_VERSION_INT
Memory handling functions.
static av_cold int init(AVCodecContext *avctx)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
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...
AVCodec ff_libkvazaar_encoder
Macro definitions for various function/variable attributes.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#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.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
int flags
AV_CODEC_FLAG_*.
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
int ff_alloc_packet(AVPacket *avpkt, int size)
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.
int flags
A combination of AV_PKT_FLAG values.
static const AVOption options[]
common internal API header
int width
picture width / height.
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
static const AVCodecDefault defaults[]
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
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.
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Describe the class of an AVClass context structure.
static int libkvazaar_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
static av_cold int libkvazaar_init(AVCodecContext *avctx)
static enum AVPixelFormat pix_fmts[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
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.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...