FFmpeg
Loading...
Searching...
No Matches
libx264.c
Go to the documentation of this file.
1/*
2 * H.264 encoding using the x264 library
3 * Copyright (C) 2005 Mans Rullgard <mans@mansr.com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "config_components.h"
23
24#include "libavutil/buffer.h"
25#include "libavutil/internal.h"
26#include "libavutil/opt.h"
28#include "libavutil/mem.h"
29#include "libavutil/pixdesc.h"
30#include "libavutil/stereo3d.h"
31#include "libavutil/time.h"
33#include "avcodec.h"
34#include "codec_internal.h"
35#include "encode.h"
36#include "internal.h"
37#include "packet_internal.h"
38#include "atsc_a53.h"
39#include "sei.h"
40#include "golomb.h"
41
42#include <x264.h>
43#include <float.h>
44#include <math.h>
45#include <stdio.h>
46#include <stdlib.h>
47#include <string.h>
48
49// from x264.h, for quant_offsets, Macroblocks are 16x16
50// blocks of pixels (with respect to the luma plane)
51#define MB_SIZE 16
52#define MB_LSIZE 4
53#define MB_FLOOR(x) ((x) >> (MB_LSIZE))
54#define MB_CEIL(x) MB_FLOOR((x) + (MB_SIZE - 1))
55
63
64typedef struct X264Context {
65 AVClass *class;
66 x264_param_t params;
67 x264_t *enc;
68 x264_picture_t pic;
69 uint8_t *sei;
71 char *preset;
72 char *tune;
73 const char *profile;
75 char *level;
77 char *wpredp;
78 char *x264opts;
79 float crf;
80 float crf_max;
81 int cqp;
84 char *psy_rd;
85 int psy;
89 int ssim;
92 int b_bias;
95 int dct8x8;
97 int aud;
98 int mbtree;
99 char *deblock;
100 float cplxblur;
104 char *stats;
109 int coder;
116
118
121
122 /**
123 * If the encoder does not support ROI then warn the first time we
124 * encounter a frame with ROI side data.
125 */
127
130
131static void X264_log(void *p, int level, const char *fmt, va_list args)
132{
133 static const int level_map[] = {
134 [X264_LOG_ERROR] = AV_LOG_ERROR,
135 [X264_LOG_WARNING] = AV_LOG_WARNING,
136 [X264_LOG_INFO] = AV_LOG_INFO,
137 [X264_LOG_DEBUG] = AV_LOG_DEBUG
138 };
139
140 if (level < 0 || level > X264_LOG_DEBUG)
141 return;
142
143 av_vlog(p, level_map[level], fmt, args);
144}
145
147{
149 memset(o, 0, sizeof(*o));
150}
151
153 const x264_nal_t *nals, int nnal)
154{
155 X264Context *x4 = ctx->priv_data;
156 uint8_t *p;
157 uint64_t size = FFMAX(x4->sei_size, 0);
158 int ret;
159
160 if (!nnal)
161 return 0;
162
163 for (int i = 0; i < nnal; i++) {
164 size += nals[i].i_payload;
165 /* ff_get_encode_buffer() accepts an int64_t and
166 * so we need to make sure that no overflow happens before
167 * that. With 32bit ints this is automatically true. */
168#if INT_MAX > INT64_MAX / INT_MAX - 1
169 if ((int64_t)size < 0)
170 return AVERROR(ERANGE);
171#endif
172 }
173
174 if ((ret = ff_get_encode_buffer(ctx, pkt, size, 0)) < 0)
175 return ret;
176
177 p = pkt->data;
178
179 /* Write the SEI as part of the first frame. */
180 if (x4->sei_size > 0) {
181 memcpy(p, x4->sei, x4->sei_size);
182 p += x4->sei_size;
183 size -= x4->sei_size;
184 /* Keep the value around in case of flush */
185 x4->sei_size = -x4->sei_size;
186 }
187
188 /* x264 guarantees the payloads of the NALs
189 * to be sequential in memory. */
190 memcpy(p, nals[0].p_payload, size);
191
192 return 1;
193}
194
196{
197 X264Context *x4 = ctx->priv_data;
198
199 if (x4->avcintra_class >= 0)
200 return;
201
202 if (x4->params.vui.i_sar_height*ctx->sample_aspect_ratio.num != ctx->sample_aspect_ratio.den * x4->params.vui.i_sar_width) {
203 x4->params.vui.i_sar_height = ctx->sample_aspect_ratio.den;
204 x4->params.vui.i_sar_width = ctx->sample_aspect_ratio.num;
205 x264_encoder_reconfig(x4->enc, &x4->params);
206 }
207
208 if (x4->params.rc.i_vbv_buffer_size != ctx->rc_buffer_size / 1000 ||
209 x4->params.rc.i_vbv_max_bitrate != ctx->rc_max_rate / 1000) {
210 x4->params.rc.i_vbv_buffer_size = ctx->rc_buffer_size / 1000;
211 x4->params.rc.i_vbv_max_bitrate = ctx->rc_max_rate / 1000;
212 x264_encoder_reconfig(x4->enc, &x4->params);
213 }
214
215 if (x4->params.rc.i_rc_method == X264_RC_ABR &&
216 x4->params.rc.i_bitrate != ctx->bit_rate / 1000) {
217 x4->params.rc.i_bitrate = ctx->bit_rate / 1000;
218 x264_encoder_reconfig(x4->enc, &x4->params);
219 }
220
221 if (x4->crf >= 0 &&
222 x4->params.rc.i_rc_method == X264_RC_CRF &&
223 x4->params.rc.f_rf_constant != x4->crf) {
224 x4->params.rc.f_rf_constant = x4->crf;
225 x264_encoder_reconfig(x4->enc, &x4->params);
226 }
227
228 if (x4->params.rc.i_rc_method == X264_RC_CQP &&
229 x4->cqp >= 0 &&
230 x4->params.rc.i_qp_constant != x4->cqp) {
231 x4->params.rc.i_qp_constant = x4->cqp;
232 x264_encoder_reconfig(x4->enc, &x4->params);
233 }
234
235 if (x4->crf_max >= 0 &&
236 x4->params.rc.f_rf_constant_max != x4->crf_max) {
237 x4->params.rc.f_rf_constant_max = x4->crf_max;
238 x264_encoder_reconfig(x4->enc, &x4->params);
239 }
240}
241
243{
244 X264Context *x4 = ctx->priv_data;
245 AVFrameSideData *side_data;
246
248
249 if (x4->avcintra_class < 0) {
250 if (x4->params.b_interlaced && x4->params.b_tff != !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST)) {
251
252 x4->params.b_tff = !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST);
253 x264_encoder_reconfig(x4->enc, &x4->params);
254 }
255 }
256
258 if (side_data) {
259 AVStereo3D *stereo = (AVStereo3D *)side_data->data;
260 int fpa_type;
261
262 switch (stereo->type) {
264 fpa_type = 0;
265 break;
267 fpa_type = 1;
268 break;
270 fpa_type = 2;
271 break;
273 fpa_type = 3;
274 break;
276 fpa_type = 4;
277 break;
279 fpa_type = 5;
280 break;
281 case AV_STEREO3D_2D:
282 fpa_type = 6;
283 break;
284 default:
285 fpa_type = -1;
286 break;
287 }
288
289 /* Inverted mode is not supported by x264 */
290 if (stereo->flags & AV_STEREO3D_FLAG_INVERT) {
292 "Ignoring unsupported inverted stereo value %d\n", fpa_type);
293 fpa_type = -1;
294 }
295
296 if (fpa_type != x4->params.i_frame_packing) {
297 x4->params.i_frame_packing = fpa_type;
298 x264_encoder_reconfig(x4->enc, &x4->params);
299 }
300 }
301}
302
303static void free_picture(x264_picture_t *pic)
304{
305 for (int i = 0; i < pic->extra_sei.num_payloads; i++)
306 av_free(pic->extra_sei.payloads[i].payload);
307 av_freep(&pic->extra_sei.payloads);
308 av_freep(&pic->prop.quant_offsets);
309 av_freep(&pic->prop.mb_info);
310 pic->extra_sei.num_payloads = 0;
311}
312
313static enum AVPixelFormat csp_to_pixfmt(int csp)
314{
315 switch (csp) {
316#ifdef X264_CSP_I400
317 case X264_CSP_I400: return AV_PIX_FMT_GRAY8;
318 case X264_CSP_I400 | X264_CSP_HIGH_DEPTH: return AV_PIX_FMT_GRAY10;
319#endif
320 case X264_CSP_I420: return AV_PIX_FMT_YUV420P;
321 case X264_CSP_I420 | X264_CSP_HIGH_DEPTH: return AV_PIX_FMT_YUV420P10;
322 case X264_CSP_I422: return AV_PIX_FMT_YUV422P;
323 case X264_CSP_I422 | X264_CSP_HIGH_DEPTH: return AV_PIX_FMT_YUV422P10;
324 case X264_CSP_I444: return AV_PIX_FMT_YUV444P;
325 case X264_CSP_I444 | X264_CSP_HIGH_DEPTH: return AV_PIX_FMT_YUV444P10;
326 case X264_CSP_NV12: return AV_PIX_FMT_NV12;
327#ifdef X264_CSP_NV21
328 case X264_CSP_NV21: return AV_PIX_FMT_NV21;
329#endif
330 case X264_CSP_NV16: return AV_PIX_FMT_NV16;
331 };
332 return AV_PIX_FMT_NONE;
333}
334
336 int *min_x,
337 int *max_x,
338 int *min_y,
339 int *max_y)
340{
341 *min_y = MB_FLOOR(rect->y);
342 *max_y = MB_CEIL(rect->y + rect->height);
343 *min_x = MB_FLOOR(rect->x);
344 *max_x = MB_CEIL(rect->x + rect->width);
345}
346
348 int *min_x,
349 int *max_x,
350 int *min_y,
351 int *max_y)
352{
353 *min_y = MB_CEIL(rect->y);
354 *max_y = MB_FLOOR(rect->y + rect->height);
355 *min_x = MB_CEIL(rect->x);
356 *max_x = MB_FLOOR(rect->x + rect->width);
357}
358
359static int setup_mb_info(AVCodecContext *ctx, x264_picture_t *pic,
360 const AVFrame *frame,
361 const AVVideoHint *info)
362{
363 int mb_width = (frame->width + MB_SIZE - 1) / MB_SIZE;
364 int mb_height = (frame->height + MB_SIZE - 1) / MB_SIZE;
365
366 const AVVideoRect *mbinfo_rects;
367 int nb_rects;
368 uint8_t *mbinfo;
369
370 mbinfo_rects = (const AVVideoRect *)av_video_hint_rects(info);
371 nb_rects = info->nb_rects;
372
373 mbinfo = av_calloc(mb_width * mb_height, sizeof(*mbinfo));
374 if (!mbinfo)
375 return AVERROR(ENOMEM);
376
377#define COMPUTE_MBINFO(mbinfo_filler_, mbinfo_marker_, compute_coords_fn_) \
378 memset(mbinfo, mbinfo_filler_, sizeof(*mbinfo) * mb_width * mb_height); \
379 \
380 for (int i = 0; i < nb_rects; i++) { \
381 int min_x, max_x, min_y, max_y; \
382 \
383 compute_coords_fn_(mbinfo_rects, &min_x, &max_x, &min_y, &max_y); \
384 for (int mb_y = min_y; mb_y < max_y; ++mb_y) { \
385 memset(mbinfo + mb_y * mb_width + min_x, mbinfo_marker_, max_x - min_x); \
386 } \
387 \
388 mbinfo_rects++; \
389 } \
390
391 if (info->type == AV_VIDEO_HINT_TYPE_CHANGED) {
392 COMPUTE_MBINFO(X264_MBINFO_CONSTANT, 0, mbinfo_compute_changed_coords);
393 } else /* if (info->type == AV_VIDEO_HINT_TYPE_CHANGED) */ {
394 COMPUTE_MBINFO(0, X264_MBINFO_CONSTANT, mbinfo_compute_constant_coords);
395 }
396
397 pic->prop.mb_info = mbinfo;
398 pic->prop.mb_info_free = av_free;
399
400 return 0;
401}
402
403static int setup_roi(AVCodecContext *ctx, x264_picture_t *pic,
404 const AVFrame *frame, const uint8_t *data, size_t size)
405{
406 X264Context *x4 = ctx->priv_data;
407
408 int mbx = (frame->width + MB_SIZE - 1) / MB_SIZE;
409 int mby = (frame->height + MB_SIZE - 1) / MB_SIZE;
410 int qp_range = 51 + 6 * (x4->params.i_bitdepth - 8);
411 int nb_rois;
412 const AVRegionOfInterest *roi;
413 uint32_t roi_size;
414 float *qoffsets;
415
416 if (x4->params.rc.i_aq_mode == X264_AQ_NONE) {
417 if (!x4->roi_warned) {
418 x4->roi_warned = 1;
419 av_log(ctx, AV_LOG_WARNING, "Adaptive quantization must be enabled to use ROI encoding, skipping ROI.\n");
420 }
421 return 0;
422 } else if (frame->flags & AV_FRAME_FLAG_INTERLACED) {
423 if (!x4->roi_warned) {
424 x4->roi_warned = 1;
425 av_log(ctx, AV_LOG_WARNING, "interlaced_frame not supported for ROI encoding yet, skipping ROI.\n");
426 }
427 return 0;
428 }
429
430 roi = (const AVRegionOfInterest*)data;
431 roi_size = roi->self_size;
432 if (!roi_size || size % roi_size != 0) {
433 av_log(ctx, AV_LOG_ERROR, "Invalid AVRegionOfInterest.self_size.\n");
434 return AVERROR(EINVAL);
435 }
436 nb_rois = size / roi_size;
437
438 qoffsets = av_calloc(mbx * mby, sizeof(*qoffsets));
439 if (!qoffsets)
440 return AVERROR(ENOMEM);
441
442 // This list must be iterated in reverse because the first
443 // region in the list applies when regions overlap.
444 for (int i = nb_rois - 1; i >= 0; i--) {
445 int startx, endx, starty, endy;
446 float qoffset;
447
448 roi = (const AVRegionOfInterest*)(data + roi_size * i);
449
450 starty = FFMIN(mby, roi->top / MB_SIZE);
451 endy = FFMIN(mby, (roi->bottom + MB_SIZE - 1)/ MB_SIZE);
452 startx = FFMIN(mbx, roi->left / MB_SIZE);
453 endx = FFMIN(mbx, (roi->right + MB_SIZE - 1)/ MB_SIZE);
454
455 if (roi->qoffset.den == 0) {
456 av_free(qoffsets);
457 av_log(ctx, AV_LOG_ERROR, "AVRegionOfInterest.qoffset.den must not be zero.\n");
458 return AVERROR(EINVAL);
459 }
460 qoffset = roi->qoffset.num * 1.0f / roi->qoffset.den;
461 qoffset = av_clipf(qoffset * qp_range, -qp_range, +qp_range);
462
463 for (int y = starty; y < endy; y++) {
464 for (int x = startx; x < endx; x++) {
465 qoffsets[x + y*mbx] = qoffset;
466 }
467 }
468 }
469
470 pic->prop.quant_offsets = qoffsets;
471 pic->prop.quant_offsets_free = av_free;
472
473 return 0;
474}
475
477 x264_picture_t **ppic)
478{
479 X264Context *x4 = ctx->priv_data;
481 x264_picture_t *pic = &x4->pic;
482 x264_sei_t *sei = &pic->extra_sei;
483 unsigned int sei_data_size = 0;
484 int64_t wallclock = 0;
485 int ret;
486 AVFrameSideData *sd;
487 AVFrameSideData *mbinfo_sd;
488
489 *ppic = NULL;
490 if (!frame)
491 return 0;
492
493 x264_picture_init(pic);
494 pic->img.i_csp = x4->params.i_csp;
495 if (x4->params.i_bitdepth > 8)
496 pic->img.i_csp |= X264_CSP_HIGH_DEPTH;
497 pic->img.i_plane = av_pix_fmt_count_planes(ctx->pix_fmt);
498
499 for (int i = 0; i < pic->img.i_plane; i++) {
500 pic->img.plane[i] = frame->data[i];
501 pic->img.i_stride[i] = frame->linesize[i];
502 }
503
504 pic->i_pts = frame->pts;
505
506 opaque_uninit(opaque);
507
508 if (ctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
509 opaque->frame_opaque = frame->opaque;
510 ret = av_buffer_replace(&opaque->frame_opaque_ref, frame->opaque_ref);
511 if (ret < 0)
512 goto fail;
513 }
514
515 opaque->duration = frame->duration;
516 opaque->wallclock = wallclock;
517 if (ctx->export_side_data & AV_CODEC_EXPORT_DATA_PRFT)
518 opaque->wallclock = av_gettime();
519
520 pic->opaque = opaque;
521
524
525 switch (frame->pict_type) {
527 pic->i_type = x4->forced_idr > 0 ? X264_TYPE_IDR : X264_TYPE_KEYFRAME;
528 break;
530 pic->i_type = X264_TYPE_P;
531 break;
533 pic->i_type = X264_TYPE_B;
534 break;
535 default:
536 pic->i_type = X264_TYPE_AUTO;
537 break;
538 }
540
541 if (x4->a53_cc) {
542 void *sei_data;
543 size_t sei_size;
544
545 ret = ff_alloc_a53_sei(frame, 0, &sei_data, &sei_size);
546 if (ret < 0)
547 goto fail;
548
549 if (sei_data) {
550 sei->payloads = av_mallocz(sizeof(sei->payloads[0]));
551 if (!sei->payloads) {
552 av_free(sei_data);
553 ret = AVERROR(ENOMEM);
554 goto fail;
555 }
556
557 sei->sei_free = av_free;
558
559 sei->payloads[0].payload_size = sei_size;
560 sei->payloads[0].payload = sei_data;
561 sei->payloads[0].payload_type = SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35;
562 sei->num_payloads = 1;
563 }
564 }
565
567 if (sd) {
568 ret = setup_roi(ctx, pic, frame, sd->data, sd->size);
569 if (ret < 0)
570 goto fail;
571 }
572
574 if (mbinfo_sd) {
575 int err = setup_mb_info(ctx, pic, frame, (const AVVideoHint *)mbinfo_sd->data);
576 if (err < 0) {
577 /* No need to fail here, this is not fatal. We just proceed with no
578 * mb_info and log a message */
579
580 av_log(ctx, AV_LOG_WARNING, "setup_mb_info failed with error: %s\n", av_err2str(err));
581 }
582 }
583
584 if (x4->udu_sei) {
585 for (int j = 0; j < frame->nb_side_data; j++) {
586 AVFrameSideData *side_data = frame->side_data[j];
587 void *tmp;
588 x264_sei_payload_t *sei_payload;
589 if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
590 continue;
591 tmp = av_fast_realloc(sei->payloads, &sei_data_size, (sei->num_payloads + 1) * sizeof(*sei_payload));
592 if (!tmp) {
593 ret = AVERROR(ENOMEM);
594 goto fail;
595 }
596 sei->payloads = tmp;
597 sei->sei_free = av_free;
598 sei_payload = &sei->payloads[sei->num_payloads];
599 sei_payload->payload = av_memdup(side_data->data, side_data->size);
600 if (!sei_payload->payload) {
601 ret = AVERROR(ENOMEM);
602 goto fail;
603 }
604 sei_payload->payload_size = side_data->size;
606 sei->num_payloads++;
607 }
608 }
609
610 *ppic = pic;
611 return 0;
612
613fail:
614 free_picture(pic);
615 *ppic = NULL;
616 return ret;
617}
618
620 int *got_packet)
621{
622 X264Context *x4 = ctx->priv_data;
623 x264_nal_t *nal;
624 int nnal, ret;
625 x264_picture_t pic_out = {0}, *pic_in;
626 enum AVPictureType pict_type;
627 int64_t wallclock = 0;
628 X264Opaque *out_opaque;
629
630 ret = setup_frame(ctx, frame, &pic_in);
631 if (ret < 0)
632 return ret;
633
634 do {
635 if (x264_encoder_encode(x4->enc, &nal, &nnal, pic_in, &pic_out) < 0)
636 return AVERROR_EXTERNAL;
637
638 if (nnal && (ctx->flags & AV_CODEC_FLAG_RECON_FRAME)) {
639 AVCodecInternal *avci = ctx->internal;
640
642
643 avci->recon_frame->format = csp_to_pixfmt(pic_out.img.i_csp);
644 if (avci->recon_frame->format == AV_PIX_FMT_NONE) {
646 "Unhandled reconstructed frame colorspace: %d\n",
647 pic_out.img.i_csp);
648 return AVERROR(ENOSYS);
649 }
650
651 avci->recon_frame->width = ctx->width;
652 avci->recon_frame->height = ctx->height;
653 for (int i = 0; i < pic_out.img.i_plane; i++) {
654 avci->recon_frame->data[i] = pic_out.img.plane[i];
655 avci->recon_frame->linesize[i] = pic_out.img.i_stride[i];
656 }
657
659 if (ret < 0) {
661 return ret;
662 }
663 }
664
665 ret = encode_nals(ctx, pkt, nal, nnal);
666 if (ret < 0)
667 return ret;
668 } while (!ret && !frame && x264_encoder_delayed_frames(x4->enc));
669
670 if (!ret)
671 return 0;
672
673 pkt->pts = pic_out.i_pts;
674 pkt->dts = pic_out.i_dts;
675
676 out_opaque = pic_out.opaque;
677 if (out_opaque >= x4->reordered_opaque &&
678 out_opaque < &x4->reordered_opaque[x4->nb_reordered_opaque]) {
679 wallclock = out_opaque->wallclock;
680 pkt->duration = out_opaque->duration;
681
682 if (ctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
683 pkt->opaque = out_opaque->frame_opaque;
684 pkt->opaque_ref = out_opaque->frame_opaque_ref;
685 out_opaque->frame_opaque_ref = NULL;
686 }
687
688 opaque_uninit(out_opaque);
689 } else {
690 // Unexpected opaque pointer on picture output
691 av_log(ctx, AV_LOG_ERROR, "Unexpected opaque pointer; "
692 "this is a bug, please report it.\n");
693 }
694
695 switch (pic_out.i_type) {
696 case X264_TYPE_IDR:
697 case X264_TYPE_I:
698 pict_type = AV_PICTURE_TYPE_I;
699 break;
700 case X264_TYPE_P:
701 pict_type = AV_PICTURE_TYPE_P;
702 break;
703 case X264_TYPE_B:
704 case X264_TYPE_BREF:
705 pict_type = AV_PICTURE_TYPE_B;
706 break;
707 default:
708 av_log(ctx, AV_LOG_ERROR, "Unknown picture type encountered.\n");
709 return AVERROR_EXTERNAL;
710 }
711
712 pkt->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe;
713 if (ret) {
714 int error_count = 0;
715 int64_t *errors = NULL;
716 int64_t sse[3] = {0};
717
718 if (ctx->flags & AV_CODEC_FLAG_PSNR) {
719 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(ctx->pix_fmt);
720 double scale[3] = { 1,
721 (double)(1 << pix_desc->log2_chroma_h) * (1 << pix_desc->log2_chroma_w),
722 (double)(1 << pix_desc->log2_chroma_h) * (1 << pix_desc->log2_chroma_w),
723 };
724
725 error_count = pix_desc->nb_components;
726
727 for (int i = 0; i < pix_desc->nb_components; ++i) {
728 double max_value = (double)(1 << pix_desc->comp[i].depth) - 1.0;
729 double plane_size = ctx->width * (double)ctx->height / scale[i];
730
731 /* psnr = 10 * log10(max_value * max_value / mse) */
732 double mse = (max_value * max_value) / pow(10, pic_out.prop.f_psnr[i] / 10.0);
733
734 /* SSE = MSE * width * height / scale -> because of possible chroma downsampling */
735 sse[i] = (int64_t)floor(mse * plane_size + .5);
736 }
737
738 errors = sse;
739 }
740
741 ff_encode_add_stats_side_data(pkt, (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA,
742 errors, error_count, pict_type);
743
744 if (wallclock)
745 ff_side_data_set_prft(pkt, wallclock);
746 }
747
748 *got_packet = ret;
749 return 0;
750}
751
752static void X264_flush(AVCodecContext *avctx)
753{
754 X264Context *x4 = avctx->priv_data;
755 x264_nal_t *nal;
756 int nnal, ret;
757 x264_picture_t pic_out = {0};
758
759 do {
760 ret = x264_encoder_encode(x4->enc, &nal, &nnal, NULL, &pic_out);
761 } while (ret > 0 && x264_encoder_delayed_frames(x4->enc));
762
763 for (int i = 0; i < x4->nb_reordered_opaque; i++)
765
766 if (x4->sei_size < 0)
767 x4->sei_size = -x4->sei_size;
768}
769
771{
772 int ret;
773
774 ret = ff_encode_reconf_parse_dict(avctx, dict);
775 if (ret < 0)
776 return ret;
777
778 reconfig_encoder(avctx);
779
780 return 0;
781}
782
784{
785 X264Context *x4 = avctx->priv_data;
786
787 av_freep(&x4->sei);
788
789 for (int i = 0; i < x4->nb_reordered_opaque; i++)
792
793#if X264_BUILD >= 161
794 x264_param_cleanup(&x4->params);
795#endif
796
797 if (x4->enc) {
798 x264_encoder_close(x4->enc);
799 x4->enc = NULL;
800 }
801
802 return 0;
803}
804
805static int parse_opts(AVCodecContext *avctx, const char *opt, const char *param)
806{
807 X264Context *x4 = avctx->priv_data;
808 int ret;
809
810 if ((ret = x264_param_parse(&x4->params, opt, param)) < 0) {
811 if (ret == X264_PARAM_BAD_NAME) {
812 av_log(avctx, AV_LOG_ERROR,
813 "bad option '%s': '%s'\n", opt, param);
814 ret = AVERROR(EINVAL);
815#if X264_BUILD >= 161
816 } else if (ret == X264_PARAM_ALLOC_FAILED) {
817 av_log(avctx, AV_LOG_ERROR,
818 "out of memory parsing option '%s': '%s'\n", opt, param);
819 ret = AVERROR(ENOMEM);
820#endif
821 } else {
822 av_log(avctx, AV_LOG_ERROR,
823 "bad value for '%s': '%s'\n", opt, param);
824 ret = AVERROR(EINVAL);
825 }
826 }
827
828 return ret;
829}
830
832{
833 switch (pix_fmt) {
837 case AV_PIX_FMT_YUV420P10: return X264_CSP_I420;
840 case AV_PIX_FMT_YUV422P10: return X264_CSP_I422;
844 case AV_PIX_FMT_YUV444P10: return X264_CSP_I444;
845 case AV_PIX_FMT_BGR0:
846 return X264_CSP_BGRA;
847 case AV_PIX_FMT_BGR24:
848 return X264_CSP_BGR;
849
850 case AV_PIX_FMT_RGB24:
851 return X264_CSP_RGB;
852 case AV_PIX_FMT_NV12: return X264_CSP_NV12;
853 case AV_PIX_FMT_NV16:
854 case AV_PIX_FMT_NV20: return X264_CSP_NV16;
855#ifdef X264_CSP_NV21
856 case AV_PIX_FMT_NV21: return X264_CSP_NV21;
857#endif
858#ifdef X264_CSP_I400
859 case AV_PIX_FMT_GRAY8:
860 case AV_PIX_FMT_GRAY10: return X264_CSP_I400;
861#endif
862 };
863 return 0;
864}
865
866static int save_sei(AVCodecContext *avctx, x264_nal_t *nal)
867{
868 X264Context *x4 = avctx->priv_data;
869
870 av_log(avctx, AV_LOG_INFO, "%s\n", nal->p_payload + 25);
871 x4->sei_size = nal->i_payload;
872 x4->sei = av_malloc(x4->sei_size);
873 if (!x4->sei)
874 return AVERROR(ENOMEM);
875
876 memcpy(x4->sei, nal->p_payload, nal->i_payload);
877
878 return 0;
879}
880
881#if CONFIG_LIBX264_ENCODER
882static int set_avcc_extradata(AVCodecContext *avctx, x264_nal_t *nal, int nnal)
883{
884 x264_nal_t *sps_nal = NULL;
885 x264_nal_t *pps_nal = NULL;
886 uint8_t *p, *sps;
887 int ret;
888
889 /* We know it's in the order of SPS/PPS/SEI, but it's not documented in x264 API.
890 * The x264 param i_sps_id implies there is a single pair of SPS/PPS.
891 */
892 for (int i = 0; i < nnal; i++) {
893 switch (nal[i].i_type) {
894 case NAL_SPS:
895 sps_nal = &nal[i];
896 break;
897 case NAL_PPS:
898 pps_nal = &nal[i];
899 break;
900 case NAL_SEI:
901 ret = save_sei(avctx, &nal[i]);
902 if (ret < 0)
903 return ret;
904 break;
905 }
906 }
907 if (!sps_nal || !pps_nal)
908 return AVERROR_EXTERNAL;
909
910 avctx->extradata_size = sps_nal->i_payload + pps_nal->i_payload + 7;
912 if (!avctx->extradata)
913 return AVERROR(ENOMEM);
914
915 // Now create AVCDecoderConfigurationRecord
916 p = avctx->extradata;
917 // Skip size part
918 sps = sps_nal->p_payload + 4;
919 *p++ = 1; // version
920 *p++ = sps[1]; // AVCProfileIndication
921 *p++ = sps[2]; // profile_compatibility
922 *p++ = sps[3]; // AVCLevelIndication
923 *p++ = 0xFF;
924 *p++ = 0xE0 | 0x01; // 3 bits reserved (111) + 5 bits number of sps
925 memcpy(p, sps_nal->p_payload + 2, sps_nal->i_payload - 2);
926 // Make sps has AV_INPUT_BUFFER_PADDING_SIZE padding, so it can be used
927 // with GetBitContext
928 sps = p + 2;
929 p += sps_nal->i_payload - 2;
930 *p++ = 1;
931 memcpy(p, pps_nal->p_payload + 2, pps_nal->i_payload - 2);
932 p += pps_nal->i_payload - 2;
933
934 if (sps[3] != 66 && sps[3] != 77 && sps[3] != 88) {
935 GetBitContext gbc;
936 int chroma_format_idc;
937 int bit_depth_luma_minus8, bit_depth_chroma_minus8;
938
939 /* It's not possible to have emulation prevention byte before
940 * bit_depth_chroma_minus8 due to the range of sps id, chroma_format_idc
941 * and so on. So we can read directly without need to escape emulation
942 * prevention byte.
943 *
944 * +4 to skip until sps id.
945 */
946 ret = init_get_bits8(&gbc, sps + 4, sps_nal->i_payload - 4 - 4);
947 if (ret < 0)
948 return ret;
949 // Skip sps id
950 get_ue_golomb_31(&gbc);
951 chroma_format_idc = get_ue_golomb_31(&gbc);
952 if (chroma_format_idc == 3)
953 skip_bits1(&gbc);
954 bit_depth_luma_minus8 = get_ue_golomb_31(&gbc);
955 bit_depth_chroma_minus8 = get_ue_golomb_31(&gbc);
956
957 *p++ = 0xFC | chroma_format_idc;
958 *p++ = 0xF8 | bit_depth_luma_minus8;
959 *p++ = 0xF8 | bit_depth_chroma_minus8;
960 *p++ = 0;
961 }
962 av_assert2(avctx->extradata + avctx->extradata_size >= p);
963 avctx->extradata_size = p - avctx->extradata;
964
965 return 0;
966}
967#endif
968
970{
971 X264Context *x4 = avctx->priv_data;
972 x264_nal_t *nal;
973 uint8_t *p;
974 int nnal, s;
975
976 s = x264_encoder_headers(x4->enc, &nal, &nnal);
977 if (s < 0)
978 return AVERROR_EXTERNAL;
979
980#if CONFIG_LIBX264_ENCODER
981 if (!x4->params.b_annexb)
982 return set_avcc_extradata(avctx, nal, nnal);
983#endif
984
986 if (!p)
987 return AVERROR(ENOMEM);
988
989 for (int i = 0; i < nnal; i++) {
990 /* Don't put the SEI in extradata. */
991 if (nal[i].i_type == NAL_SEI) {
992 s = save_sei(avctx, &nal[i]);
993 if (s < 0)
994 return s;
995 continue;
996 }
997 memcpy(p, nal[i].p_payload, nal[i].i_payload);
998 p += nal[i].i_payload;
999 }
1000 avctx->extradata_size = p - avctx->extradata;
1001
1002 return 0;
1003}
1004
1005#define PARSE_X264_OPT(name, var)\
1006 if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
1007 av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
1008 return AVERROR(EINVAL);\
1009 }
1010
1011#if CONFIG_LIBX264_HDR10
1012static void handle_mdcv(x264_param_t *params,
1013 const AVMasteringDisplayMetadata *mdcv)
1014{
1015 if (!mdcv->has_primaries && !mdcv->has_luminance)
1016 return;
1017
1018 params->mastering_display.b_mastering_display = 1;
1019
1020 if (mdcv->has_primaries) {
1021 int *const points[][2] = {
1022 {
1023 &params->mastering_display.i_red_x,
1024 &params->mastering_display.i_red_y
1025 },
1026 {
1027 &params->mastering_display.i_green_x,
1028 &params->mastering_display.i_green_y
1029 },
1030 {
1031 &params->mastering_display.i_blue_x,
1032 &params->mastering_display.i_blue_y
1033 },
1034 };
1035
1036 for (int i = 0; i < 3; i++) {
1037 const AVRational *src = mdcv->display_primaries[i];
1038 int *dst[2] = { points[i][0], points[i][1] };
1039
1040 *dst[0] = av_rescale_q(1, src[0], (AVRational){ 1, 50000 });
1041 *dst[1] = av_rescale_q(1, src[1], (AVRational){ 1, 50000 });
1042 }
1043
1044 params->mastering_display.i_white_x =
1045 av_rescale_q(1, mdcv->white_point[0], (AVRational){ 1, 50000 });
1046 params->mastering_display.i_white_y =
1047 av_rescale_q(1, mdcv->white_point[1], (AVRational){ 1, 50000 });
1048 }
1049
1050 if (mdcv->has_luminance) {
1051 params->mastering_display.i_display_max =
1052 av_rescale_q(1, mdcv->max_luminance, (AVRational){ 1, 10000 });
1053 params->mastering_display.i_display_min =
1054 av_rescale_q(1, mdcv->min_luminance, (AVRational){ 1, 10000 });
1055 }
1056}
1057#endif // CONFIG_LIBX264_HDR10
1058
1059static void handle_side_data(AVCodecContext *avctx, x264_param_t *params)
1060{
1061#if CONFIG_LIBX264_HDR10
1062 const AVFrameSideData *cll_sd =
1065 const AVFrameSideData *mdcv_sd =
1067 avctx->nb_decoded_side_data,
1069
1070 if (cll_sd) {
1071 const AVContentLightMetadata *cll =
1072 (AVContentLightMetadata *)cll_sd->data;
1073
1074 params->content_light_level.i_max_cll = cll->MaxCLL;
1075 params->content_light_level.i_max_fall = cll->MaxFALL;
1076
1077 params->content_light_level.b_cll = 1;
1078 }
1079
1080 if (mdcv_sd) {
1082 }
1083#endif // CONFIG_LIBX264_HDR10
1084}
1085
1087{
1088 X264Context *x4 = avctx->priv_data;
1089 AVCPBProperties *cpb_props;
1090 int sw,sh;
1091 int ret;
1092
1093 if (avctx->global_quality > 0)
1094 av_log(avctx, AV_LOG_WARNING, "-qscale is ignored, -crf is recommended.\n");
1095
1096#if CONFIG_LIBX262_ENCODER
1097 if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
1098 x4->params.b_mpeg2 = 1;
1099 x264_param_default_mpeg2(&x4->params);
1100 } else
1101#endif
1102 x264_param_default(&x4->params);
1103
1104 x4->params.b_deblocking_filter = avctx->flags & AV_CODEC_FLAG_LOOP_FILTER;
1105
1106 if (x4->preset || x4->tune)
1107 if (x264_param_default_preset(&x4->params, x4->preset, x4->tune) < 0) {
1108 int i;
1109 av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", x4->preset, x4->tune);
1110 av_log(avctx, AV_LOG_INFO, "Possible presets:");
1111 for (i = 0; x264_preset_names[i]; i++)
1112 av_log(avctx, AV_LOG_INFO, " %s", x264_preset_names[i]);
1113 av_log(avctx, AV_LOG_INFO, "\n");
1114 av_log(avctx, AV_LOG_INFO, "Possible tunes:");
1115 for (i = 0; x264_tune_names[i]; i++)
1116 av_log(avctx, AV_LOG_INFO, " %s", x264_tune_names[i]);
1117 av_log(avctx, AV_LOG_INFO, "\n");
1118 return AVERROR(EINVAL);
1119 }
1120
1121 if (avctx->level > 0)
1122 x4->params.i_level_idc = avctx->level;
1123
1124 x4->params.pf_log = X264_log;
1125 x4->params.p_log_private = avctx;
1126 x4->params.i_log_level = X264_LOG_DEBUG;
1127 x4->params.i_csp = convert_pix_fmt(avctx->pix_fmt);
1128 x4->params.i_bitdepth = av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth;
1129
1130 PARSE_X264_OPT("weightp", wpredp);
1131
1132 if (avctx->bit_rate) {
1133 if (avctx->bit_rate / 1000 > INT_MAX || avctx->rc_max_rate / 1000 > INT_MAX) {
1134 av_log(avctx, AV_LOG_ERROR, "bit_rate and rc_max_rate > %d000 not supported by libx264\n", INT_MAX);
1135 return AVERROR(EINVAL);
1136 }
1137 x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
1138 x4->params.rc.i_rc_method = X264_RC_ABR;
1139 }
1140 x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
1141 x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
1142 x4->params.rc.b_stat_write = avctx->flags & AV_CODEC_FLAG_PASS1;
1143 if (avctx->flags & AV_CODEC_FLAG_PASS2) {
1144 x4->params.rc.b_stat_read = 1;
1145 } else {
1146 if (x4->crf >= 0) {
1147 x4->params.rc.i_rc_method = X264_RC_CRF;
1148 x4->params.rc.f_rf_constant = x4->crf;
1149 } else if (x4->cqp >= 0) {
1150 x4->params.rc.i_rc_method = X264_RC_CQP;
1151 x4->params.rc.i_qp_constant = x4->cqp;
1152 }
1153
1154 if (x4->crf_max >= 0)
1155 x4->params.rc.f_rf_constant_max = x4->crf_max;
1156 }
1157
1158 if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy > 0 &&
1159 (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
1160 x4->params.rc.f_vbv_buffer_init =
1162 }
1163
1164 PARSE_X264_OPT("level", level);
1165
1166 if (avctx->i_quant_factor > 0)
1167 x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor);
1168 if (avctx->b_quant_factor > 0)
1169 x4->params.rc.f_pb_factor = avctx->b_quant_factor;
1170
1171 if (x4->chroma_offset)
1172 x4->params.analyse.i_chroma_qp_offset = x4->chroma_offset;
1173
1174 if (avctx->gop_size >= 0)
1175 x4->params.i_keyint_max = avctx->gop_size;
1176 if (avctx->max_b_frames >= 0)
1177 x4->params.i_bframe = avctx->max_b_frames;
1178
1179 if (x4->scenechange_threshold >= 0)
1180 x4->params.i_scenecut_threshold = x4->scenechange_threshold;
1181
1182 if (avctx->qmin >= 0)
1183 x4->params.rc.i_qp_min = avctx->qmin;
1184 if (avctx->qmax >= 0)
1185 x4->params.rc.i_qp_max = avctx->qmax;
1186 if (avctx->max_qdiff >= 0)
1187 x4->params.rc.i_qp_step = avctx->max_qdiff;
1188 if (avctx->qblur >= 0)
1189 x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */
1190 if (avctx->qcompress >= 0)
1191 x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
1192 if (avctx->refs >= 0)
1193 x4->params.i_frame_reference = avctx->refs;
1194 else if (x4->params.i_level_idc > 0) {
1195 int i;
1196 int mbn = AV_CEIL_RSHIFT(avctx->width, 4) * AV_CEIL_RSHIFT(avctx->height, 4);
1197
1198 for (i = 0; i<x264_levels[i].level_idc; i++)
1199 if (x264_levels[i].level_idc == x4->params.i_level_idc)
1200 x4->params.i_frame_reference = av_clip(x264_levels[i].dpb / mbn, 1, x4->params.i_frame_reference);
1201 }
1202
1203 if (avctx->trellis >= 0)
1204 x4->params.analyse.i_trellis = avctx->trellis;
1205 if (avctx->me_range >= 0)
1206 x4->params.analyse.i_me_range = avctx->me_range;
1207 if (x4->noise_reduction >= 0)
1208 x4->params.analyse.i_noise_reduction = x4->noise_reduction;
1209 if (avctx->me_subpel_quality >= 0)
1210 x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
1211 if (avctx->keyint_min >= 0)
1212 x4->params.i_keyint_min = avctx->keyint_min;
1213 if (avctx->me_cmp >= 0)
1214 x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
1215
1216 if (x4->aq_mode >= 0)
1217 x4->params.rc.i_aq_mode = x4->aq_mode;
1218 if (x4->aq_strength >= 0)
1219 x4->params.rc.f_aq_strength = x4->aq_strength;
1220 PARSE_X264_OPT("psy-rd", psy_rd);
1221 PARSE_X264_OPT("deblock", deblock);
1222 PARSE_X264_OPT("partitions", partitions);
1223 PARSE_X264_OPT("stats", stats);
1224 if (x4->psy >= 0)
1225 x4->params.analyse.b_psy = x4->psy;
1226 if (x4->rc_lookahead >= 0)
1227 x4->params.rc.i_lookahead = x4->rc_lookahead;
1228 if (x4->weightp >= 0)
1229 x4->params.analyse.i_weighted_pred = x4->weightp;
1230 if (x4->weightb >= 0)
1231 x4->params.analyse.b_weighted_bipred = x4->weightb;
1232 if (x4->cplxblur >= 0)
1233 x4->params.rc.f_complexity_blur = x4->cplxblur;
1234
1235 if (x4->ssim >= 0)
1236 x4->params.analyse.b_ssim = x4->ssim;
1237 if (x4->intra_refresh >= 0)
1238 x4->params.b_intra_refresh = x4->intra_refresh;
1239 if (x4->bluray_compat >= 0) {
1240 x4->params.b_bluray_compat = x4->bluray_compat;
1241 x4->params.b_vfr_input = 0;
1242 }
1243 if (x4->avcintra_class >= 0)
1244 x4->params.i_avcintra_class = x4->avcintra_class;
1245
1246 if (x4->avcintra_class > 200) {
1247#if X264_BUILD < 164
1248 av_log(avctx, AV_LOG_ERROR,
1249 "x264 too old for AVC Intra 300/480, at least version 164 needed\n");
1250 return AVERROR(EINVAL);
1251#else
1252 /* AVC-Intra 300/480 only supported by Sony XAVC flavor */
1253 x4->params.i_avcintra_flavor = X264_AVCINTRA_FLAVOR_SONY;
1254#endif
1255 }
1256
1257 if (x4->b_bias != INT_MIN)
1258 x4->params.i_bframe_bias = x4->b_bias;
1259 if (x4->b_pyramid >= 0)
1260 x4->params.i_bframe_pyramid = x4->b_pyramid;
1261 if (x4->mixed_refs >= 0)
1262 x4->params.analyse.b_mixed_references = x4->mixed_refs;
1263 if (x4->dct8x8 >= 0)
1264 x4->params.analyse.b_transform_8x8 = x4->dct8x8;
1265 if (x4->fast_pskip >= 0)
1266 x4->params.analyse.b_fast_pskip = x4->fast_pskip;
1267 if (x4->aud >= 0)
1268 x4->params.b_aud = x4->aud;
1269 if (x4->mbtree >= 0)
1270 x4->params.rc.b_mb_tree = x4->mbtree;
1271 if (x4->direct_pred >= 0)
1272 x4->params.analyse.i_direct_mv_pred = x4->direct_pred;
1273
1274 if (x4->slice_max_size >= 0)
1275 x4->params.i_slice_max_size = x4->slice_max_size;
1276
1277 if (x4->fastfirstpass)
1278 x264_param_apply_fastfirstpass(&x4->params);
1279
1280 x4->profile = x4->profile_opt;
1281 /* Allow specifying the x264 profile through AVCodecContext. */
1282 if (!x4->profile)
1283 switch (avctx->profile) {
1285 x4->profile = "baseline";
1286 break;
1288 x4->profile = "high";
1289 break;
1291 x4->profile = "high10";
1292 break;
1294 x4->profile = "high422";
1295 break;
1297 x4->profile = "high444";
1298 break;
1300 x4->profile = "main";
1301 break;
1302 default:
1303 break;
1304 }
1305
1306 if (x4->nal_hrd >= 0)
1307 x4->params.i_nal_hrd = x4->nal_hrd;
1308
1309 if (x4->motion_est >= 0)
1310 x4->params.analyse.i_me_method = x4->motion_est;
1311
1312 if (x4->coder >= 0)
1313 x4->params.b_cabac = x4->coder;
1314
1315 if (x4->b_frame_strategy >= 0)
1316 x4->params.i_bframe_adaptive = x4->b_frame_strategy;
1317
1318 if (x4->profile)
1319 if (x264_param_apply_profile(&x4->params, x4->profile) < 0) {
1320 int i;
1321 av_log(avctx, AV_LOG_ERROR, "Error setting profile %s.\n", x4->profile);
1322 av_log(avctx, AV_LOG_INFO, "Possible profiles:");
1323 for (i = 0; x264_profile_names[i]; i++)
1324 av_log(avctx, AV_LOG_INFO, " %s", x264_profile_names[i]);
1325 av_log(avctx, AV_LOG_INFO, "\n");
1326 return AVERROR(EINVAL);
1327 }
1328
1329 x4->params.i_width = avctx->width;
1330 x4->params.i_height = avctx->height;
1331 av_reduce(&sw, &sh, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 4096);
1332 x4->params.vui.i_sar_width = sw;
1333 x4->params.vui.i_sar_height = sh;
1334 x4->params.i_timebase_den = avctx->time_base.den;
1335 x4->params.i_timebase_num = avctx->time_base.num;
1336 if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
1337 x4->params.i_fps_num = avctx->framerate.num;
1338 x4->params.i_fps_den = avctx->framerate.den;
1339 } else {
1340 x4->params.i_fps_num = avctx->time_base.den;
1341 x4->params.i_fps_den = avctx->time_base.num;
1342 }
1343
1344 x4->params.analyse.b_psnr = avctx->flags & AV_CODEC_FLAG_PSNR;
1345
1346 x4->params.i_threads = avctx->thread_count;
1347 if (avctx->thread_type)
1348 x4->params.b_sliced_threads = avctx->thread_type == FF_THREAD_SLICE;
1349
1350 x4->params.b_interlaced = avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT;
1351
1352 x4->params.b_open_gop = !(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP);
1353
1354 x4->params.i_slice_count = avctx->slices;
1355
1357 x4->params.vui.b_fullrange = avctx->color_range == AVCOL_RANGE_JPEG;
1358 else if (avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
1359 avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
1360 avctx->pix_fmt == AV_PIX_FMT_YUVJ444P)
1361 x4->params.vui.b_fullrange = 1;
1362
1363 if (avctx->colorspace != AVCOL_SPC_UNSPECIFIED)
1364 x4->params.vui.i_colmatrix = avctx->colorspace;
1366 x4->params.vui.i_colorprim = avctx->color_primaries;
1367 if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED)
1368 x4->params.vui.i_transfer = avctx->color_trc;
1370 x4->params.vui.i_chroma_loc = avctx->chroma_sample_location - 1;
1371
1372 handle_side_data(avctx, &x4->params);
1373
1375 x4->params.b_repeat_headers = 0;
1376
1377 if (avctx->flags & AV_CODEC_FLAG_RECON_FRAME)
1378 x4->params.b_full_recon = 1;
1379
1380 if(x4->x264opts){
1381 const char *p= x4->x264opts;
1382 while(p){
1383 char param[4096]={0}, val[4096]={0};
1384 if(sscanf(p, "%4095[^:=]=%4095[^:]", param, val) == 1){
1385 ret = parse_opts(avctx, param, "1");
1386 if (ret < 0)
1387 return ret;
1388 } else {
1389 ret = parse_opts(avctx, param, val);
1390 if (ret < 0)
1391 return ret;
1392 }
1393 p= strchr(p, ':');
1394 if (p) {
1395 ++p;
1396 }
1397 }
1398 }
1399
1400 /* Separate headers not supported in AVC-Intra mode */
1401 if (x4->avcintra_class >= 0)
1402 x4->params.b_repeat_headers = 1;
1403
1404 {
1405 const AVDictionaryEntry *en = NULL;
1406 while (en = av_dict_iterate(x4->x264_params, en)) {
1407 if ((ret = x264_param_parse(&x4->params, en->key, en->value)) < 0) {
1408 av_log(avctx, AV_LOG_WARNING,
1409 "Error parsing option '%s = %s'.\n",
1410 en->key, en->value);
1411#if X264_BUILD >= 161
1412 if (ret == X264_PARAM_ALLOC_FAILED)
1413 return AVERROR(ENOMEM);
1414#endif
1415 }
1416 }
1417 }
1418
1419 x4->params.analyse.b_mb_info = x4->mb_info;
1420
1421 // update AVCodecContext with x264 parameters
1422 avctx->has_b_frames = x4->params.i_bframe ?
1423 x4->params.i_bframe_pyramid ? 2 : 1 : 0;
1424 if (avctx->max_b_frames < 0)
1425 avctx->max_b_frames = 0;
1426
1427 avctx->bit_rate = x4->params.rc.i_bitrate*1000LL;
1428
1429 x4->enc = x264_encoder_open(&x4->params);
1430 if (!x4->enc)
1431 return AVERROR_EXTERNAL;
1432
1433 if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
1434 ret = set_extradata(avctx);
1435 if (ret < 0)
1436 return ret;
1437 }
1438
1439 cpb_props = ff_encode_add_cpb_side_data(avctx);
1440 if (!cpb_props)
1441 return AVERROR(ENOMEM);
1442 cpb_props->buffer_size = x4->params.rc.i_vbv_buffer_size * 1000;
1443 cpb_props->max_bitrate = x4->params.rc.i_vbv_max_bitrate * 1000LL;
1444 cpb_props->avg_bitrate = x4->params.rc.i_bitrate * 1000LL;
1445
1446 // Overestimate the reordered opaque buffer size, in case a runtime
1447 // reconfigure would increase the delay (which it shouldn't).
1448 x4->nb_reordered_opaque = x264_encoder_maximum_delayed_frames(x4->enc) + 17;
1450 sizeof(*x4->reordered_opaque));
1451 if (!x4->reordered_opaque) {
1452 x4->nb_reordered_opaque = 0;
1453 return AVERROR(ENOMEM);
1454 }
1455
1456 return 0;
1457}
1458
1459static const enum AVPixelFormat pix_fmts_8bit[] = {
1468#ifdef X264_CSP_NV21
1470#endif
1472};
1485static const enum AVPixelFormat pix_fmts_all[] = {
1494#ifdef X264_CSP_NV21
1496#endif
1501#ifdef X264_CSP_I400
1504#endif
1506};
1507#if CONFIG_LIBX264RGB_ENCODER
1508static const enum AVPixelFormat pix_fmts_8bit_rgb[] = {
1513};
1514#endif
1515
1516#define OFFSET(x) offsetof(X264Context, x)
1517#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1518#define VER VE | AV_OPT_FLAG_RUNTIME_PARAM
1519static const AVOption options[] = {
1520 { "preset", "Set the encoding preset (cf. x264 --fullhelp)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "medium" }, 0, 0, VE},
1521 { "tune", "Tune the encoding params (cf. x264 --fullhelp)", OFFSET(tune), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
1522 { "profile", "Set profile restrictions (cf. x264 --fullhelp)", OFFSET(profile_opt), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
1523 { "fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE},
1524 {"level", "Specify level (as defined by Annex A)", OFFSET(level), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
1525 {"passlogfile", "Filename for 2 pass stats", OFFSET(stats), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
1526 {"wpredp", "Weighted prediction for P-frames", OFFSET(wpredp), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
1527 {"a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, VE},
1528 {"x264opts", "x264 options", OFFSET(x264opts), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
1529 { "crf", "Select the quality for constant quality mode", OFFSET(crf), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VER },
1530 { "crf_max", "In CRF mode, prevents VBV from lowering quality beyond this point.",OFFSET(crf_max), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VER },
1531 { "qp", "Constant quantization parameter rate control method",OFFSET(cqp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VER },
1532 { "aq-mode", "AQ method", OFFSET(aq_mode), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, .unit = "aq_mode"},
1533 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_NONE}, INT_MIN, INT_MAX, VE, .unit = "aq_mode" },
1534 { "variance", "Variance AQ (complexity mask)", 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX, VE, .unit = "aq_mode" },
1535 { "autovariance", "Auto-variance AQ", 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX, VE, .unit = "aq_mode" },
1536 { "autovariance-biased", "Auto-variance AQ with bias to dark scenes", 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE_BIASED}, INT_MIN, INT_MAX, VE, .unit = "aq_mode" },
1537 { "aq-strength", "AQ strength. Reduces blocking and blurring in flat and textured areas.", OFFSET(aq_strength), AV_OPT_TYPE_FLOAT, {.dbl = -1}, -1, FLT_MAX, VE},
1538 { "psy", "Use psychovisual optimizations.", OFFSET(psy), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1539 { "psy-rd", "Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.", OFFSET(psy_rd), AV_OPT_TYPE_STRING, {0 }, 0, 0, VE},
1540 { "rc-lookahead", "Number of frames to look ahead for frametype and ratecontrol", OFFSET(rc_lookahead), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE },
1541 { "weightb", "Weighted prediction for B-frames.", OFFSET(weightb), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1542 { "weightp", "Weighted prediction analysis method.", OFFSET(weightp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, .unit = "weightp" },
1543 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_NONE}, INT_MIN, INT_MAX, VE, .unit = "weightp" },
1544 { "simple", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SIMPLE}, INT_MIN, INT_MAX, VE, .unit = "weightp" },
1545 { "smart", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SMART}, INT_MIN, INT_MAX, VE, .unit = "weightp" },
1546 { "ssim", "Calculate and print SSIM stats.", OFFSET(ssim), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1547 { "intra-refresh", "Use Periodic Intra Refresh instead of IDR frames.",OFFSET(intra_refresh),AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1548 { "bluray-compat", "Bluray compatibility workarounds.", OFFSET(bluray_compat) ,AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1549 { "b-bias", "Influences how often B-frames are used", OFFSET(b_bias), AV_OPT_TYPE_INT, { .i64 = INT_MIN}, INT_MIN, INT_MAX, VE },
1550 { "b-pyramid", "Keep some B-frames as references.", OFFSET(b_pyramid), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, .unit = "b_pyramid" },
1551 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NONE}, INT_MIN, INT_MAX, VE, .unit = "b_pyramid" },
1552 { "strict", "Strictly hierarchical pyramid", 0, AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX, VE, .unit = "b_pyramid" },
1553 { "normal", "Non-strict (not Blu-ray compatible)", 0, AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX, VE, .unit = "b_pyramid" },
1554 { "mixed-refs", "One reference per partition, as opposed to one reference per macroblock", OFFSET(mixed_refs), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, VE },
1555 { "8x8dct", "High profile 8x8 transform.", OFFSET(dct8x8), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE},
1556 { "fast-pskip", NULL, OFFSET(fast_pskip), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE},
1557 { "aud", "Use access unit delimiters.", OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE},
1558 { "mbtree", "Use macroblock tree ratecontrol.", OFFSET(mbtree), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE},
1559 { "deblock", "Loop filter parameters, in <alpha:beta> form.", OFFSET(deblock), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
1560 { "cplxblur", "Reduce fluctuations in QP (before curve compression)", OFFSET(cplxblur), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VE},
1561 { "partitions", "A comma-separated list of partitions to consider. "
1562 "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all", OFFSET(partitions), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
1563 { "direct-pred", "Direct MV prediction mode", OFFSET(direct_pred), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, .unit = "direct-pred" },
1564 { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_NONE }, 0, 0, VE, .unit = "direct-pred" },
1565 { "spatial", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_SPATIAL }, 0, 0, VE, .unit = "direct-pred" },
1566 { "temporal", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_TEMPORAL }, 0, 0, VE, .unit = "direct-pred" },
1567 { "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_AUTO }, 0, 0, VE, .unit = "direct-pred" },
1568 { "slice-max-size","Limit the size of each slice in bytes", OFFSET(slice_max_size),AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE },
1569 { "stats", "Filename for 2 pass stats", OFFSET(stats), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
1570 { "nal-hrd", "Signal HRD information (requires vbv-bufsize; "
1571 "cbr not allowed in .mp4)", OFFSET(nal_hrd), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, .unit = "nal-hrd" },
1572 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_NONE}, INT_MIN, INT_MAX, VE, .unit = "nal-hrd" },
1573 { "vbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_VBR}, INT_MIN, INT_MAX, VE, .unit = "nal-hrd" },
1574 { "cbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_CBR}, INT_MIN, INT_MAX, VE, .unit = "nal-hrd" },
1575 { "avcintra-class","AVC-Intra class 50/100/200/300/480", OFFSET(avcintra_class),AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 480 , VE},
1576 { "me_method", "Set motion estimation method", OFFSET(motion_est), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, X264_ME_TESA, VE, .unit = "motion-est"},
1577 { "motion-est", "Set motion estimation method", OFFSET(motion_est), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, X264_ME_TESA, VE, .unit = "motion-est"},
1578 { "dia", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_DIA }, INT_MIN, INT_MAX, VE, .unit = "motion-est" },
1579 { "hex", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_HEX }, INT_MIN, INT_MAX, VE, .unit = "motion-est" },
1580 { "umh", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_UMH }, INT_MIN, INT_MAX, VE, .unit = "motion-est" },
1581 { "esa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_ESA }, INT_MIN, INT_MAX, VE, .unit = "motion-est" },
1582 { "tesa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_TESA }, INT_MIN, INT_MAX, VE, .unit = "motion-est" },
1583 { "forced-idr", "If forcing keyframes, force them as IDR frames.", OFFSET(forced_idr), AV_OPT_TYPE_BOOL, { .i64 = 0 }, -1, 1, VE },
1584 { "coder", "Coder type", OFFSET(coder), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE, .unit = "coder" },
1585 { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, INT_MIN, INT_MAX, VE, .unit = "coder" },
1586 { "cavlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, .unit = "coder" },
1587 { "cabac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, .unit = "coder" },
1588 { "vlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, .unit = "coder" },
1589 { "ac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, .unit = "coder" },
1590 { "b_strategy", "Strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2, VE },
1591 { "chromaoffset", "QP difference between chroma and luma", OFFSET(chroma_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, VE },
1592 { "sc_threshold", "Scene change threshold", OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX, VE },
1593 { "noise_reduction", "Noise reduction", OFFSET(noise_reduction), AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX, VE },
1594 { "udu_sei", "Use user data unregistered SEI if available", OFFSET(udu_sei), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
1595 { "x264-params", "Override the x264 configuration using a :-separated list of key=value parameters", OFFSET(x264_params), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
1596 { "mb_info", "Set mb_info data through AVSideData, only useful when used from the API", OFFSET(mb_info), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
1597 { NULL },
1598};
1599
1601 { "sar", "0", AV_OPT_FLAG_RUNTIME_PARAM },
1602 { "b", "0", AV_OPT_FLAG_RUNTIME_PARAM },
1603 { "bufsize", "0", AV_OPT_FLAG_RUNTIME_PARAM },
1604 { "maxrate", "0", AV_OPT_FLAG_RUNTIME_PARAM },
1605 { "bf", "-1" },
1606 { "flags2", "0" },
1607 { "g", "-1" },
1608 { "i_qfactor", "-1" },
1609 { "b_qfactor", "-1" },
1610 { "qmin", "-1" },
1611 { "qmax", "-1" },
1612 { "qdiff", "-1" },
1613 { "qblur", "-1" },
1614 { "qcomp", "-1" },
1615// { "rc_lookahead", "-1" },
1616 { "refs", "-1" },
1617 { "trellis", "-1" },
1618 { "me_range", "-1" },
1619 { "subq", "-1" },
1620 { "keyint_min", "-1" },
1621 { "cmp", "-1" },
1622 { "threads", AV_STRINGIFY(X264_THREADS_AUTO) },
1623 { "thread_type", "0" },
1624 { "flags", "+cgop" },
1625 { "rc_init_occupancy","-1" },
1626 { NULL },
1627};
1628
1629#if CONFIG_LIBX264_ENCODER
1630static const AVClass x264_class = {
1631 .class_name = "libx264",
1632 .item_name = av_default_item_name,
1633 .option = options,
1634 .version = LIBAVUTIL_VERSION_INT,
1635};
1636
1638 .p.name = "libx264",
1639 CODEC_LONG_NAME("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
1640 .p.type = AVMEDIA_TYPE_VIDEO,
1641 .p.id = AV_CODEC_ID_H264,
1642 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
1648 .p.priv_class = &x264_class,
1649 .p.wrapper_name = "libx264",
1650 .priv_data_size = sizeof(X264Context),
1651 .init = X264_init,
1653 .flush = X264_flush,
1654 .reconf = X264_reconf,
1655 .close = X264_close,
1656 .defaults = x264_defaults,
1658 .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
1660#if X264_BUILD < 158
1662#endif
1663 ,
1664};
1665#endif
1666
1667#if CONFIG_LIBX264RGB_ENCODER
1668static const AVClass rgbclass = {
1669 .class_name = "libx264rgb",
1670 .item_name = av_default_item_name,
1671 .option = options,
1672 .version = LIBAVUTIL_VERSION_INT,
1673};
1674
1676 .p.name = "libx264rgb",
1677 CODEC_LONG_NAME("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB"),
1678 .p.type = AVMEDIA_TYPE_VIDEO,
1679 .p.id = AV_CODEC_ID_H264,
1680 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
1683 CODEC_PIXFMTS_ARRAY(pix_fmts_8bit_rgb),
1684 .p.priv_class = &rgbclass,
1685 .p.wrapper_name = "libx264",
1686 .priv_data_size = sizeof(X264Context),
1687 .init = X264_init,
1689 .close = X264_close,
1690 .defaults = x264_defaults,
1692#if X264_BUILD < 158
1694#endif
1695 ,
1696};
1697#endif
1698
1699#if CONFIG_LIBX262_ENCODER
1700static const AVClass X262_class = {
1701 .class_name = "libx262",
1702 .item_name = av_default_item_name,
1703 .option = options,
1704 .version = LIBAVUTIL_VERSION_INT,
1705};
1706
1708 .p.name = "libx262",
1709 CODEC_LONG_NAME("libx262 MPEG2VIDEO"),
1710 .p.type = AVMEDIA_TYPE_VIDEO,
1711 .p.id = AV_CODEC_ID_MPEG2VIDEO,
1712 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
1716 .color_ranges = AVCOL_RANGE_MPEG,
1717 .p.priv_class = &X262_class,
1718 .p.wrapper_name = "libx264",
1719 .priv_data_size = sizeof(X264Context),
1720 .init = X264_init,
1722 .close = X264_close,
1723 .defaults = x264_defaults,
1724 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
1726};
1727#endif
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
SwsAArch64OpImplParams params
Definition ops.c:51
static double val(void *priv, double ch)
Definition aeval.c:77
const FFCodec ff_libx264_encoder
const FFCodec ff_libx262_encoder
const FFCodec ff_libx264rgb_encoder
#define VE
Definition amfenc_av1.c:30
static AVFormatContext * ctx
int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, void **data, size_t *sei_size)
Check AVFrame for A53 side data and allocate and fill SEI message with A53 info.
Definition atsc_a53.c:26
static enum AVPixelFormat pix_fmts_8bit[2][2]
Definition av1_parser.c:38
static enum AVPixelFormat pix_fmts_10bit[2][2]
Definition av1_parser.c:42
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition avassert.h:68
Libavcodec external API header.
#define FF_CMP_CHROMA
Definition avcodec.h:897
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
Definition avcodec.h:1591
refcounted data buffer API
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
static int FUNC sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
static int FUNC aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int FUNC sei_payload(CodedBitstreamContext *ctx, RWContext *rw, LCEVCRawSEI *current, int payload_size)
static int FUNC nal(CodedBitstreamContext *ctx, RWContext *rw, LCEVCRawNAL *current, int nal_unit_type)
#define s(width, name)
Definition cbs_vp9.c:198
#define MB_SIZE
Definition cinepakenc.c:54
#define CODEC_PIXFMTS_ARRAY(array)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define av_clip
Definition common.h:100
#define av_clipf
Definition common.h:145
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static __device__ float fabs(float a)
static __device__ float floor(float a)
#define AV_PROFILE_H264_MAIN
Definition defs.h:112
#define AV_PROFILE_H264_HIGH_444
Definition defs.h:121
#define AV_PROFILE_H264_HIGH
Definition defs.h:114
#define AV_PROFILE_H264_HIGH_10
Definition defs.h:115
#define AV_PROFILE_H264_HIGH_422
Definition defs.h:118
#define AV_PROFILE_H264_BASELINE
Definition defs.h:110
static AVPacket * pkt
static enum AVPixelFormat pix_fmt
static AVFrame * frame
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition encode.c:106
AVCPBProperties * ff_encode_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Definition encode.c:1039
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
Definition encode.c:1070
av_cold int ff_encode_reconf_parse_dict(AVCodecContext *avctx, AVDictionary **dict)
Definition encode.c:599
static enum AVPixelFormat pix_fmts_9bit[NUM_CHROMA_FORMATS]
Definition evc_parser.c:44
static CheckasmStats stats
Definition checkasm.c:75
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition get_bits.h:544
static void skip_bits1(GetBitContext *s)
Definition get_bits.h:416
exp golomb vlc stuff
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
Definition golomb.h:120
#define fail
Definition test.h:479
#define AV_OPT_FLAG_RUNTIME_PARAM
A generic parameter which can be set by the user at runtime.
Definition opt.h:376
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition opt.h:270
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
Definition opt.h:289
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition codec.h:147
#define AV_CODEC_CAP_ENCODER_RECONF
Encoder can be reconfigured by passing new initialization parameters.
Definition codec.h:54
#define AV_CODEC_CAP_ENCODER_FLUSH
This encoder can be flushed using avcodec_flush_buffers().
Definition codec.h:154
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition avcodec.h:294
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
Definition codec.h:112
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition codec.h:79
#define AV_CODEC_EXPORT_DATA_PRFT
Export encoder Producer Reference Time through packet side data.
Definition avcodec.h:394
#define AV_CODEC_FLAG_CLOSED_GOP
Definition avcodec.h:332
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
Definition avcodec.h:310
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition avcodec.h:290
#define AV_CODEC_FLAG_LOOP_FILTER
loop filter.
Definition avcodec.h:298
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition avcodec.h:318
#define AV_CODEC_FLAG_PSNR
error[?
Definition avcodec.h:306
#define AV_CODEC_CAP_ENCODER_RECON_FRAME
The encoder is able to output reconstructed frame data, i.e.
Definition codec.h:162
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition avcodec.h:279
#define AV_CODEC_FLAG_RECON_FRAME
Request the encoder to output reconstructed frames, i.e. frames that would be produced by decoding th...
Definition avcodec.h:244
@ AV_CODEC_ID_H264
Definition codec_id.h:77
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition codec_id.h:52
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:650
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:139
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition buffer.c:233
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition dict.c:42
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition avutil.h:226
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition error.h:59
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition frame.h:695
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition frame.h:700
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:496
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:659
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition frame.c:552
static const AVFrameSideData * av_frame_side_data_get(AVFrameSideData *const *sd, const int nb_sd, enum AVFrameSideDataType type)
Wrapper around av_frame_side_data_get_c() to workaround the limitation that for any type T the conver...
Definition frame.h:1196
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition frame.h:137
@ AV_FRAME_DATA_SEI_UNREGISTERED
User data unregistered metadata associated with a video frame.
Definition frame.h:178
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
Definition frame.h:120
@ AV_FRAME_DATA_STEREO3D
Stereoscopic 3d metadata.
Definition frame.h:64
@ AV_FRAME_DATA_VIDEO_HINT
Provide encoder-specific hinting information about changed/unchanged portions of a frame.
Definition frame.h:230
@ AV_FRAME_DATA_REGIONS_OF_INTEREST
Regions Of Interest, the data is an array of AVRegionOfInterest type, the number of array element is ...
Definition frame.h:165
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
void av_vlog(void *avcl, int level, const char *fmt, va_list vl)
Send the specified message to the log if the level is less than or equal to the current av_log_level.
Definition log.c:459
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition rational.c:35
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
Definition mem.c:495
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition mem.c:302
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
AVPictureType
Definition avutil.h:276
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
@ AV_PICTURE_TYPE_P
Predicted.
Definition avutil.h:279
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition avutil.h:280
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition stereo3d.h:194
@ AV_STEREO3D_COLUMNS
Views are packed per column.
Definition stereo3d.h:138
@ AV_STEREO3D_LINES
Views are packed per line, as if interlaced.
Definition stereo3d.h:126
@ AV_STEREO3D_2D
Video is not stereoscopic (and metadata has to be there).
Definition stereo3d.h:52
@ AV_STEREO3D_CHECKERBOARD
Views are packed in a checkerboard-like structure per pixel.
Definition stereo3d.h:101
@ AV_STEREO3D_TOPBOTTOM
Views are on top of each other.
Definition stereo3d.h:76
@ AV_STEREO3D_FRAMESEQUENCE
Views are alternated temporally.
Definition stereo3d.h:89
@ AV_STEREO3D_SIDEBYSIDE
Views are next to each other.
Definition stereo3d.h:64
#define AV_STRINGIFY(s)
Definition macros.h:66
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition intra.c:278
static const uint8_t level_map[LCEVC_LogLevelCount]
Definition lcevcdec.c:280
#define VER
Definition libaomenc.c:1584
common internal api header.
#define av_always_inline
Definition attributes.h:72
#define av_cold
Definition attributes.h:117
common internal API header
Stereoscopic video.
static void handle_mdcv(struct EbSvtAv1MasteringDisplayInfo *dst, const AVMasteringDisplayMetadata *mdcv)
Definition libsvtav1.c:149
static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition libx264.c:619
static void reconfig_encoder_from_frame(AVCodecContext *ctx, const AVFrame *frame)
Definition libx264.c:242
static int setup_mb_info(AVCodecContext *ctx, x264_picture_t *pic, const AVFrame *frame, const AVVideoHint *info)
Definition libx264.c:359
static void X264_flush(AVCodecContext *avctx)
Definition libx264.c:752
static av_cold int X264_close(AVCodecContext *avctx)
Definition libx264.c:783
#define PARSE_X264_OPT(name, var)
Definition libx264.c:1005
static av_cold int X264_init(AVCodecContext *avctx)
Definition libx264.c:1086
#define COMPUTE_MBINFO(mbinfo_filler_, mbinfo_marker_, compute_coords_fn_)
#define MB_FLOOR(x)
Definition libx264.c:53
static int set_extradata(AVCodecContext *avctx)
Definition libx264.c:969
static int parse_opts(AVCodecContext *avctx, const char *opt, const char *param)
Definition libx264.c:805
static av_cold int X264_reconf(AVCodecContext *avctx, AVDictionary **dict)
Definition libx264.c:770
static const FFCodecDefault x264_defaults[]
Definition libx264.c:1600
static void X264_log(void *p, int level, const char *fmt, va_list args)
Definition libx264.c:131
#define MB_CEIL(x)
Definition libx264.c:54
static void opaque_uninit(X264Opaque *o)
Definition libx264.c:146
static void handle_side_data(AVCodecContext *avctx, x264_param_t *params)
Definition libx264.c:1059
static void reconfig_encoder(AVCodecContext *ctx)
Definition libx264.c:195
static void av_always_inline mbinfo_compute_constant_coords(const AVVideoRect *rect, int *min_x, int *max_x, int *min_y, int *max_y)
Definition libx264.c:347
static int encode_nals(AVCodecContext *ctx, AVPacket *pkt, const x264_nal_t *nals, int nnal)
Definition libx264.c:152
static int setup_frame(AVCodecContext *ctx, const AVFrame *frame, x264_picture_t **ppic)
Definition libx264.c:476
static void free_picture(x264_picture_t *pic)
Definition libx264.c:303
static int setup_roi(AVCodecContext *ctx, x264_picture_t *pic, const AVFrame *frame, const uint8_t *data, size_t size)
Definition libx264.c:403
#define OFFSET(x)
Definition libx264.c:1516
static enum AVPixelFormat csp_to_pixfmt(int csp)
Definition libx264.c:313
static enum AVPixelFormat pix_fmts_all[]
Definition libx264.c:1485
static void av_always_inline mbinfo_compute_changed_coords(const AVVideoRect *rect, int *min_x, int *max_x, int *min_y, int *max_y)
Definition libx264.c:335
static int save_sei(AVCodecContext *avctx, x264_nal_t *nal)
Definition libx264.c:866
static int convert_pix_fmt(enum AVPixelFormat pix_fmt)
Definition libx264.c:831
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:264
Memory handling functions.
static int sse(const MPVEncContext *const s, const uint8_t *src1, const uint8_t *src2, int w, int h, int stride)
const char data[16]
Definition mxf.c:149
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp)
Definition packet.c:548
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3500
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#define AV_PIX_FMT_YUV444P9
Definition pixfmt.h:544
@ AVCHROMA_LOC_UNSPECIFIED
Definition pixfmt.h:803
#define AV_PIX_FMT_YUV420P10
Definition pixfmt.h:545
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:749
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
#define AV_PIX_FMT_YUV422P10
Definition pixfmt.h:546
#define AV_PIX_FMT_NV20
Definition pixfmt.h:606
#define AV_PIX_FMT_YUV420P9
Definition pixfmt.h:542
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition pixfmt.h:96
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
Definition pixfmt.h:97
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition pixfmt.h:265
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_NV16
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:198
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition pixfmt.h:86
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition pixfmt.h:76
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition pixfmt.h:87
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition pixfmt.h:85
#define AV_PIX_FMT_GRAY10
Definition pixfmt.h:525
@ AVCOL_PRI_UNSPECIFIED
Definition pixfmt.h:645
@ AVCOL_TRC_UNSPECIFIED
Definition pixfmt.h:675
#define AV_PIX_FMT_YUV444P10
Definition pixfmt.h:548
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:709
static void deblock(const RV60Context *s, AVFrame *frame, int xpos, int ypos, int size, int dpos)
Definition rv60dec.c:2154
@ SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
Definition sei.h:34
@ SEI_TYPE_USER_DATA_UNREGISTERED
Definition sei.h:35
A reference to a data buffer.
Definition buffer.h:82
This structure describes the bitrate properties of an encoded bitstream.
Definition defs.h:282
int64_t avg_bitrate
Average bitrate of the stream, in bits per second.
Definition defs.h:297
int64_t max_bitrate
Maximum bitrate of the stream, in bits per second.
Definition defs.h:287
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
Definition defs.h:303
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
int trellis
trellis RD quantization
Definition avcodec.h:1323
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:643
int max_qdiff
maximum quantizer difference between frames
Definition avcodec.h:1266
int width
picture width / height.
Definition avcodec.h:604
int rc_buffer_size
decoder bitstream buffer size
Definition avcodec.h:1273
int me_cmp
motion estimation comparison function
Definition avcodec.h:862
int global_quality
Global quality for codecs which cannot change it per frame.
Definition avcodec.h:1235
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition avcodec.h:681
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition avcodec.h:657
int me_subpel_quality
subpel ME quality
Definition avcodec.h:932
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
Definition avcodec.h:781
int qmin
minimum quantizer
Definition avcodec.h:1252
int keyint_min
minimum GOP size
Definition avcodec.h:1014
float b_quant_factor
qscale factor between IP and B-frames If > 0 then the last P-frame quantizer will be used (q= lastp_q...
Definition avcodec.h:790
AVRational framerate
Definition avcodec.h:563
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition avcodec.h:628
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition avcodec.h:709
int level
Encoding level descriptor.
Definition avcodec.h:1646
int64_t bit_rate
the average bitrate
Definition avcodec.h:493
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition avcodec.h:1316
int thread_type
Which multithreading methods to use.
Definition avcodec.h:1589
int profile
profile
Definition avcodec.h:1636
int nb_decoded_side_data
Definition avcodec.h:1930
enum AVColorSpace colorspace
YUV colorspace type.
Definition avcodec.h:671
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition avcodec.h:1021
int refs
number of reference frames
Definition avcodec.h:701
int64_t rc_max_rate
maximum bitrate
Definition avcodec.h:1288
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition avcodec.h:1579
int qmax
maximum quantizer
Definition avcodec.h:1259
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition avcodec.h:664
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avcodec.h:547
int flags
AV_CODEC_FLAG_*.
Definition avcodec.h:500
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
Definition avcodec.h:1929
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition avcodec.h:526
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition avcodec.h:688
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
Definition avcodec.h:1244
float qblur
amount of qscale smoothing over time (0.0-1.0)
Definition avcodec.h:1245
int me_range
maximum motion estimation search range in subpel units If 0 then no limit.
Definition avcodec.h:941
enum AVCodecID codec_id
Definition avcodec.h:453
int extradata_size
Definition avcodec.h:527
float i_quant_factor
qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_...
Definition avcodec.h:806
void * priv_data
Definition avcodec.h:470
int slices
Number of slices.
Definition avcodec.h:1037
AVFrame * recon_frame
When the AV_CODEC_FLAG_RECON_FRAME flag is used.
Definition internal.h:114
int depth
Number of bits in the component.
Definition pixdesc.h:57
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
unsigned MaxFALL
Max average light level per frame (cd/m^2).
unsigned MaxCLL
Max content light level (cd/m^2).
char * key
Definition dict.h:91
char * value
Definition dict.h:92
Structure to hold side data for an AVFrame.
Definition frame.h:327
enum AVFrameSideDataType type
Definition frame.h:328
size_t size
Definition frame.h:330
uint8_t * data
Definition frame.h:329
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
int width
Definition frame.h:544
int height
Definition frame.h:544
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition frame.h:517
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition frame.h:559
Mastering display metadata capable of representing the color volume of the display used to master the...
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition pixdesc.h:105
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition pixdesc.h:80
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition pixdesc.h:89
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition pixdesc.h:71
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
Structure describing a single Region Of Interest.
Definition frame.h:398
uint32_t self_size
Must be set to the size of this data structure (that is, sizeof(AVRegionOfInterest)).
Definition frame.h:403
AVRational qoffset
Quantisation offset.
Definition frame.h:440
int top
Distance in pixels from the top edge of the frame to the top and bottom edges and from the left edge ...
Definition frame.h:413
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
Definition stereo3d.h:203
enum AVStereo3DType type
How views are packed within the video.
Definition stereo3d.h:207
int flags
Additional information about the frame packing.
Definition stereo3d.h:212
AVVideoHintType type
Definition video_hint.h:63
size_t nb_rects
Number of AVVideoRect present.
Definition video_hint.h:50
Copyright 2023 Elias Carotti <eliascrt at amazon dot it>
Definition video_hint.h:29
int weightp
Definition libx264.c:87
int next_reordered_opaque
Definition libx264.c:119
char * preset
Definition libx264.c:71
int weightb
Definition libx264.c:88
int direct_pred
Definition libx264.c:102
AVDictionary * x264_params
Definition libx264.c:117
float crf
Definition libx264.c:79
char * level
Definition libx264.c:75
float cplxblur
Definition libx264.c:100
uint8_t * sei
Definition libx264.c:69
x264_t * enc
Definition libx264.c:67
x264_param_t params
Definition libx264.c:66
char * deblock
Definition libx264.c:99
X264Opaque * reordered_opaque
Definition libx264.c:120
int b_pyramid
Definition libx264.c:93
int chroma_offset
Definition libx264.c:112
int slice_max_size
Definition libx264.c:103
x264_picture_t pic
Definition libx264.c:68
float aq_strength
Definition libx264.c:83
int udu_sei
Definition libx264.c:115
int intra_refresh
Definition libx264.c:90
int nb_reordered_opaque
Definition libx264.c:119
int mixed_refs
Definition libx264.c:94
int fastfirstpass
Definition libx264.c:76
int dct8x8
Definition libx264.c:95
char * tune
Definition libx264.c:72
char * partitions
Definition libx264.c:101
char * x264opts
Definition libx264.c:78
int avcintra_class
Definition libx264.c:106
char * stats
Definition libx264.c:104
int sei_size
Definition libx264.c:70
int nal_hrd
Definition libx264.c:105
int rc_lookahead
Definition libx264.c:86
int bluray_compat
Definition libx264.c:91
int motion_est
Definition libx264.c:107
int aq_mode
Definition libx264.c:82
int forced_idr
Definition libx264.c:108
char * wpredp
Definition libx264.c:77
int noise_reduction
Definition libx264.c:114
int b_frame_strategy
Definition libx264.c:111
int scenechange_threshold
Definition libx264.c:113
int mbtree
Definition libx264.c:98
int b_bias
Definition libx264.c:92
int roi_warned
If the encoder does not support ROI then warn the first time we encounter a frame with ROI side data.
Definition libx264.c:126
float crf_max
Definition libx264.c:80
int mb_info
Definition libx264.c:128
char * psy_rd
Definition libx264.c:84
int fast_pskip
Definition libx264.c:96
const char * profile
Definition libx264.c:73
char * profile_opt
Definition libx264.c:74
void * frame_opaque
Definition libx264.c:60
int64_t wallclock
Definition libx264.c:57
AVBufferRef * frame_opaque_ref
Definition libx264.c:61
int64_t duration
Definition libx264.c:58
int y
Definition f_ebur128.c:78
int x
Definition f_ebur128.c:78
uint8_t level
Definition svq3.c:208
#define av_free(p)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
static void dct8x8(int16_t *coef, int bit_depth)
Definition h264dsp.c:165
#define src
Definition vp8dsp.c:248
int level_idc
Definition h264_levels.c:29
int64_t av_gettime(void)
Get the current time in microseconds.
Definition time.c:40
int size
preset
Definition vf_curves.c:47
@ AV_VIDEO_HINT_TYPE_CHANGED
Definition video_hint.h:39
static av_always_inline AVVideoRect * av_video_hint_rects(const AVVideoHint *hints)
Definition video_hint.h:67