50 const kvz_api *
const api = ctx->
api = kvz_api_get(8);
51 kvz_config *cfg =
NULL;
52 kvz_encoder *enc =
NULL;
57 "Video dimensions are not a multiple of 8 (%dx%d).\n",
62 ctx->
config = cfg = api->config_alloc();
65 "Could not allocate kvazaar config structure.\n");
69 if (!api->config_init(cfg)) {
71 "Could not initialize kvazaar config structure.\n");
75 cfg->width = avctx->
width;
76 cfg->height = avctx->
height;
80 "Could not set framerate for kvazaar: integer overflow\n");
85 cfg->target_bitrate = avctx->
bit_rate;
94 if (!api->config_parse(cfg, entry->
key, entry->
value)) {
103 ctx->
encoder = enc = api->encoder_open(cfg);
110 kvz_data_chunk *data_out =
NULL;
111 kvz_data_chunk *chunk =
NULL;
115 if (!api->encoder_headers(enc, &data_out, &len_out))
120 ctx->
api->chunk_free(data_out);
126 for (chunk = data_out; chunk !=
NULL; chunk = chunk->next) {
127 memcpy(p, chunk->data, chunk->len);
131 ctx->
api->chunk_free(data_out);
158 kvz_picture *input_pic =
NULL;
159 kvz_picture *recon_pic =
NULL;
160 kvz_frame_info frame_info;
161 kvz_data_chunk *data_out =
NULL;
162 uint32_t len_out = 0;
171 "Changing video dimensions during encoding is not supported. "
172 "(changed from %dx%d to %dx%d)\n",
181 "Changing pixel format during encoding is not supported. "
182 "(changed from %s to %s)\n",
199 int dst_linesizes[4] = {
210 input_pic->pts = frame->
pts;
213 retval = ctx->
api->encoder_encode(ctx->
encoder,
227 kvz_data_chunk *chunk =
NULL;
228 uint64_t written = 0;
236 for (chunk = data_out; chunk !=
NULL; chunk = chunk->next) {
238 memcpy(avpkt->
data + written, chunk->data, chunk->len);
239 written += chunk->len;
242 avpkt->
pts = recon_pic->pts;
243 avpkt->
dts = recon_pic->dts;
247 if (frame_info.nal_unit_type >= KVZ_NAL_BLA_W_LP &&
248 frame_info.nal_unit_type <= KVZ_NAL_RSV_IRAP_VCL23) {
256 ctx->
api->picture_free(input_pic);
257 ctx->
api->picture_free(recon_pic);
258 ctx->
api->chunk_free(data_out);
267 #define OFFSET(x) offsetof(LibkvazaarContext, x)
268 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
270 {
"kvazaar-params",
"Set kvazaar parameters as a comma-separated list of key=value pairs.",
288 .
name =
"libkvazaar",
295 .priv_class = &
class,
297 .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
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
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.
int width
width and height of the video frame
#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.
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...
attribute_deprecated int ff_alloc_packet(AVPacket *avpkt, int size)
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...