Lines Matching refs:avctx

82 static av_cold int libx265_encode_close(AVCodecContext *avctx)
84 libx265Context *ctx = avctx->priv_data;
95 static av_cold int libx265_param_parse_float(AVCodecContext *avctx,
98 libx265Context *ctx = avctx->priv_data;
103 av_log(avctx, AV_LOG_ERROR, "Invalid value %2.2f for param \"%s\".\n", value, key);
110 static av_cold int libx265_param_parse_int(AVCodecContext *avctx,
113 libx265Context *ctx = avctx->priv_data;
118 av_log(avctx, AV_LOG_ERROR, "Invalid value %d for param \"%s\".\n", value, key);
125 static av_cold int libx265_encode_init(AVCodecContext *avctx)
127 libx265Context *ctx = avctx->priv_data;
129 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
138 av_log(avctx, AV_LOG_ERROR, "Could not allocate x265 param structure.\n");
145 av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", ctx->preset, ctx->tune);
146 av_log(avctx, AV_LOG_INFO, "Possible presets:");
148 av_log(avctx, AV_LOG_INFO, " %s", x265_preset_names[i]);
150 av_log(avctx, AV_LOG_INFO, "\n");
151 av_log(avctx, AV_LOG_INFO, "Possible tunes:");
153 av_log(avctx, AV_LOG_INFO, " %s", x265_tune_names[i]);
155 av_log(avctx, AV_LOG_INFO, "\n");
160 ctx->params->frameNumThreads = avctx->thread_count;
161 if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
162 ctx->params->fpsNum = avctx->framerate.num;
163 ctx->params->fpsDenom = avctx->framerate.den;
165 ctx->params->fpsNum = avctx->time_base.den;
166 ctx->params->fpsDenom = avctx->time_base.num * avctx->ticks_per_frame;
168 ctx->params->sourceWidth = avctx->width;
169 ctx->params->sourceHeight = avctx->height;
170 ctx->params->bEnablePsnr = !!(avctx->flags & AV_CODEC_FLAG_PSNR);
171 ctx->params->bOpenGOP = !(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP);
179 av_log(avctx, AV_LOG_ERROR, "Image size is too small (%dx%d).\n",
187 if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED)
189 avctx->color_range == AVCOL_RANGE_JPEG;
193 avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
194 avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
195 avctx->pix_fmt == AV_PIX_FMT_YUVJ444P;
197 if ((avctx->color_primaries <= AVCOL_PRI_SMPTE432 &&
198 avctx->color_primaries != AVCOL_PRI_UNSPECIFIED) ||
199 (avctx->color_trc <= AVCOL_TRC_ARIB_STD_B67 &&
200 avctx->color_trc != AVCOL_TRC_UNSPECIFIED) ||
201 (avctx->colorspace <= AVCOL_SPC_ICTCP &&
202 avctx->colorspace != AVCOL_SPC_UNSPECIFIED)) {
207 ctx->params->vui.colorPrimaries = avctx->color_primaries;
208 ctx->params->vui.transferCharacteristics = avctx->color_trc;
210 if (avctx->color_trc == AVCOL_TRC_ARIB_STD_B67)
213 ctx->params->vui.matrixCoeffs = avctx->colorspace;
220 avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED &&
226 avctx->chroma_sample_location - 1;
229 if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0) {
234 avctx->sample_aspect_ratio.num,
235 avctx->sample_aspect_ratio.den, 65535);
238 av_log(avctx, AV_LOG_ERROR, "Invalid SAR: %d:%d.\n", sar_num, sar_den);
249 av_log(avctx, AV_LOG_ERROR,
273 av_log(avctx, AV_LOG_ERROR,
284 av_log(avctx, AV_LOG_ERROR, "Invalid crf: %2.2f.\n", ctx->crf);
287 } else if (avctx->bit_rate > 0) {
288 ctx->params->rc.bitrate = avctx->bit_rate / 1000;
291 ret = libx265_param_parse_int(avctx, "qp", ctx->cqp);
297 if (avctx->qmin >= 0) {
298 ret = libx265_param_parse_int(avctx, "qpmin", avctx->qmin);
302 if (avctx->qmax >= 0) {
303 ret = libx265_param_parse_int(avctx, "qpmax", avctx->qmax);
308 if (avctx->max_qdiff >= 0) {
309 ret = libx265_param_parse_int(avctx, "qpstep", avctx->max_qdiff);
313 if (avctx->qblur >= 0) {
314 ret = libx265_param_parse_float(avctx, "qblur", avctx->qblur);
318 if (avctx->qcompress >= 0) {
319 ret = libx265_param_parse_float(avctx, "qcomp", avctx->qcompress);
323 if (avctx->i_quant_factor >= 0) {
324 ret = libx265_param_parse_float(avctx, "ipratio", avctx->i_quant_factor);
328 if (avctx->b_quant_factor >= 0) {
329 ret = libx265_param_parse_float(avctx, "pbratio", avctx->b_quant_factor);
334 ctx->params->rc.vbvBufferSize = avctx->rc_buffer_size / 1000;
335 ctx->params->rc.vbvMaxBitrate = avctx->rc_max_rate / 1000;
337 cpb_props = ff_add_cpb_side_data(avctx);
344 if (!(avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER))
347 if (avctx->gop_size >= 0) {
348 ret = libx265_param_parse_int(avctx, "keyint", avctx->gop_size);
352 if (avctx->keyint_min > 0) {
353 ret = libx265_param_parse_int(avctx, "min-keyint", avctx->keyint_min);
357 if (avctx->max_b_frames >= 0) {
358 ret = libx265_param_parse_int(avctx, "bframes", avctx->max_b_frames);
362 if (avctx->refs >= 0) {
363 ret = libx265_param_parse_int(avctx, "ref", avctx->refs);
375 av_log(avctx, AV_LOG_WARNING,
379 av_log(avctx, AV_LOG_WARNING,
388 if (ctx->params->rc.vbvBufferSize && avctx->rc_initial_buffer_occupancy > 1000 &&
390 ctx->params->rc.vbvBufferInit = (float)avctx->rc_initial_buffer_occupancy / 1000;
396 av_log(avctx, AV_LOG_ERROR, "Invalid or incompatible profile set: %s.\n", ctx->profile);
397 av_log(avctx, AV_LOG_INFO, "Possible profiles:");
399 av_log(avctx, AV_LOG_INFO, " %s", x265_profile_names[i]);
400 av_log(avctx, AV_LOG_INFO, "\n");
407 av_log(avctx, AV_LOG_ERROR, "Cannot open libx265 encoder.\n");
408 libx265_encode_close(avctx);
412 if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
416 avctx->extradata_size = ctx->api->encoder_headers(ctx->encoder, &nal, &nnal);
417 if (avctx->extradata_size <= 0) {
418 av_log(avctx, AV_LOG_ERROR, "Cannot encode headers.\n");
419 libx265_encode_close(avctx);
423 avctx->extradata = av_malloc(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
424 if (!avctx->extradata) {
425 av_log(avctx, AV_LOG_ERROR,
426 "Cannot allocate HEVC header of size %d.\n", avctx->extradata_size);
427 libx265_encode_close(avctx);
431 memcpy(avctx->extradata, nal[0].payload, avctx->extradata_size);
432 memset(avctx->extradata + avctx->extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
502 static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
505 libx265Context *ctx = avctx->priv_data;
527 x265pic.bitDepth = av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth;
592 ret = ff_get_encode_buffer(avctx, pkt, payload, 0);
594 av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
623 av_log(avctx, AV_LOG_ERROR, "Unknown picture type encountered.\n");
637 memcpy(&avctx->reordered_opaque, x265pic_out.userData, sizeof(avctx->reordered_opaque));
640 avctx->reordered_opaque = 0;