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