FFmpeg  4.4.9
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 "libavutil/eval.h"
23 #include "libavutil/internal.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/mem.h"
26 #include "libavutil/pixdesc.h"
27 #include "libavutil/stereo3d.h"
28 #include "libavutil/time.h"
29 #include "libavutil/intreadwrite.h"
30 #include "avcodec.h"
31 #include "internal.h"
32 #include "packet_internal.h"
33 #include "atsc_a53.h"
34 
35 #if defined(_MSC_VER)
36 #define X264_API_IMPORTS 1
37 #endif
38 
39 #include <x264.h>
40 #include <float.h>
41 #include <math.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 
46 // from x264.h, for quant_offsets, Macroblocks are 16x16
47 // blocks of pixels (with respect to the luma plane)
48 #define MB_SIZE 16
49 
50 typedef struct X264Opaque {
53 } X264Opaque;
54 
55 typedef struct X264Context {
56  AVClass *class;
57  x264_param_t params;
58  x264_t *enc;
59  x264_picture_t pic;
61  int sei_size;
62  char *preset;
63  char *tune;
64  char *profile;
65  char *level;
67  char *wpredp;
68  char *x264opts;
69  float crf;
70  float crf_max;
71  int cqp;
72  int aq_mode;
73  float aq_strength;
74  char *psy_rd;
75  int psy;
77  int weightp;
78  int weightb;
79  int ssim;
82  int b_bias;
83  int b_pyramid;
85  int dct8x8;
87  int aud;
88  int mbtree;
89  char *deblock;
90  float cplxblur;
91  char *partitions;
94  char *stats;
95  int nal_hrd;
99  int coder;
100  int a53_cc;
105 
107 
110 
111  /**
112  * If the encoder does not support ROI then warn the first time we
113  * encounter a frame with ROI side data.
114  */
116 } X264Context;
117 
118 static void X264_log(void *p, int level, const char *fmt, va_list args)
119 {
120  static const int level_map[] = {
121  [X264_LOG_ERROR] = AV_LOG_ERROR,
122  [X264_LOG_WARNING] = AV_LOG_WARNING,
123  [X264_LOG_INFO] = AV_LOG_INFO,
124  [X264_LOG_DEBUG] = AV_LOG_DEBUG
125  };
126 
127  if (level < 0 || level > X264_LOG_DEBUG)
128  return;
129 
130  av_vlog(p, level_map[level], fmt, args);
131 }
132 
133 
135  const x264_nal_t *nals, int nnal)
136 {
137  X264Context *x4 = ctx->priv_data;
138  uint8_t *p;
139  uint64_t size = x4->sei_size;
140  int i;
141  int ret;
142 
143  if (!nnal)
144  return 0;
145 
146  for (int i = 0; i < nnal; i++) {
147  size += nals[i].i_payload;
148  /* ff_get_encode_buffer() accepts an int64_t and
149  * so we need to make sure that no overflow happens before
150  * that. With 32bit ints this is automatically true. */
151 #if INT_MAX > INT64_MAX / INT_MAX - 1
152  if ((int64_t)size < 0)
153  return AVERROR(ERANGE);
154 #endif
155  }
156 
157  if ((ret = ff_alloc_packet2(ctx, pkt, size, 0)) < 0)
158  return ret;
159 
160  p = pkt->data;
161 
162  /* Write the SEI as part of the first frame. */
163  if (x4->sei_size > 0 && nnal > 0) {
164  if (x4->sei_size > size) {
165  av_log(ctx, AV_LOG_ERROR, "Error: nal buffer is too small\n");
166  return -1;
167  }
168  memcpy(p, x4->sei, x4->sei_size);
169  p += x4->sei_size;
170  x4->sei_size = 0;
171  av_freep(&x4->sei);
172  }
173 
174  for (i = 0; i < nnal; i++){
175  memcpy(p, nals[i].p_payload, nals[i].i_payload);
176  p += nals[i].i_payload;
177  }
178 
179  return 1;
180 }
181 
182 static int avfmt2_num_planes(int avfmt)
183 {
184  switch (avfmt) {
185  case AV_PIX_FMT_YUV420P:
186  case AV_PIX_FMT_YUVJ420P:
187  case AV_PIX_FMT_YUV420P9:
189  case AV_PIX_FMT_YUV444P:
190  return 3;
191 
192  case AV_PIX_FMT_BGR0:
193  case AV_PIX_FMT_BGR24:
194  case AV_PIX_FMT_RGB24:
195  case AV_PIX_FMT_GRAY8:
196  case AV_PIX_FMT_GRAY10:
197  return 1;
198 
199  default:
200  return 3;
201  }
202 }
203 
205 {
206  X264Context *x4 = ctx->priv_data;
207  AVFrameSideData *side_data;
208 
209 
210  if (x4->avcintra_class < 0) {
211  if (x4->params.b_interlaced && x4->params.b_tff != frame->top_field_first) {
212 
213  x4->params.b_tff = frame->top_field_first;
214  x264_encoder_reconfig(x4->enc, &x4->params);
215  }
216  if (x4->params.vui.i_sar_height*ctx->sample_aspect_ratio.num != ctx->sample_aspect_ratio.den * x4->params.vui.i_sar_width) {
217  x4->params.vui.i_sar_height = ctx->sample_aspect_ratio.den;
218  x4->params.vui.i_sar_width = ctx->sample_aspect_ratio.num;
219  x264_encoder_reconfig(x4->enc, &x4->params);
220  }
221 
222  if (x4->params.rc.i_vbv_buffer_size != ctx->rc_buffer_size / 1000 ||
223  x4->params.rc.i_vbv_max_bitrate != ctx->rc_max_rate / 1000) {
224  x4->params.rc.i_vbv_buffer_size = ctx->rc_buffer_size / 1000;
225  x4->params.rc.i_vbv_max_bitrate = ctx->rc_max_rate / 1000;
226  x264_encoder_reconfig(x4->enc, &x4->params);
227  }
228 
229  if (x4->params.rc.i_rc_method == X264_RC_ABR &&
230  x4->params.rc.i_bitrate != ctx->bit_rate / 1000) {
231  x4->params.rc.i_bitrate = ctx->bit_rate / 1000;
232  x264_encoder_reconfig(x4->enc, &x4->params);
233  }
234 
235  if (x4->crf >= 0 &&
236  x4->params.rc.i_rc_method == X264_RC_CRF &&
237  x4->params.rc.f_rf_constant != x4->crf) {
238  x4->params.rc.f_rf_constant = x4->crf;
239  x264_encoder_reconfig(x4->enc, &x4->params);
240  }
241 
242  if (x4->params.rc.i_rc_method == X264_RC_CQP &&
243  x4->cqp >= 0 &&
244  x4->params.rc.i_qp_constant != x4->cqp) {
245  x4->params.rc.i_qp_constant = x4->cqp;
246  x264_encoder_reconfig(x4->enc, &x4->params);
247  }
248 
249  if (x4->crf_max >= 0 &&
250  x4->params.rc.f_rf_constant_max != x4->crf_max) {
251  x4->params.rc.f_rf_constant_max = x4->crf_max;
252  x264_encoder_reconfig(x4->enc, &x4->params);
253  }
254  }
255 
257  if (side_data) {
258  AVStereo3D *stereo = (AVStereo3D *)side_data->data;
259  int fpa_type;
260 
261  switch (stereo->type) {
263  fpa_type = 0;
264  break;
265  case AV_STEREO3D_COLUMNS:
266  fpa_type = 1;
267  break;
268  case AV_STEREO3D_LINES:
269  fpa_type = 2;
270  break;
272  fpa_type = 3;
273  break;
275  fpa_type = 4;
276  break;
278  fpa_type = 5;
279  break;
280 #if X264_BUILD >= 145
281  case AV_STEREO3D_2D:
282  fpa_type = 6;
283  break;
284 #endif
285  default:
286  fpa_type = -1;
287  break;
288  }
289 
290  /* Inverted mode is not supported by x264 */
291  if (stereo->flags & AV_STEREO3D_FLAG_INVERT) {
293  "Ignoring unsupported inverted stereo value %d\n", fpa_type);
294  fpa_type = -1;
295  }
296 
297  if (fpa_type != x4->params.i_frame_packing) {
298  x4->params.i_frame_packing = fpa_type;
299  x264_encoder_reconfig(x4->enc, &x4->params);
300  }
301  }
302 }
303 
305  int *got_packet)
306 {
307  X264Context *x4 = ctx->priv_data;
308  x264_nal_t *nal;
309  int nnal, i, ret;
310  x264_picture_t pic_out = {0};
311  int pict_type;
312  int bit_depth;
313  int64_t wallclock = 0;
314  X264Opaque *out_opaque;
315  AVFrameSideData *sd;
316 
317  x264_picture_init( &x4->pic );
318  x4->pic.img.i_csp = x4->params.i_csp;
319 #if X264_BUILD >= 153
320  bit_depth = x4->params.i_bitdepth;
321 #else
322  bit_depth = x264_bit_depth;
323 #endif
324  if (bit_depth > 8)
325  x4->pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
326  x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt);
327 
328  if (frame) {
329  for (i = 0; i < x4->pic.img.i_plane; i++) {
330  x4->pic.img.plane[i] = frame->data[i];
331  x4->pic.img.i_stride[i] = frame->linesize[i];
332  }
333 
334  x4->pic.i_pts = frame->pts;
335 
337  x4->reordered_opaque[x4->next_reordered_opaque].wallclock = wallclock;
338  if (ctx->export_side_data & AV_CODEC_EXPORT_DATA_PRFT)
340  x4->pic.opaque = &x4->reordered_opaque[x4->next_reordered_opaque];
341  x4->next_reordered_opaque++;
343 
344  switch (frame->pict_type) {
345  case AV_PICTURE_TYPE_I:
346  x4->pic.i_type = x4->forced_idr > 0 ? X264_TYPE_IDR
347  : X264_TYPE_KEYFRAME;
348  break;
349  case AV_PICTURE_TYPE_P:
350  x4->pic.i_type = X264_TYPE_P;
351  break;
352  case AV_PICTURE_TYPE_B:
353  x4->pic.i_type = X264_TYPE_B;
354  break;
355  default:
356  x4->pic.i_type = X264_TYPE_AUTO;
357  break;
358  }
360 
361  if (x4->a53_cc) {
362  void *sei_data;
363  size_t sei_size;
364 
365  ret = ff_alloc_a53_sei(frame, 0, &sei_data, &sei_size);
366  if (ret < 0) {
367  av_log(ctx, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n");
368  } else if (sei_data) {
369  x4->pic.extra_sei.payloads = av_mallocz(sizeof(x4->pic.extra_sei.payloads[0]));
370  if (x4->pic.extra_sei.payloads == NULL) {
371  av_log(ctx, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n");
372  av_free(sei_data);
373  } else {
374  x4->pic.extra_sei.sei_free = av_free;
375 
376  x4->pic.extra_sei.payloads[0].payload_size = sei_size;
377  x4->pic.extra_sei.payloads[0].payload = sei_data;
378  x4->pic.extra_sei.num_payloads = 1;
379  x4->pic.extra_sei.payloads[0].payload_type = 4;
380  }
381  }
382  }
383 
385  if (sd) {
386  if (x4->params.rc.i_aq_mode == X264_AQ_NONE) {
387  if (!x4->roi_warned) {
388  x4->roi_warned = 1;
389  av_log(ctx, AV_LOG_WARNING, "Adaptive quantization must be enabled to use ROI encoding, skipping ROI.\n");
390  }
391  } else {
392  if (frame->interlaced_frame == 0) {
393  int mbx = (frame->width + MB_SIZE - 1) / MB_SIZE;
394  int mby = (frame->height + MB_SIZE - 1) / MB_SIZE;
395  int qp_range = 51 + 6 * (bit_depth - 8);
396  int nb_rois;
397  const AVRegionOfInterest *roi;
398  uint32_t roi_size;
399  float *qoffsets;
400 
401  roi = (const AVRegionOfInterest*)sd->data;
402  roi_size = roi->self_size;
403  if (!roi_size || sd->size % roi_size != 0) {
404  av_log(ctx, AV_LOG_ERROR, "Invalid AVRegionOfInterest.self_size.\n");
405  return AVERROR(EINVAL);
406  }
407  nb_rois = sd->size / roi_size;
408 
409  qoffsets = av_mallocz_array(mbx * mby, sizeof(*qoffsets));
410  if (!qoffsets)
411  return AVERROR(ENOMEM);
412 
413  // This list must be iterated in reverse because the first
414  // region in the list applies when regions overlap.
415  for (int i = nb_rois - 1; i >= 0; i--) {
416  int startx, endx, starty, endy;
417  float qoffset;
418 
419  roi = (const AVRegionOfInterest*)(sd->data + roi_size * i);
420 
421  starty = FFMIN(mby, roi->top / MB_SIZE);
422  endy = FFMIN(mby, (roi->bottom + MB_SIZE - 1)/ MB_SIZE);
423  startx = FFMIN(mbx, roi->left / MB_SIZE);
424  endx = FFMIN(mbx, (roi->right + MB_SIZE - 1)/ MB_SIZE);
425 
426  if (roi->qoffset.den == 0) {
427  av_free(qoffsets);
428  av_log(ctx, AV_LOG_ERROR, "AVRegionOfInterest.qoffset.den must not be zero.\n");
429  return AVERROR(EINVAL);
430  }
431  qoffset = roi->qoffset.num * 1.0f / roi->qoffset.den;
432  qoffset = av_clipf(qoffset * qp_range, -qp_range, +qp_range);
433 
434  for (int y = starty; y < endy; y++) {
435  for (int x = startx; x < endx; x++) {
436  qoffsets[x + y*mbx] = qoffset;
437  }
438  }
439  }
440 
441  x4->pic.prop.quant_offsets = qoffsets;
442  x4->pic.prop.quant_offsets_free = av_free;
443  } else {
444  if (!x4->roi_warned) {
445  x4->roi_warned = 1;
446  av_log(ctx, AV_LOG_WARNING, "interlaced_frame not supported for ROI encoding yet, skipping ROI.\n");
447  }
448  }
449  }
450  }
451  }
452 
453  do {
454  if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
455  return AVERROR_EXTERNAL;
456 
457  ret = encode_nals(ctx, pkt, nal, nnal);
458  if (ret < 0)
459  return ret;
460  } while (!ret && !frame && x264_encoder_delayed_frames(x4->enc));
461 
462  if (!ret)
463  return 0;
464 
465  pkt->pts = pic_out.i_pts;
466  pkt->dts = pic_out.i_dts;
467 
468  out_opaque = pic_out.opaque;
469  if (out_opaque >= x4->reordered_opaque &&
470  out_opaque < &x4->reordered_opaque[x4->nb_reordered_opaque]) {
471  ctx->reordered_opaque = out_opaque->reordered_opaque;
472  wallclock = out_opaque->wallclock;
473  } else {
474  // Unexpected opaque pointer on picture output
475  ctx->reordered_opaque = 0;
476  }
477 
478  switch (pic_out.i_type) {
479  case X264_TYPE_IDR:
480  case X264_TYPE_I:
481  pict_type = AV_PICTURE_TYPE_I;
482  break;
483  case X264_TYPE_P:
484  pict_type = AV_PICTURE_TYPE_P;
485  break;
486  case X264_TYPE_B:
487  case X264_TYPE_BREF:
488  pict_type = AV_PICTURE_TYPE_B;
489  break;
490  default:
491  av_log(ctx, AV_LOG_ERROR, "Unknown picture type encountered.\n");
492  return AVERROR_EXTERNAL;
493  }
494 #if FF_API_CODED_FRAME
496  ctx->coded_frame->pict_type = pict_type;
498 #endif
499 
500  pkt->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe;
501  if (ret) {
502  ff_side_data_set_encoder_stats(pkt, (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA, NULL, 0, pict_type);
503  if (wallclock)
504  ff_side_data_set_prft(pkt, wallclock);
505 
506 #if FF_API_CODED_FRAME
508  ctx->coded_frame->quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
510 #endif
511  }
512 
513  *got_packet = ret;
514  return 0;
515 }
516 
518 {
519  X264Context *x4 = avctx->priv_data;
520 
521  av_freep(&avctx->extradata);
522  av_freep(&x4->sei);
524 
525 #if X264_BUILD >= 161
526  x264_param_cleanup(&x4->params);
527 #endif
528 
529  if (x4->enc) {
530  x264_encoder_close(x4->enc);
531  x4->enc = NULL;
532  }
533 
534  return 0;
535 }
536 
537 static int parse_opts(AVCodecContext *avctx, const char *opt, const char *param)
538 {
539  X264Context *x4 = avctx->priv_data;
540  int ret;
541 
542  if ((ret = x264_param_parse(&x4->params, opt, param)) < 0) {
543  if (ret == X264_PARAM_BAD_NAME) {
544  av_log(avctx, AV_LOG_ERROR,
545  "bad option '%s': '%s'\n", opt, param);
546  ret = AVERROR(EINVAL);
547 #if X264_BUILD >= 161
548  } else if (ret == X264_PARAM_ALLOC_FAILED) {
549  av_log(avctx, AV_LOG_ERROR,
550  "out of memory parsing option '%s': '%s'\n", opt, param);
551  ret = AVERROR(ENOMEM);
552 #endif
553  } else {
554  av_log(avctx, AV_LOG_ERROR,
555  "bad value for '%s': '%s'\n", opt, param);
556  ret = AVERROR(EINVAL);
557  }
558  }
559 
560  return ret;
561 }
562 
564 {
565  switch (pix_fmt) {
566  case AV_PIX_FMT_YUV420P:
567  case AV_PIX_FMT_YUVJ420P:
568  case AV_PIX_FMT_YUV420P9:
569  case AV_PIX_FMT_YUV420P10: return X264_CSP_I420;
570  case AV_PIX_FMT_YUV422P:
571  case AV_PIX_FMT_YUVJ422P:
572  case AV_PIX_FMT_YUV422P10: return X264_CSP_I422;
573  case AV_PIX_FMT_YUV444P:
574  case AV_PIX_FMT_YUVJ444P:
575  case AV_PIX_FMT_YUV444P9:
576  case AV_PIX_FMT_YUV444P10: return X264_CSP_I444;
577 #if CONFIG_LIBX264RGB_ENCODER
578  case AV_PIX_FMT_BGR0:
579  return X264_CSP_BGRA;
580  case AV_PIX_FMT_BGR24:
581  return X264_CSP_BGR;
582 
583  case AV_PIX_FMT_RGB24:
584  return X264_CSP_RGB;
585 #endif
586  case AV_PIX_FMT_NV12: return X264_CSP_NV12;
587  case AV_PIX_FMT_NV16:
588  case AV_PIX_FMT_NV20: return X264_CSP_NV16;
589 #ifdef X264_CSP_NV21
590  case AV_PIX_FMT_NV21: return X264_CSP_NV21;
591 #endif
592 #ifdef X264_CSP_I400
593  case AV_PIX_FMT_GRAY8:
594  case AV_PIX_FMT_GRAY10: return X264_CSP_I400;
595 #endif
596  };
597  return 0;
598 }
599 
600 #define PARSE_X264_OPT(name, var)\
601  if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
602  av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
603  return AVERROR(EINVAL);\
604  }
605 
606 static av_cold int X264_init(AVCodecContext *avctx)
607 {
608  X264Context *x4 = avctx->priv_data;
609  AVCPBProperties *cpb_props;
610  int sw,sh;
611  int ret;
612 
613  if (avctx->global_quality > 0)
614  av_log(avctx, AV_LOG_WARNING, "-qscale is ignored, -crf is recommended.\n");
615 
616 #if CONFIG_LIBX262_ENCODER
617  if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
618  x4->params.b_mpeg2 = 1;
619  x264_param_default_mpeg2(&x4->params);
620  } else
621 #endif
622  x264_param_default(&x4->params);
623 
624  x4->params.b_deblocking_filter = avctx->flags & AV_CODEC_FLAG_LOOP_FILTER;
625 
626  if (x4->preset || x4->tune)
627  if (x264_param_default_preset(&x4->params, x4->preset, x4->tune) < 0) {
628  int i;
629  av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", x4->preset, x4->tune);
630  av_log(avctx, AV_LOG_INFO, "Possible presets:");
631  for (i = 0; x264_preset_names[i]; i++)
632  av_log(avctx, AV_LOG_INFO, " %s", x264_preset_names[i]);
633  av_log(avctx, AV_LOG_INFO, "\n");
634  av_log(avctx, AV_LOG_INFO, "Possible tunes:");
635  for (i = 0; x264_tune_names[i]; i++)
636  av_log(avctx, AV_LOG_INFO, " %s", x264_tune_names[i]);
637  av_log(avctx, AV_LOG_INFO, "\n");
638  return AVERROR(EINVAL);
639  }
640 
641  if (avctx->level > 0)
642  x4->params.i_level_idc = avctx->level;
643 
644  x4->params.pf_log = X264_log;
645  x4->params.p_log_private = avctx;
646  x4->params.i_log_level = X264_LOG_DEBUG;
647  x4->params.i_csp = convert_pix_fmt(avctx->pix_fmt);
648 #if X264_BUILD >= 153
649  x4->params.i_bitdepth = av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth;
650 #endif
651 
652  PARSE_X264_OPT("weightp", wpredp);
653 
654  if (avctx->bit_rate) {
655  if (avctx->bit_rate / 1000 > INT_MAX || avctx->rc_max_rate / 1000 > INT_MAX) {
656  av_log(avctx, AV_LOG_ERROR, "bit_rate and rc_max_rate > %d000 not supported by libx264\n", INT_MAX);
657  return AVERROR(EINVAL);
658  }
659  x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
660  x4->params.rc.i_rc_method = X264_RC_ABR;
661  }
662  x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
663  x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
664  x4->params.rc.b_stat_write = avctx->flags & AV_CODEC_FLAG_PASS1;
665  if (avctx->flags & AV_CODEC_FLAG_PASS2) {
666  x4->params.rc.b_stat_read = 1;
667  } else {
668  if (x4->crf >= 0) {
669  x4->params.rc.i_rc_method = X264_RC_CRF;
670  x4->params.rc.f_rf_constant = x4->crf;
671  } else if (x4->cqp >= 0) {
672  x4->params.rc.i_rc_method = X264_RC_CQP;
673  x4->params.rc.i_qp_constant = x4->cqp;
674  }
675 
676  if (x4->crf_max >= 0)
677  x4->params.rc.f_rf_constant_max = x4->crf_max;
678  }
679 
680  if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy > 0 &&
681  (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
682  x4->params.rc.f_vbv_buffer_init =
683  (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size;
684  }
685 
686  PARSE_X264_OPT("level", level);
687 
688  if (avctx->i_quant_factor > 0)
689  x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor);
690  if (avctx->b_quant_factor > 0)
691  x4->params.rc.f_pb_factor = avctx->b_quant_factor;
692 
693 #if FF_API_PRIVATE_OPT
695  if (avctx->chromaoffset)
696  x4->chroma_offset = avctx->chromaoffset;
698 #endif
699  if (x4->chroma_offset)
700  x4->params.analyse.i_chroma_qp_offset = x4->chroma_offset;
701 
702  if (avctx->gop_size >= 0)
703  x4->params.i_keyint_max = avctx->gop_size;
704  if (avctx->max_b_frames >= 0)
705  x4->params.i_bframe = avctx->max_b_frames;
706 
707 #if FF_API_PRIVATE_OPT
709  if (avctx->scenechange_threshold >= 0)
712 #endif
713  if (x4->scenechange_threshold >= 0)
714  x4->params.i_scenecut_threshold = x4->scenechange_threshold;
715 
716  if (avctx->qmin >= 0)
717  x4->params.rc.i_qp_min = avctx->qmin;
718  if (avctx->qmax >= 0)
719  x4->params.rc.i_qp_max = avctx->qmax;
720  if (avctx->max_qdiff >= 0)
721  x4->params.rc.i_qp_step = avctx->max_qdiff;
722  if (avctx->qblur >= 0)
723  x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */
724  if (avctx->qcompress >= 0)
725  x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
726  if (avctx->refs >= 0)
727  x4->params.i_frame_reference = avctx->refs;
728  else if (x4->params.i_level_idc > 0) {
729  int i;
730  int mbn = AV_CEIL_RSHIFT(avctx->width, 4) * AV_CEIL_RSHIFT(avctx->height, 4);
731  int scale = X264_BUILD < 129 ? 384 : 1;
732 
733  for (i = 0; i<x264_levels[i].level_idc; i++)
734  if (x264_levels[i].level_idc == x4->params.i_level_idc)
735  x4->params.i_frame_reference = av_clip(x264_levels[i].dpb / mbn / scale, 1, x4->params.i_frame_reference);
736  }
737 
738  if (avctx->trellis >= 0)
739  x4->params.analyse.i_trellis = avctx->trellis;
740  if (avctx->me_range >= 0)
741  x4->params.analyse.i_me_range = avctx->me_range;
742 #if FF_API_PRIVATE_OPT
744  if (avctx->noise_reduction >= 0)
745  x4->noise_reduction = avctx->noise_reduction;
747 #endif
748  if (x4->noise_reduction >= 0)
749  x4->params.analyse.i_noise_reduction = x4->noise_reduction;
750  if (avctx->me_subpel_quality >= 0)
751  x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
752 #if FF_API_PRIVATE_OPT
754  if (avctx->b_frame_strategy >= 0)
755  x4->b_frame_strategy = avctx->b_frame_strategy;
757 #endif
758  if (avctx->keyint_min >= 0)
759  x4->params.i_keyint_min = avctx->keyint_min;
760 #if FF_API_CODER_TYPE
762  if (avctx->coder_type >= 0)
763  x4->coder = avctx->coder_type == FF_CODER_TYPE_AC;
765 #endif
766  if (avctx->me_cmp >= 0)
767  x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
768 
769  if (x4->aq_mode >= 0)
770  x4->params.rc.i_aq_mode = x4->aq_mode;
771  if (x4->aq_strength >= 0)
772  x4->params.rc.f_aq_strength = x4->aq_strength;
773  PARSE_X264_OPT("psy-rd", psy_rd);
774  PARSE_X264_OPT("deblock", deblock);
775  PARSE_X264_OPT("partitions", partitions);
776  PARSE_X264_OPT("stats", stats);
777  if (x4->psy >= 0)
778  x4->params.analyse.b_psy = x4->psy;
779  if (x4->rc_lookahead >= 0)
780  x4->params.rc.i_lookahead = x4->rc_lookahead;
781  if (x4->weightp >= 0)
782  x4->params.analyse.i_weighted_pred = x4->weightp;
783  if (x4->weightb >= 0)
784  x4->params.analyse.b_weighted_bipred = x4->weightb;
785  if (x4->cplxblur >= 0)
786  x4->params.rc.f_complexity_blur = x4->cplxblur;
787 
788  if (x4->ssim >= 0)
789  x4->params.analyse.b_ssim = x4->ssim;
790  if (x4->intra_refresh >= 0)
791  x4->params.b_intra_refresh = x4->intra_refresh;
792  if (x4->bluray_compat >= 0) {
793  x4->params.b_bluray_compat = x4->bluray_compat;
794  x4->params.b_vfr_input = 0;
795  }
796  if (x4->avcintra_class >= 0)
797 #if X264_BUILD >= 142
798  x4->params.i_avcintra_class = x4->avcintra_class;
799 #else
800  av_log(avctx, AV_LOG_ERROR,
801  "x264 too old for AVC Intra, at least version 142 needed\n");
802 #endif
803  if (x4->b_bias != INT_MIN)
804  x4->params.i_bframe_bias = x4->b_bias;
805  if (x4->b_pyramid >= 0)
806  x4->params.i_bframe_pyramid = x4->b_pyramid;
807  if (x4->mixed_refs >= 0)
808  x4->params.analyse.b_mixed_references = x4->mixed_refs;
809  if (x4->dct8x8 >= 0)
810  x4->params.analyse.b_transform_8x8 = x4->dct8x8;
811  if (x4->fast_pskip >= 0)
812  x4->params.analyse.b_fast_pskip = x4->fast_pskip;
813  if (x4->aud >= 0)
814  x4->params.b_aud = x4->aud;
815  if (x4->mbtree >= 0)
816  x4->params.rc.b_mb_tree = x4->mbtree;
817  if (x4->direct_pred >= 0)
818  x4->params.analyse.i_direct_mv_pred = x4->direct_pred;
819 
820  if (x4->slice_max_size >= 0)
821  x4->params.i_slice_max_size = x4->slice_max_size;
822 
823  if (x4->fastfirstpass)
824  x264_param_apply_fastfirstpass(&x4->params);
825 
826  /* Allow specifying the x264 profile through AVCodecContext. */
827  if (!x4->profile)
828  switch (avctx->profile) {
830  x4->profile = av_strdup("baseline");
831  break;
833  x4->profile = av_strdup("high");
834  break;
836  x4->profile = av_strdup("high10");
837  break;
839  x4->profile = av_strdup("high422");
840  break;
842  x4->profile = av_strdup("high444");
843  break;
845  x4->profile = av_strdup("main");
846  break;
847  default:
848  break;
849  }
850 
851  if (x4->nal_hrd >= 0)
852  x4->params.i_nal_hrd = x4->nal_hrd;
853 
854  if (x4->motion_est >= 0)
855  x4->params.analyse.i_me_method = x4->motion_est;
856 
857  if (x4->coder >= 0)
858  x4->params.b_cabac = x4->coder;
859 
860  if (x4->b_frame_strategy >= 0)
861  x4->params.i_bframe_adaptive = x4->b_frame_strategy;
862 
863  if (x4->profile)
864  if (x264_param_apply_profile(&x4->params, x4->profile) < 0) {
865  int i;
866  av_log(avctx, AV_LOG_ERROR, "Error setting profile %s.\n", x4->profile);
867  av_log(avctx, AV_LOG_INFO, "Possible profiles:");
868  for (i = 0; x264_profile_names[i]; i++)
869  av_log(avctx, AV_LOG_INFO, " %s", x264_profile_names[i]);
870  av_log(avctx, AV_LOG_INFO, "\n");
871  return AVERROR(EINVAL);
872  }
873 
874  x4->params.i_width = avctx->width;
875  x4->params.i_height = avctx->height;
876  av_reduce(&sw, &sh, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 4096);
877  x4->params.vui.i_sar_width = sw;
878  x4->params.vui.i_sar_height = sh;
879  x4->params.i_timebase_den = avctx->time_base.den;
880  x4->params.i_timebase_num = avctx->time_base.num;
881  if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
882  x4->params.i_fps_num = avctx->framerate.num;
883  x4->params.i_fps_den = avctx->framerate.den;
884  } else {
885  x4->params.i_fps_num = avctx->time_base.den;
886  x4->params.i_fps_den = avctx->time_base.num * avctx->ticks_per_frame;
887  }
888 
889  x4->params.analyse.b_psnr = avctx->flags & AV_CODEC_FLAG_PSNR;
890 
891  x4->params.i_threads = avctx->thread_count;
892  if (avctx->thread_type)
893  x4->params.b_sliced_threads = avctx->thread_type == FF_THREAD_SLICE;
894 
895  x4->params.b_interlaced = avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT;
896 
897  x4->params.b_open_gop = !(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP);
898 
899  x4->params.i_slice_count = avctx->slices;
900 
901  if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED)
902  x4->params.vui.b_fullrange = avctx->color_range == AVCOL_RANGE_JPEG;
903  else if (avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
904  avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
905  avctx->pix_fmt == AV_PIX_FMT_YUVJ444P)
906  x4->params.vui.b_fullrange = 1;
907 
908  if (avctx->colorspace != AVCOL_SPC_UNSPECIFIED)
909  x4->params.vui.i_colmatrix = avctx->colorspace;
911  x4->params.vui.i_colorprim = avctx->color_primaries;
912  if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED)
913  x4->params.vui.i_transfer = avctx->color_trc;
914 
915  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)
916  x4->params.b_repeat_headers = 0;
917 
918  if(x4->x264opts){
919  const char *p= x4->x264opts;
920  while(p){
921  char param[4096]={0}, val[4096]={0};
922  if(sscanf(p, "%4095[^:=]=%4095[^:]", param, val) == 1){
923  ret = parse_opts(avctx, param, "1");
924  if (ret < 0)
925  return ret;
926  } else {
927  ret = parse_opts(avctx, param, val);
928  if (ret < 0)
929  return ret;
930  }
931  p= strchr(p, ':');
932  p+=!!p;
933  }
934  }
935 
936 
937  {
938  AVDictionaryEntry *en = NULL;
939  while (en = av_dict_get(x4->x264_params, "", en, AV_DICT_IGNORE_SUFFIX)) {
940  if ((ret = x264_param_parse(&x4->params, en->key, en->value)) < 0) {
941  av_log(avctx, AV_LOG_WARNING,
942  "Error parsing option '%s = %s'.\n",
943  en->key, en->value);
944 #if X264_BUILD >= 161
945  if (ret == X264_PARAM_ALLOC_FAILED)
946  return AVERROR(ENOMEM);
947 #endif
948  }
949  }
950  }
951 
952  // update AVCodecContext with x264 parameters
953  avctx->has_b_frames = x4->params.i_bframe ?
954  x4->params.i_bframe_pyramid ? 2 : 1 : 0;
955  if (avctx->max_b_frames < 0)
956  avctx->max_b_frames = 0;
957 
958  avctx->bit_rate = x4->params.rc.i_bitrate*1000LL;
959 
960  x4->enc = x264_encoder_open(&x4->params);
961  if (!x4->enc)
962  return AVERROR_EXTERNAL;
963 
964  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
965  x264_nal_t *nal;
966  uint8_t *p;
967  int nnal, s, i;
968 
969  s = x264_encoder_headers(x4->enc, &nal, &nnal);
971  if (!p)
972  return AVERROR(ENOMEM);
973 
974  for (i = 0; i < nnal; i++) {
975  /* Don't put the SEI in extradata. */
976  if (nal[i].i_type == NAL_SEI) {
977  av_log(avctx, AV_LOG_INFO, "%s\n", nal[i].p_payload+25);
978  x4->sei_size = nal[i].i_payload;
979  x4->sei = av_malloc(x4->sei_size);
980  if (!x4->sei)
981  return AVERROR(ENOMEM);
982  memcpy(x4->sei, nal[i].p_payload, nal[i].i_payload);
983  continue;
984  }
985  memcpy(p, nal[i].p_payload, nal[i].i_payload);
986  p += nal[i].i_payload;
987  }
988  avctx->extradata_size = p - avctx->extradata;
989  }
990 
991  cpb_props = ff_add_cpb_side_data(avctx);
992  if (!cpb_props)
993  return AVERROR(ENOMEM);
994  cpb_props->buffer_size = x4->params.rc.i_vbv_buffer_size * 1000;
995  cpb_props->max_bitrate = x4->params.rc.i_vbv_max_bitrate * 1000LL;
996  cpb_props->avg_bitrate = x4->params.rc.i_bitrate * 1000LL;
997 
998  // Overestimate the reordered opaque buffer size, in case a runtime
999  // reconfigure would increase the delay (which it shouldn't).
1000  x4->nb_reordered_opaque = x264_encoder_maximum_delayed_frames(x4->enc) + 17;
1002  sizeof(*x4->reordered_opaque));
1003  if (!x4->reordered_opaque)
1004  return AVERROR(ENOMEM);
1005 
1006  return 0;
1007 }
1008 
1009 static const enum AVPixelFormat pix_fmts_8bit[] = {
1018 #ifdef X264_CSP_NV21
1020 #endif
1022 };
1023 static const enum AVPixelFormat pix_fmts_9bit[] = {
1027 };
1028 static const enum AVPixelFormat pix_fmts_10bit[] = {
1034 };
1035 static const enum AVPixelFormat pix_fmts_all[] = {
1044 #ifdef X264_CSP_NV21
1046 #endif
1051 #ifdef X264_CSP_I400
1054 #endif
1056 };
1057 #if CONFIG_LIBX264RGB_ENCODER
1058 static const enum AVPixelFormat pix_fmts_8bit_rgb[] = {
1063 };
1064 #endif
1065 
1066 #if X264_BUILD < 153
1067 static av_cold void X264_init_static(AVCodec *codec)
1068 {
1069  if (x264_bit_depth == 8)
1070  codec->pix_fmts = pix_fmts_8bit;
1071  else if (x264_bit_depth == 9)
1072  codec->pix_fmts = pix_fmts_9bit;
1073  else if (x264_bit_depth == 10)
1074  codec->pix_fmts = pix_fmts_10bit;
1075 }
1076 #endif
1077 
1078 #define OFFSET(x) offsetof(X264Context, x)
1079 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1080 static const AVOption options[] = {
1081  { "preset", "Set the encoding preset (cf. x264 --fullhelp)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "medium" }, 0, 0, VE},
1082  { "tune", "Tune the encoding params (cf. x264 --fullhelp)", OFFSET(tune), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
1083  { "profile", "Set profile restrictions (cf. x264 --fullhelp) ", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
1084  { "fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE},
1085  {"level", "Specify level (as defined by Annex A)", OFFSET(level), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
1086  {"passlogfile", "Filename for 2 pass stats", OFFSET(stats), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
1087  {"wpredp", "Weighted prediction for P-frames", OFFSET(wpredp), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
1088  {"a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, VE},
1089  {"x264opts", "x264 options", OFFSET(x264opts), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
1090  { "crf", "Select the quality for constant quality mode", OFFSET(crf), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VE },
1091  { "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 },
1092  { "qp", "Constant quantization parameter rate control method",OFFSET(cqp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE },
1093  { "aq-mode", "AQ method", OFFSET(aq_mode), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, "aq_mode"},
1094  { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_NONE}, INT_MIN, INT_MAX, VE, "aq_mode" },
1095  { "variance", "Variance AQ (complexity mask)", 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" },
1096  { "autovariance", "Auto-variance AQ", 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" },
1097 #if X264_BUILD >= 144
1098  { "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, "aq_mode" },
1099 #endif
1100  { "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},
1101  { "psy", "Use psychovisual optimizations.", OFFSET(psy), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1102  { "psy-rd", "Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.", OFFSET(psy_rd), AV_OPT_TYPE_STRING, {0 }, 0, 0, VE},
1103  { "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 },
1104  { "weightb", "Weighted prediction for B-frames.", OFFSET(weightb), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1105  { "weightp", "Weighted prediction analysis method.", OFFSET(weightp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, "weightp" },
1106  { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_NONE}, INT_MIN, INT_MAX, VE, "weightp" },
1107  { "simple", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SIMPLE}, INT_MIN, INT_MAX, VE, "weightp" },
1108  { "smart", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SMART}, INT_MIN, INT_MAX, VE, "weightp" },
1109  { "ssim", "Calculate and print SSIM stats.", OFFSET(ssim), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1110  { "intra-refresh", "Use Periodic Intra Refresh instead of IDR frames.",OFFSET(intra_refresh),AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1111  { "bluray-compat", "Bluray compatibility workarounds.", OFFSET(bluray_compat) ,AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1112  { "b-bias", "Influences how often B-frames are used", OFFSET(b_bias), AV_OPT_TYPE_INT, { .i64 = INT_MIN}, INT_MIN, INT_MAX, VE },
1113  { "b-pyramid", "Keep some B-frames as references.", OFFSET(b_pyramid), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, "b_pyramid" },
1114  { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NONE}, INT_MIN, INT_MAX, VE, "b_pyramid" },
1115  { "strict", "Strictly hierarchical pyramid", 0, AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX, VE, "b_pyramid" },
1116  { "normal", "Non-strict (not Blu-ray compatible)", 0, AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX, VE, "b_pyramid" },
1117  { "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 },
1118  { "8x8dct", "High profile 8x8 transform.", OFFSET(dct8x8), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE},
1119  { "fast-pskip", NULL, OFFSET(fast_pskip), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE},
1120  { "aud", "Use access unit delimiters.", OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE},
1121  { "mbtree", "Use macroblock tree ratecontrol.", OFFSET(mbtree), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE},
1122  { "deblock", "Loop filter parameters, in <alpha:beta> form.", OFFSET(deblock), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
1123  { "cplxblur", "Reduce fluctuations in QP (before curve compression)", OFFSET(cplxblur), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VE},
1124  { "partitions", "A comma-separated list of partitions to consider. "
1125  "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all", OFFSET(partitions), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
1126  { "direct-pred", "Direct MV prediction mode", OFFSET(direct_pred), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, "direct-pred" },
1127  { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_NONE }, 0, 0, VE, "direct-pred" },
1128  { "spatial", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_SPATIAL }, 0, 0, VE, "direct-pred" },
1129  { "temporal", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_TEMPORAL }, 0, 0, VE, "direct-pred" },
1130  { "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_AUTO }, 0, 0, VE, "direct-pred" },
1131  { "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 },
1132  { "stats", "Filename for 2 pass stats", OFFSET(stats), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
1133  { "nal-hrd", "Signal HRD information (requires vbv-bufsize; "
1134  "cbr not allowed in .mp4)", OFFSET(nal_hrd), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, "nal-hrd" },
1135  { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_NONE}, INT_MIN, INT_MAX, VE, "nal-hrd" },
1136  { "vbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_VBR}, INT_MIN, INT_MAX, VE, "nal-hrd" },
1137  { "cbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_CBR}, INT_MIN, INT_MAX, VE, "nal-hrd" },
1138  { "avcintra-class","AVC-Intra class 50/100/200", OFFSET(avcintra_class),AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 200 , VE},
1139  { "me_method", "Set motion estimation method", OFFSET(motion_est), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, X264_ME_TESA, VE, "motion-est"},
1140  { "motion-est", "Set motion estimation method", OFFSET(motion_est), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, X264_ME_TESA, VE, "motion-est"},
1141  { "dia", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_DIA }, INT_MIN, INT_MAX, VE, "motion-est" },
1142  { "hex", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_HEX }, INT_MIN, INT_MAX, VE, "motion-est" },
1143  { "umh", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_UMH }, INT_MIN, INT_MAX, VE, "motion-est" },
1144  { "esa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_ESA }, INT_MIN, INT_MAX, VE, "motion-est" },
1145  { "tesa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_TESA }, INT_MIN, INT_MAX, VE, "motion-est" },
1146  { "forced-idr", "If forcing keyframes, force them as IDR frames.", OFFSET(forced_idr), AV_OPT_TYPE_BOOL, { .i64 = 0 }, -1, 1, VE },
1147  { "coder", "Coder type", OFFSET(coder), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE, "coder" },
1148  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, INT_MIN, INT_MAX, VE, "coder" },
1149  { "cavlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, "coder" },
1150  { "cabac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "coder" },
1151  { "vlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, "coder" },
1152  { "ac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "coder" },
1153  { "b_strategy", "Strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2, VE },
1154  { "chromaoffset", "QP difference between chroma and luma", OFFSET(chroma_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, VE },
1155  { "sc_threshold", "Scene change threshold", OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX, VE },
1156  { "noise_reduction", "Noise reduction", OFFSET(noise_reduction), AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX, VE },
1157 
1158  { "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 },
1159  { NULL },
1160 };
1161 
1162 static const AVCodecDefault x264_defaults[] = {
1163  { "b", "0" },
1164  { "bf", "-1" },
1165  { "flags2", "0" },
1166  { "g", "-1" },
1167  { "i_qfactor", "-1" },
1168  { "b_qfactor", "-1" },
1169  { "qmin", "-1" },
1170  { "qmax", "-1" },
1171  { "qdiff", "-1" },
1172  { "qblur", "-1" },
1173  { "qcomp", "-1" },
1174 // { "rc_lookahead", "-1" },
1175  { "refs", "-1" },
1176 #if FF_API_PRIVATE_OPT
1177  { "sc_threshold", "-1" },
1178 #endif
1179  { "trellis", "-1" },
1180 #if FF_API_PRIVATE_OPT
1181  { "nr", "-1" },
1182 #endif
1183  { "me_range", "-1" },
1184  { "subq", "-1" },
1185 #if FF_API_PRIVATE_OPT
1186  { "b_strategy", "-1" },
1187 #endif
1188  { "keyint_min", "-1" },
1189 #if FF_API_CODER_TYPE
1190  { "coder", "-1" },
1191 #endif
1192  { "cmp", "-1" },
1193  { "threads", AV_STRINGIFY(X264_THREADS_AUTO) },
1194  { "thread_type", "0" },
1195  { "flags", "+cgop" },
1196  { "rc_init_occupancy","-1" },
1197  { NULL },
1198 };
1199 
1200 #if CONFIG_LIBX264_ENCODER
1201 static const AVClass x264_class = {
1202  .class_name = "libx264",
1203  .item_name = av_default_item_name,
1204  .option = options,
1205  .version = LIBAVUTIL_VERSION_INT,
1206 };
1207 
1209  .name = "libx264",
1210  .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
1211  .type = AVMEDIA_TYPE_VIDEO,
1212  .id = AV_CODEC_ID_H264,
1213  .priv_data_size = sizeof(X264Context),
1214  .init = X264_init,
1215  .encode2 = X264_frame,
1216  .close = X264_close,
1219  .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
1220  .priv_class = &x264_class,
1222 #if X264_BUILD < 153
1224 #else
1226 #endif
1228 #if X264_BUILD >= 158
1230 #endif
1231  ,
1232  .wrapper_name = "libx264",
1233 };
1234 #endif
1235 
1236 #if CONFIG_LIBX264RGB_ENCODER
1237 static const AVClass rgbclass = {
1238  .class_name = "libx264rgb",
1239  .item_name = av_default_item_name,
1240  .option = options,
1241  .version = LIBAVUTIL_VERSION_INT,
1242 };
1243 
1245  .name = "libx264rgb",
1246  .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB"),
1247  .type = AVMEDIA_TYPE_VIDEO,
1248  .id = AV_CODEC_ID_H264,
1249  .priv_data_size = sizeof(X264Context),
1250  .init = X264_init,
1251  .encode2 = X264_frame,
1252  .close = X264_close,
1255  .priv_class = &rgbclass,
1257  .pix_fmts = pix_fmts_8bit_rgb,
1259 #if X264_BUILD >= 158
1261 #endif
1262  ,
1263  .wrapper_name = "libx264",
1264 };
1265 #endif
1266 
1267 #if CONFIG_LIBX262_ENCODER
1268 static const AVClass X262_class = {
1269  .class_name = "libx262",
1270  .item_name = av_default_item_name,
1271  .option = options,
1272  .version = LIBAVUTIL_VERSION_INT,
1273 };
1274 
1276  .name = "libx262",
1277  .long_name = NULL_IF_CONFIG_SMALL("libx262 MPEG2VIDEO"),
1278  .type = AVMEDIA_TYPE_VIDEO,
1279  .id = AV_CODEC_ID_MPEG2VIDEO,
1280  .priv_data_size = sizeof(X264Context),
1281  .init = X264_init,
1282  .encode2 = X264_frame,
1283  .close = X264_close,
1286  .priv_class = &X262_class,
1290  .wrapper_name = "libx264",
1291 };
1292 #endif
static double val(void *priv, double ch)
Definition: aeval.c:76
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:254
AVCodec ff_libx262_encoder
AVCodec ff_libx264_encoder
AVCodec ff_libx264rgb_encoder
static const AVCodecDefault defaults[]
Definition: amfenc_h264.c:361
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
#define av_cold
Definition: attributes.h:88
uint8_t
Libavcodec external API header.
#define FF_PROFILE_H264_HIGH
Definition: avcodec.h:1905
#define FF_PROFILE_H264_HIGH_444
Definition: avcodec.h:1912
#define FF_CMP_CHROMA
Definition: avcodec.h:957
#define FF_PROFILE_H264_HIGH_422
Definition: avcodec.h:1909
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
Definition: avcodec.h:1789
#define FF_PROFILE_H264_MAIN
Definition: avcodec.h:1903
#define FF_PROFILE_H264_HIGH_10
Definition: avcodec.h:1906
#define FF_PROFILE_H264_BASELINE
Definition: avcodec.h:1901
#define FF_CODER_TYPE_AC
Definition: avcodec.h:1452
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
Definition: avpacket.c:820
int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp)
Definition: avpacket.c:845
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
#define s(width, name)
Definition: cbs_vp9.c:257
#define FFMIN(a, b)
Definition: common.h:105
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
#define av_clip
Definition: common.h:122
#define av_clipf
Definition: common.h:170
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
static enum AVPixelFormat pix_fmt
static AVFrame * frame
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: encode.c:34
simple arithmetic expression evaluator
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
@ AV_OPT_TYPE_DICT
Definition: opt.h:232
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This codec takes the reordered_opaque field from input AVFrames and returns it in the corresponding f...
Definition: codec.h:171
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:300
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
Definition: codec.h:122
#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:77
#define AV_CODEC_EXPORT_DATA_PRFT
Export encoder Producer Reference Time through packet side data.
Definition: avcodec.h:407
#define AV_CODEC_FLAG_CLOSED_GOP
Definition: avcodec.h:343
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
Definition: avcodec.h:321
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:296
#define AV_CODEC_FLAG_LOOP_FILTER
loop filter.
Definition: avcodec.h:304
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition: avcodec.h:329
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
Definition: avcodec.h:312
@ AV_CODEC_ID_H264
Definition: codec_id.h:76
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:51
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition: avcodec.h:215
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:410
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition: dict.h:70
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:40
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:227
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:57
#define AVERROR(e)
Definition: error.h:43
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:738
@ AV_FRAME_DATA_STEREO3D
Stereoscopic 3d metadata.
Definition: frame.h:63
@ 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:181
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
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:424
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
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
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:253
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
Definition: mem.c:190
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:276
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition: stereo3d.h:167
@ AV_STEREO3D_COLUMNS
Views are packed per column.
Definition: stereo3d.h:141
@ AV_STEREO3D_LINES
Views are packed per line, as if interlaced.
Definition: stereo3d.h:129
@ AV_STEREO3D_2D
Video is not stereoscopic (and metadata has to be there).
Definition: stereo3d.h:55
@ AV_STEREO3D_CHECKERBOARD
Views are packed in a checkerboard-like structure per pixel.
Definition: stereo3d.h:104
@ AV_STEREO3D_TOPBOTTOM
Views are on top of each other.
Definition: stereo3d.h:79
@ AV_STEREO3D_FRAMESEQUENCE
Views are alternated temporally.
Definition: stereo3d.h:92
@ AV_STEREO3D_SIDEBYSIDE
Views are next to each other.
Definition: stereo3d.h:67
#define AV_STRINGIFY(s)
Definition: macros.h:36
int i
Definition: input.c:407
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Definition: utils.c:1084
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:41
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:49
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Definition: internal.h:80
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:83
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
Stereoscopic video.
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: libx264.c:304
static enum AVPixelFormat pix_fmts_10bit[]
Definition: libx264.c:1028
static av_cold int X264_close(AVCodecContext *avctx)
Definition: libx264.c:517
static enum AVPixelFormat pix_fmts_9bit[]
Definition: libx264.c:1023
static const AVOption options[]
Definition: libx264.c:1080
#define PARSE_X264_OPT(name, var)
Definition: libx264.c:600
#define VE
Definition: libx264.c:1079
static av_cold int X264_init(AVCodecContext *avctx)
Definition: libx264.c:606
static av_cold void X264_init_static(AVCodec *codec)
Definition: libx264.c:1067
#define MB_SIZE
Definition: libx264.c:48
static int parse_opts(AVCodecContext *avctx, const char *opt, const char *param)
Definition: libx264.c:537
static const AVCodecDefault x264_defaults[]
Definition: libx264.c:1162
static void X264_log(void *p, int level, const char *fmt, va_list args)
Definition: libx264.c:118
static void reconfig_encoder(AVCodecContext *ctx, const AVFrame *frame)
Definition: libx264.c:204
static enum AVPixelFormat pix_fmts_8bit[]
Definition: libx264.c:1009
static int encode_nals(AVCodecContext *ctx, AVPacket *pkt, const x264_nal_t *nals, int nnal)
Definition: libx264.c:134
#define OFFSET(x)
Definition: libx264.c:1078
static enum AVPixelFormat pix_fmts_all[]
Definition: libx264.c:1035
static int avfmt2_num_planes(int avfmt)
Definition: libx264.c:182
static int convert_pix_fmt(enum AVPixelFormat pix_fmt)
Definition: libx264.c:563
Memory handling functions.
static av_cold void init_static_data(void)
Definition: mv30.c:660
AVOptions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:398
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:552
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:586
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
#define AV_PIX_FMT_NV20
Definition: pixfmt.h:446
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:396
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ 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:89
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
Definition: pixfmt.h:90
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:240
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
@ AV_PIX_FMT_NV16
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:201
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
@ 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:79
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
@ 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:80
@ 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:78
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:380
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:461
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:486
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:515
mfxU16 profile
Definition: qsvenc.c:45
This structure describes the bitrate properties of an encoded bitstream.
Definition: avcodec.h:453
int avg_bitrate
Average bitrate of the stream, in bits per second.
Definition: avcodec.h:477
int buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
Definition: avcodec.h:486
int max_bitrate
Maximum bitrate of the stream, in bits per second.
Definition: avcodec.h:459
Describe the class of an AVClass context structure.
Definition: log.h:67
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:72
main external API structure.
Definition: avcodec.h:536
int trellis
trellis RD quantization
Definition: avcodec.h:1491
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:746
int max_qdiff
maximum quantizer difference between frames
Definition: avcodec.h:1398
int width
picture width / height.
Definition: avcodec.h:709
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:1405
int me_cmp
motion estimation comparison function
Definition: avcodec.h:922
int global_quality
Global quality for codecs which cannot change it per frame.
Definition: avcodec.h:602
attribute_deprecated int coder_type
Definition: avcodec.h:1459
attribute_deprecated int scenechange_threshold
Definition: avcodec.h:1050
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1171
attribute_deprecated int chromaoffset
Definition: avcodec.h:1129
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1150
int me_subpel_quality
subpel ME quality
Definition: avcodec.h:998
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:796
int qmin
minimum quantizer
Definition: avcodec.h:1384
int keyint_min
minimum GOP size
Definition: avcodec.h:1117
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:805
AVRational framerate
Definition: avcodec.h:2075
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:915
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:668
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:826
int level
level
Definition: avcodec.h:1988
int64_t bit_rate
the average bitrate
Definition: avcodec.h:586
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition: avcodec.h:1448
int thread_type
Which multithreading methods to use.
Definition: avcodec.h:1787
int profile
profile
Definition: avcodec.h:1862
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1164
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:731
int refs
number of reference frames
Definition: avcodec.h:1124
int64_t rc_max_rate
maximum bitrate
Definition: avcodec.h:1420
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1777
int qmax
maximum quantizer
Definition: avcodec.h:1391
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1157
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:659
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:616
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:637
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
Definition: avcodec.h:1376
float qblur
amount of qscale smoothing over time (0.0-1.0)
Definition: avcodec.h:1377
int me_range
maximum motion estimation search range in subpel units If 0 then no limit.
Definition: avcodec.h:1007
attribute_deprecated int noise_reduction
Definition: avcodec.h:1054
enum AVCodecID codec_id
Definition: avcodec.h:546
attribute_deprecated int b_frame_strategy
Definition: avcodec.h:810
int extradata_size
Definition: avcodec.h:638
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:841
void * priv_data
Definition: avcodec.h:563
int slices
Number of slices.
Definition: avcodec.h:1187
AVCodec.
Definition: codec.h:197
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
Definition: codec.h:218
const char * name
Name of the codec implementation.
Definition: codec.h:204
int depth
Number of bits in the component.
Definition: pixdesc.h:58
char * key
Definition: dict.h:82
char * value
Definition: dict.h:83
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
Definition: avformat.h:1354
void * priv_data
Format private data.
Definition: avformat.h:1260
Structure to hold side data for an AVFrame.
Definition: frame.h:220
uint8_t * data
Definition: frame.h:222
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:411
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int width
Definition: frame.h:376
int height
Definition: frame.h:376
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:470
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:465
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
int64_t reordered_opaque
reordered opaque 64 bits (generally an integer or a double precision float PTS but can be anything).
Definition: frame.h:485
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:401
AVOption.
Definition: opt.h:248
This structure stores compressed data.
Definition: packet.h:346
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:375
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:368
uint8_t * data
Definition: packet.h:369
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
int num
Numerator.
Definition: rational.h:59
int den
Denominator.
Definition: rational.h:60
Structure describing a single Region Of Interest.
Definition: frame.h:243
uint32_t self_size
Must be set to the size of this data structure (that is, sizeof(AVRegionOfInterest)).
Definition: frame.h:248
AVRational qoffset
Quantisation offset.
Definition: frame.h:285
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:258
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
Definition: stereo3d.h:176
enum AVStereo3DType type
How views are packed within the video.
Definition: stereo3d.h:180
int flags
Additional information about the frame packing.
Definition: stereo3d.h:185
int weightp
Definition: libx264.c:77
int next_reordered_opaque
Definition: libx264.c:108
char * preset
Definition: libx264.c:62
int weightb
Definition: libx264.c:78
int direct_pred
Definition: libx264.c:92
AVDictionary * x264_params
Definition: libx264.c:106
float crf
Definition: libx264.c:69
char * level
Definition: libx264.c:65
float cplxblur
Definition: libx264.c:90
uint8_t * sei
Definition: libx264.c:60
int ssim
Definition: libx264.c:79
x264_t * enc
Definition: libx264.c:58
x264_param_t params
Definition: libx264.c:57
char * deblock
Definition: libx264.c:89
X264Opaque * reordered_opaque
Definition: libx264.c:109
int aud
Definition: libx264.c:87
int b_pyramid
Definition: libx264.c:83
char * profile
Definition: libx264.c:64
int chroma_offset
Definition: libx264.c:102
int slice_max_size
Definition: libx264.c:93
int coder
Definition: libx264.c:99
x264_picture_t pic
Definition: libx264.c:59
float aq_strength
Definition: libx264.c:73
int intra_refresh
Definition: libx264.c:80
int nb_reordered_opaque
Definition: libx264.c:108
int mixed_refs
Definition: libx264.c:84
int fastfirstpass
Definition: libx264.c:66
int dct8x8
Definition: libx264.c:85
char * tune
Definition: libx264.c:63
char * partitions
Definition: libx264.c:91
char * x264opts
Definition: libx264.c:68
int avcintra_class
Definition: libx264.c:96
char * stats
Definition: libx264.c:94
int sei_size
Definition: libx264.c:61
int psy
Definition: libx264.c:75
int nal_hrd
Definition: libx264.c:95
int rc_lookahead
Definition: libx264.c:76
int bluray_compat
Definition: libx264.c:81
int motion_est
Definition: libx264.c:97
int aq_mode
Definition: libx264.c:72
int forced_idr
Definition: libx264.c:98
char * wpredp
Definition: libx264.c:67
int noise_reduction
Definition: libx264.c:104
int b_frame_strategy
Definition: libx264.c:101
int scenechange_threshold
Definition: libx264.c:103
int mbtree
Definition: libx264.c:88
int b_bias
Definition: libx264.c:82
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:115
int cqp
Definition: libx264.c:71
float crf_max
Definition: libx264.c:70
char * psy_rd
Definition: libx264.c:74
int fast_pskip
Definition: libx264.c:86
int a53_cc
Definition: libx264.c:100
int64_t wallclock
Definition: libx264.c:52
int64_t reordered_opaque
Definition: libx264.c:51
uint8_t level
Definition: svq3.c:206
#define av_free(p)
#define av_freep(p)
#define av_malloc(s)
#define av_log(a,...)
static void dct8x8(int16_t *coef, int bit_depth)
Definition: h264dsp.c:165
int level_idc
Definition: h264_levels.c:25
AVPacket * pkt
Definition: movenc.c:59
AVFormatContext * ctx
Definition: movenc.c:48
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:39
int size
preset
Definition: vf_curves.c:47
if(ret< 0)
Definition: vf_mcdeint.c:282
static void stats(AVPacket *const *in, int n_in, unsigned *_max, unsigned *_sum)