int log_level;
void *encoder;
- char *xavs2_opts;
+ AVDictionary *xavs2_opts;
xavs2_outpacket_t packet;
xavs2_param_t *param;
static av_cold int xavs2_init(AVCodecContext *avctx)
{
- XAVS2EContext *cae= avctx->priv_data;
+ XAVS2EContext *cae = avctx->priv_data;
int bit_depth, code;
bit_depth = avctx->pix_fmt == AV_PIX_FMT_YUV420P ? 8 : 10;
/* get API handler */
cae->api = xavs2_api_get(bit_depth);
if (!cae->api) {
- av_log(avctx, AV_LOG_ERROR, "api get failed\n");
+ av_log(avctx, AV_LOG_ERROR, "Failed to get xavs2 api context\n");
return AVERROR_EXTERNAL;
}
cae->param = cae->api->opt_alloc();
if (!cae->param) {
- av_log(avctx, AV_LOG_ERROR, "param alloc failed\n");
+ av_log(avctx, AV_LOG_ERROR, "Failed to alloc xavs2 parameters\n");
return AVERROR(ENOMEM);
}
xavs2_opt_set2("OpenGOP", "%d", !(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP));
- if (cae->xavs2_opts) {
- AVDictionary *dict = NULL;
+ {
AVDictionaryEntry *en = NULL;
-
- if (!av_dict_parse_string(&dict, cae->xavs2_opts, "=", ":", 0)) {
- while ((en = av_dict_get(dict, "", en, AV_DICT_IGNORE_SUFFIX))) {
- xavs2_opt_set2(en->key, "%s", en->value);
- }
- av_dict_free(&dict);
- }
+ while ((en = av_dict_get(cae->xavs2_opts, "", en, AV_DICT_IGNORE_SUFFIX)))
+ xavs2_opt_set2(en->key, "%s", en->value);
}
/* Rate control */
xavs2_opt_set2("InitialQP", "%d", cae->qp);
}
-
ff_mpeg12_find_best_frame_rate(avctx->framerate, &code, NULL, NULL, 0);
-
xavs2_opt_set2("FrameRate", "%d", code);
cae->encoder = cae->api->encoder_create(cae->param);
if (!cae->encoder) {
- av_log(avctx,AV_LOG_ERROR, "Can not create encoder. Null pointer returned\n");
+ av_log(avctx, AV_LOG_ERROR, "Failed to create xavs2 encoder instance.\n");
return AVERROR(EINVAL);
}
/* create the XAVS2 video encoder */
/* read frame data and send to the XAVS2 video encoder */
if (cae->api->encoder_get_buffer(cae->encoder, &pic) < 0) {
- av_log(avctx,AV_LOG_ERROR, "failed to get frame buffer\n");
+ av_log(avctx, AV_LOG_ERROR, "Failed to get xavs2 frame buffer\n");
return AVERROR_EXTERNAL;
}
if (frame) {
ret = cae->api->encoder_encode(cae->encoder, &pic, &cae->packet);
if (ret) {
- av_log(avctx, AV_LOG_ERROR, "encode failed\n");
+ av_log(avctx, AV_LOG_ERROR, "Encoding error occured.\n");
return AVERROR_EXTERNAL;
}
cae->api->encoder_encode(cae->encoder, NULL, &cae->packet);
}
- if ((cae->packet.len) && (cae->packet.state != XAVS2_STATE_FLUSH_END)){
-
- if (av_new_packet(pkt, cae->packet.len) < 0){
- av_log(avctx, AV_LOG_ERROR, "packet alloc failed\n");
+ if ((cae->packet.len) && (cae->packet.state != XAVS2_STATE_FLUSH_END)) {
+ if (av_new_packet(pkt, cae->packet.len) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to alloc xavs2 packet.\n");
cae->api->encoder_packet_unref(cae->encoder, &cae->packet);
return AVERROR(ENOMEM);
}
pkt->pts = cae->packet.pts;
pkt->dts = cae->packet.dts;
+ if (cae->packet.type == XAVS2_TYPE_IDR ||
+ cae->packet.type == XAVS2_TYPE_I ||
+ cae->packet.type == XAVS2_TYPE_KEYFRAME) {
+ pkt->flags |= AV_PKT_FLAG_KEY;
+ }
+
memcpy(pkt->data, cae->packet.stream, cae->packet.len);
pkt->size = cae->packet.len;
{ "min_qp" , "min qp for rate control" , OFFSET(min_qp) , AV_OPT_TYPE_INT, {.i64 = 20 }, 0, 63, VE },
{ "speed_level" , "Speed level, higher is better but slower", OFFSET(preset_level) , AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 9, VE },
{ "log_level" , "log level: -1: none, 0: error, 1: warning, 2: info, 3: debug", OFFSET(log_level) , AV_OPT_TYPE_INT, {.i64 = 0 }, -1, 3, VE },
- { "xavs2-params" , "set the xavs2 configuration using a :-separated list of key=value parameters", OFFSET(xavs2_opts), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
+ { "xavs2-params" , "set the xavs2 configuration using a :-separated list of key=value parameters", OFFSET(xavs2_opts), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
{ NULL },
};
.init = xavs2_init,
.encode2 = xavs2_encode_frame,
.close = xavs2_close,
- .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
+ .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS,
+ .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
AV_PIX_FMT_NONE },
.priv_class = &libxavs2,