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"
28 #include "libavutil/mem.h"
29 #include "libavutil/pixdesc.h"
30 #include "libavutil/stereo3d.h"
31 #include "libavutil/time.h"
32 #include "libavutil/intreadwrite.h"
33 #include "libavutil/video_hint.h"
34 #include "avcodec.h"
35 #include "codec_internal.h"
36 #include "encode.h"
37 #include "internal.h"
38 #include "packet_internal.h"
39 #include "atsc_a53.h"
40 #include "sei.h"
41 
42 #include <x264.h>
43 #include <float.h>
44 #include <math.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 
49 // from x264.h, for quant_offsets, Macroblocks are 16x16
50 // blocks of pixels (with respect to the luma plane)
51 #define MB_SIZE 16
52 #define MB_LSIZE 4
53 #define MB_FLOOR(x) ((x) >> (MB_LSIZE))
54 #define MB_CEIL(x) MB_FLOOR((x) + (MB_SIZE - 1))
55 
56 typedef struct X264Opaque {
57 #if FF_API_REORDERED_OPAQUE
58  int64_t reordered_opaque;
59 #endif
60  int64_t wallclock;
61  int64_t duration;
62 
63  void *frame_opaque;
65 } X264Opaque;
66 
67 typedef struct X264Context {
68  AVClass *class;
69  x264_param_t params;
70  x264_t *enc;
71  x264_picture_t pic;
72  uint8_t *sei;
73  int sei_size;
74  char *preset;
75  char *tune;
76  const char *profile;
77  char *profile_opt;
78  char *level;
80  char *wpredp;
81  char *x264opts;
82  float crf;
83  float crf_max;
84  int cqp;
85  int aq_mode;
86  float aq_strength;
87  char *psy_rd;
88  int psy;
90  int weightp;
91  int weightb;
92  int ssim;
95  int b_bias;
96  int b_pyramid;
98  int dct8x8;
100  int aud;
101  int mbtree;
102  char *deblock;
103  float cplxblur;
104  char *partitions;
107  char *stats;
108  int nal_hrd;
112  int coder;
113  int a53_cc;
118  int udu_sei;
119 
121 
124 
125  /**
126  * If the encoder does not support ROI then warn the first time we
127  * encounter a frame with ROI side data.
128  */
130 
131  int mb_info;
132 } X264Context;
133 
134 static void X264_log(void *p, int level, const char *fmt, va_list args)
135 {
136  static const int level_map[] = {
137  [X264_LOG_ERROR] = AV_LOG_ERROR,
138  [X264_LOG_WARNING] = AV_LOG_WARNING,
139  [X264_LOG_INFO] = AV_LOG_INFO,
140  [X264_LOG_DEBUG] = AV_LOG_DEBUG
141  };
142 
143  if (level < 0 || level > X264_LOG_DEBUG)
144  return;
145 
146  av_vlog(p, level_map[level], fmt, args);
147 }
148 
149 static void opaque_uninit(X264Opaque *o)
150 {
152  memset(o, 0, sizeof(*o));
153 }
154 
156  const x264_nal_t *nals, int nnal)
157 {
158  X264Context *x4 = ctx->priv_data;
159  uint8_t *p;
160  uint64_t size = FFMAX(x4->sei_size, 0);
161  int ret;
162 
163  if (!nnal)
164  return 0;
165 
166  for (int i = 0; i < nnal; i++) {
167  size += nals[i].i_payload;
168  /* ff_get_encode_buffer() accepts an int64_t and
169  * so we need to make sure that no overflow happens before
170  * that. With 32bit ints this is automatically true. */
171 #if INT_MAX > INT64_MAX / INT_MAX - 1
172  if ((int64_t)size < 0)
173  return AVERROR(ERANGE);
174 #endif
175  }
176 
177  if ((ret = ff_get_encode_buffer(ctx, pkt, size, 0)) < 0)
178  return ret;
179 
180  p = pkt->data;
181 
182  /* Write the SEI as part of the first frame. */
183  if (x4->sei_size > 0) {
184  memcpy(p, x4->sei, x4->sei_size);
185  p += x4->sei_size;
186  size -= x4->sei_size;
187  /* Keep the value around in case of flush */
188  x4->sei_size = -x4->sei_size;
189  }
190 
191  /* x264 guarantees the payloads of the NALs
192  * to be sequential in memory. */
193  memcpy(p, nals[0].p_payload, size);
194 
195  return 1;
196 }
197 
199 {
200  X264Context *x4 = ctx->priv_data;
201  AVFrameSideData *side_data;
202 
203 
204  if (x4->avcintra_class < 0) {
205  if (x4->params.b_interlaced && x4->params.b_tff != !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST)) {
206 
207  x4->params.b_tff = !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST);
208  x264_encoder_reconfig(x4->enc, &x4->params);
209  }
210  if (x4->params.vui.i_sar_height*ctx->sample_aspect_ratio.num != ctx->sample_aspect_ratio.den * x4->params.vui.i_sar_width) {
211  x4->params.vui.i_sar_height = ctx->sample_aspect_ratio.den;
212  x4->params.vui.i_sar_width = ctx->sample_aspect_ratio.num;
213  x264_encoder_reconfig(x4->enc, &x4->params);
214  }
215 
216  if (x4->params.rc.i_vbv_buffer_size != ctx->rc_buffer_size / 1000 ||
217  x4->params.rc.i_vbv_max_bitrate != ctx->rc_max_rate / 1000) {
218  x4->params.rc.i_vbv_buffer_size = ctx->rc_buffer_size / 1000;
219  x4->params.rc.i_vbv_max_bitrate = ctx->rc_max_rate / 1000;
220  x264_encoder_reconfig(x4->enc, &x4->params);
221  }
222 
223  if (x4->params.rc.i_rc_method == X264_RC_ABR &&
224  x4->params.rc.i_bitrate != ctx->bit_rate / 1000) {
225  x4->params.rc.i_bitrate = ctx->bit_rate / 1000;
226  x264_encoder_reconfig(x4->enc, &x4->params);
227  }
228 
229  if (x4->crf >= 0 &&
230  x4->params.rc.i_rc_method == X264_RC_CRF &&
231  x4->params.rc.f_rf_constant != x4->crf) {
232  x4->params.rc.f_rf_constant = x4->crf;
233  x264_encoder_reconfig(x4->enc, &x4->params);
234  }
235 
236  if (x4->params.rc.i_rc_method == X264_RC_CQP &&
237  x4->cqp >= 0 &&
238  x4->params.rc.i_qp_constant != x4->cqp) {
239  x4->params.rc.i_qp_constant = x4->cqp;
240  x264_encoder_reconfig(x4->enc, &x4->params);
241  }
242 
243  if (x4->crf_max >= 0 &&
244  x4->params.rc.f_rf_constant_max != x4->crf_max) {
245  x4->params.rc.f_rf_constant_max = x4->crf_max;
246  x264_encoder_reconfig(x4->enc, &x4->params);
247  }
248  }
249 
251  if (side_data) {
252  AVStereo3D *stereo = (AVStereo3D *)side_data->data;
253  int fpa_type;
254 
255  switch (stereo->type) {
257  fpa_type = 0;
258  break;
259  case AV_STEREO3D_COLUMNS:
260  fpa_type = 1;
261  break;
262  case AV_STEREO3D_LINES:
263  fpa_type = 2;
264  break;
266  fpa_type = 3;
267  break;
269  fpa_type = 4;
270  break;
272  fpa_type = 5;
273  break;
274 #if X264_BUILD >= 145
275  case AV_STEREO3D_2D:
276  fpa_type = 6;
277  break;
278 #endif
279  default:
280  fpa_type = -1;
281  break;
282  }
283 
284  /* Inverted mode is not supported by x264 */
285  if (stereo->flags & AV_STEREO3D_FLAG_INVERT) {
287  "Ignoring unsupported inverted stereo value %d\n", fpa_type);
288  fpa_type = -1;
289  }
290 
291  if (fpa_type != x4->params.i_frame_packing) {
292  x4->params.i_frame_packing = fpa_type;
293  x264_encoder_reconfig(x4->enc, &x4->params);
294  }
295  }
296 }
297 
298 static void free_picture(x264_picture_t *pic)
299 {
300  for (int i = 0; i < pic->extra_sei.num_payloads; i++)
301  av_free(pic->extra_sei.payloads[i].payload);
302  av_freep(&pic->extra_sei.payloads);
303  av_freep(&pic->prop.quant_offsets);
304  av_freep(&pic->prop.mb_info);
305  pic->extra_sei.num_payloads = 0;
306 }
307 
308 static enum AVPixelFormat csp_to_pixfmt(int csp)
309 {
310  switch (csp) {
311 #ifdef X264_CSP_I400
312  case X264_CSP_I400: return AV_PIX_FMT_GRAY8;
313  case X264_CSP_I400 | X264_CSP_HIGH_DEPTH: return AV_PIX_FMT_GRAY10;
314 #endif
315  case X264_CSP_I420: return AV_PIX_FMT_YUV420P;
316  case X264_CSP_I420 | X264_CSP_HIGH_DEPTH: return AV_PIX_FMT_YUV420P10;
317  case X264_CSP_I422: return AV_PIX_FMT_YUV422P;
318  case X264_CSP_I422 | X264_CSP_HIGH_DEPTH: return AV_PIX_FMT_YUV422P10;
319  case X264_CSP_I444: return AV_PIX_FMT_YUV444P;
320  case X264_CSP_I444 | X264_CSP_HIGH_DEPTH: return AV_PIX_FMT_YUV444P10;
321  case X264_CSP_NV12: return AV_PIX_FMT_NV12;
322 #ifdef X264_CSP_NV21
323  case X264_CSP_NV21: return AV_PIX_FMT_NV21;
324 #endif
325  case X264_CSP_NV16: return AV_PIX_FMT_NV16;
326  };
327  return AV_PIX_FMT_NONE;
328 }
329 
331  int *min_x,
332  int *max_x,
333  int *min_y,
334  int *max_y)
335 {
336  *min_y = MB_FLOOR(rect->y);
337  *max_y = MB_CEIL(rect->y + rect->height);
338  *min_x = MB_FLOOR(rect->x);
339  *max_x = MB_CEIL(rect->x + rect->width);
340 }
341 
343  int *min_x,
344  int *max_x,
345  int *min_y,
346  int *max_y)
347 {
348  *min_y = MB_CEIL(rect->y);
349  *max_y = MB_FLOOR(rect->y + rect->height);
350  *min_x = MB_CEIL(rect->x);
351  *max_x = MB_FLOOR(rect->x + rect->width);
352 }
353 
354 static int setup_mb_info(AVCodecContext *ctx, x264_picture_t *pic,
355  const AVFrame *frame,
356  const AVVideoHint *info)
357 {
358  int mb_width = (frame->width + MB_SIZE - 1) / MB_SIZE;
359  int mb_height = (frame->height + MB_SIZE - 1) / MB_SIZE;
360 
361  const AVVideoRect *mbinfo_rects;
362  int nb_rects;
363  uint8_t *mbinfo;
364 
365  mbinfo_rects = (const AVVideoRect *)av_video_hint_rects(info);
366  nb_rects = info->nb_rects;
367 
368  mbinfo = av_calloc(mb_width * mb_height, sizeof(*mbinfo));
369  if (!mbinfo)
370  return AVERROR(ENOMEM);
371 
372 #define COMPUTE_MBINFO(mbinfo_filler_, mbinfo_marker_, compute_coords_fn_) \
373  memset(mbinfo, mbinfo_filler_, sizeof(*mbinfo) * mb_width * mb_height); \
374  \
375  for (int i = 0; i < nb_rects; i++) { \
376  int min_x, max_x, min_y, max_y; \
377  \
378  compute_coords_fn_(mbinfo_rects, &min_x, &max_x, &min_y, &max_y); \
379  for (int mb_y = min_y; mb_y < max_y; ++mb_y) { \
380  memset(mbinfo + mb_y * mb_width + min_x, mbinfo_marker_, max_x - min_x); \
381  } \
382  \
383  mbinfo_rects++; \
384  } \
385 
386  if (info->type == AV_VIDEO_HINT_TYPE_CHANGED) {
387  COMPUTE_MBINFO(X264_MBINFO_CONSTANT, 0, mbinfo_compute_changed_coords);
388  } else /* if (info->type == AV_VIDEO_HINT_TYPE_CHANGED) */ {
389  COMPUTE_MBINFO(0, X264_MBINFO_CONSTANT, mbinfo_compute_constant_coords);
390  }
391 
392  pic->prop.mb_info = mbinfo;
393  pic->prop.mb_info_free = av_free;
394 
395  return 0;
396 }
397 
398 static int setup_roi(AVCodecContext *ctx, x264_picture_t *pic, int bit_depth,
399  const AVFrame *frame, const uint8_t *data, size_t size)
400 {
401  X264Context *x4 = ctx->priv_data;
402 
403  int mbx = (frame->width + MB_SIZE - 1) / MB_SIZE;
404  int mby = (frame->height + MB_SIZE - 1) / MB_SIZE;
405  int qp_range = 51 + 6 * (bit_depth - 8);
406  int nb_rois;
407  const AVRegionOfInterest *roi;
408  uint32_t roi_size;
409  float *qoffsets;
410 
411  if (x4->params.rc.i_aq_mode == X264_AQ_NONE) {
412  if (!x4->roi_warned) {
413  x4->roi_warned = 1;
414  av_log(ctx, AV_LOG_WARNING, "Adaptive quantization must be enabled to use ROI encoding, skipping ROI.\n");
415  }
416  return 0;
417  } else if (frame->flags & AV_FRAME_FLAG_INTERLACED) {
418  if (!x4->roi_warned) {
419  x4->roi_warned = 1;
420  av_log(ctx, AV_LOG_WARNING, "interlaced_frame not supported for ROI encoding yet, skipping ROI.\n");
421  }
422  return 0;
423  }
424 
425  roi = (const AVRegionOfInterest*)data;
426  roi_size = roi->self_size;
427  if (!roi_size || size % roi_size != 0) {
428  av_log(ctx, AV_LOG_ERROR, "Invalid AVRegionOfInterest.self_size.\n");
429  return AVERROR(EINVAL);
430  }
431  nb_rois = size / roi_size;
432 
433  qoffsets = av_calloc(mbx * mby, sizeof(*qoffsets));
434  if (!qoffsets)
435  return AVERROR(ENOMEM);
436 
437  // This list must be iterated in reverse because the first
438  // region in the list applies when regions overlap.
439  for (int i = nb_rois - 1; i >= 0; i--) {
440  int startx, endx, starty, endy;
441  float qoffset;
442 
443  roi = (const AVRegionOfInterest*)(data + roi_size * i);
444 
445  starty = FFMIN(mby, roi->top / MB_SIZE);
446  endy = FFMIN(mby, (roi->bottom + MB_SIZE - 1)/ MB_SIZE);
447  startx = FFMIN(mbx, roi->left / MB_SIZE);
448  endx = FFMIN(mbx, (roi->right + MB_SIZE - 1)/ MB_SIZE);
449 
450  if (roi->qoffset.den == 0) {
451  av_free(qoffsets);
452  av_log(ctx, AV_LOG_ERROR, "AVRegionOfInterest.qoffset.den must not be zero.\n");
453  return AVERROR(EINVAL);
454  }
455  qoffset = roi->qoffset.num * 1.0f / roi->qoffset.den;
456  qoffset = av_clipf(qoffset * qp_range, -qp_range, +qp_range);
457 
458  for (int y = starty; y < endy; y++) {
459  for (int x = startx; x < endx; x++) {
460  qoffsets[x + y*mbx] = qoffset;
461  }
462  }
463  }
464 
465  pic->prop.quant_offsets = qoffsets;
466  pic->prop.quant_offsets_free = av_free;
467 
468  return 0;
469 }
470 
472  x264_picture_t **ppic)
473 {
474  X264Context *x4 = ctx->priv_data;
476  x264_picture_t *pic = &x4->pic;
477  x264_sei_t *sei = &pic->extra_sei;
478  unsigned int sei_data_size = 0;
479  int64_t wallclock = 0;
480  int bit_depth, ret;
481  AVFrameSideData *sd;
482  AVFrameSideData *mbinfo_sd;
483 
484  *ppic = NULL;
485  if (!frame)
486  return 0;
487 
488  x264_picture_init(pic);
489  pic->img.i_csp = x4->params.i_csp;
490 #if X264_BUILD >= 153
491  bit_depth = x4->params.i_bitdepth;
492 #else
493  bit_depth = x264_bit_depth;
494 #endif
495  if (bit_depth > 8)
496  pic->img.i_csp |= X264_CSP_HIGH_DEPTH;
497  pic->img.i_plane = av_pix_fmt_count_planes(ctx->pix_fmt);
498 
499  for (int i = 0; i < pic->img.i_plane; i++) {
500  pic->img.plane[i] = frame->data[i];
501  pic->img.i_stride[i] = frame->linesize[i];
502  }
503 
504  pic->i_pts = frame->pts;
505 
506  opaque_uninit(opaque);
507 
509  opaque->frame_opaque = frame->opaque;
510  ret = av_buffer_replace(&opaque->frame_opaque_ref, frame->opaque_ref);
511  if (ret < 0)
512  goto fail;
513  }
514 
515 #if FF_API_REORDERED_OPAQUE
517  opaque->reordered_opaque = frame->reordered_opaque;
519 #endif
520  opaque->duration = frame->duration;
521  opaque->wallclock = wallclock;
522  if (ctx->export_side_data & AV_CODEC_EXPORT_DATA_PRFT)
523  opaque->wallclock = av_gettime();
524 
525  pic->opaque = opaque;
526 
527  x4->next_reordered_opaque++;
529 
530  switch (frame->pict_type) {
531  case AV_PICTURE_TYPE_I:
532  pic->i_type = x4->forced_idr > 0 ? X264_TYPE_IDR : X264_TYPE_KEYFRAME;
533  break;
534  case AV_PICTURE_TYPE_P:
535  pic->i_type = X264_TYPE_P;
536  break;
537  case AV_PICTURE_TYPE_B:
538  pic->i_type = X264_TYPE_B;
539  break;
540  default:
541  pic->i_type = X264_TYPE_AUTO;
542  break;
543  }
545 
546  if (x4->a53_cc) {
547  void *sei_data;
548  size_t sei_size;
549 
550  ret = ff_alloc_a53_sei(frame, 0, &sei_data, &sei_size);
551  if (ret < 0)
552  goto fail;
553 
554  if (sei_data) {
555  sei->payloads = av_mallocz(sizeof(sei->payloads[0]));
556  if (!sei->payloads) {
557  av_free(sei_data);
558  ret = AVERROR(ENOMEM);
559  goto fail;
560  }
561 
562  sei->sei_free = av_free;
563 
564  sei->payloads[0].payload_size = sei_size;
565  sei->payloads[0].payload = sei_data;
566  sei->payloads[0].payload_type = SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35;
567  sei->num_payloads = 1;
568  }
569  }
570 
572  if (sd) {
573  ret = setup_roi(ctx, pic, bit_depth, frame, sd->data, sd->size);
574  if (ret < 0)
575  goto fail;
576  }
577 
579  if (mbinfo_sd) {
580  int ret = setup_mb_info(ctx, pic, frame, (const AVVideoHint *)mbinfo_sd->data);
581  if (ret < 0) {
582  /* No need to fail here, this is not fatal. We just proceed with no
583  * mb_info and log a message */
584 
585  av_log(ctx, AV_LOG_WARNING, "setup_mb_info failed with error: %s\n", av_err2str(ret));
586  }
587  }
588 
589  if (x4->udu_sei) {
590  for (int j = 0; j < frame->nb_side_data; j++) {
591  AVFrameSideData *side_data = frame->side_data[j];
592  void *tmp;
593  x264_sei_payload_t *sei_payload;
594  if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
595  continue;
596  tmp = av_fast_realloc(sei->payloads, &sei_data_size, (sei->num_payloads + 1) * sizeof(*sei_payload));
597  if (!tmp) {
598  ret = AVERROR(ENOMEM);
599  goto fail;
600  }
601  sei->payloads = tmp;
602  sei->sei_free = av_free;
603  sei_payload = &sei->payloads[sei->num_payloads];
604  sei_payload->payload = av_memdup(side_data->data, side_data->size);
605  if (!sei_payload->payload) {
606  ret = AVERROR(ENOMEM);
607  goto fail;
608  }
609  sei_payload->payload_size = side_data->size;
610  sei_payload->payload_type = SEI_TYPE_USER_DATA_UNREGISTERED;
611  sei->num_payloads++;
612  }
613  }
614 
615  *ppic = pic;
616  return 0;
617 
618 fail:
619  free_picture(pic);
620  *ppic = NULL;
621  return ret;
622 }
623 
625  int *got_packet)
626 {
627  X264Context *x4 = ctx->priv_data;
628  x264_nal_t *nal;
629  int nnal, ret;
630  x264_picture_t pic_out = {0}, *pic_in;
631  int pict_type;
632  int64_t wallclock = 0;
633  X264Opaque *out_opaque;
634 
635  ret = setup_frame(ctx, frame, &pic_in);
636  if (ret < 0)
637  return ret;
638 
639  do {
640  if (x264_encoder_encode(x4->enc, &nal, &nnal, pic_in, &pic_out) < 0)
641  return AVERROR_EXTERNAL;
642 
643  if (nnal && (ctx->flags & AV_CODEC_FLAG_RECON_FRAME)) {
644  AVCodecInternal *avci = ctx->internal;
645 
647 
648  avci->recon_frame->format = csp_to_pixfmt(pic_out.img.i_csp);
649  if (avci->recon_frame->format == AV_PIX_FMT_NONE) {
651  "Unhandled reconstructed frame colorspace: %d\n",
652  pic_out.img.i_csp);
653  return AVERROR(ENOSYS);
654  }
655 
656  avci->recon_frame->width = ctx->width;
657  avci->recon_frame->height = ctx->height;
658  for (int i = 0; i < pic_out.img.i_plane; i++) {
659  avci->recon_frame->data[i] = pic_out.img.plane[i];
660  avci->recon_frame->linesize[i] = pic_out.img.i_stride[i];
661  }
662 
664  if (ret < 0) {
666  return ret;
667  }
668  }
669 
670  ret = encode_nals(ctx, pkt, nal, nnal);
671  if (ret < 0)
672  return ret;
673  } while (!ret && !frame && x264_encoder_delayed_frames(x4->enc));
674 
675  if (!ret)
676  return 0;
677 
678  pkt->pts = pic_out.i_pts;
679  pkt->dts = pic_out.i_dts;
680 
681  out_opaque = pic_out.opaque;
682  if (out_opaque >= x4->reordered_opaque &&
683  out_opaque < &x4->reordered_opaque[x4->nb_reordered_opaque]) {
684 #if FF_API_REORDERED_OPAQUE
686  ctx->reordered_opaque = out_opaque->reordered_opaque;
688 #endif
689  wallclock = out_opaque->wallclock;
690  pkt->duration = out_opaque->duration;
691 
693  pkt->opaque = out_opaque->frame_opaque;
694  pkt->opaque_ref = out_opaque->frame_opaque_ref;
695  out_opaque->frame_opaque_ref = NULL;
696  }
697 
698  opaque_uninit(out_opaque);
699  } else {
700  // Unexpected opaque pointer on picture output
701  av_log(ctx, AV_LOG_ERROR, "Unexpected opaque pointer; "
702  "this is a bug, please report it.\n");
703 #if FF_API_REORDERED_OPAQUE
705  ctx->reordered_opaque = 0;
707 #endif
708  }
709 
710  switch (pic_out.i_type) {
711  case X264_TYPE_IDR:
712  case X264_TYPE_I:
713  pict_type = AV_PICTURE_TYPE_I;
714  break;
715  case X264_TYPE_P:
716  pict_type = AV_PICTURE_TYPE_P;
717  break;
718  case X264_TYPE_B:
719  case X264_TYPE_BREF:
720  pict_type = AV_PICTURE_TYPE_B;
721  break;
722  default:
723  av_log(ctx, AV_LOG_ERROR, "Unknown picture type encountered.\n");
724  return AVERROR_EXTERNAL;
725  }
726 
727  pkt->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe;
728  if (ret) {
729  ff_side_data_set_encoder_stats(pkt, (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA, NULL, 0, pict_type);
730  if (wallclock)
731  ff_side_data_set_prft(pkt, wallclock);
732  }
733 
734  *got_packet = ret;
735  return 0;
736 }
737 
738 static void X264_flush(AVCodecContext *avctx)
739 {
740  X264Context *x4 = avctx->priv_data;
741  x264_nal_t *nal;
742  int nnal, ret;
743  x264_picture_t pic_out = {0};
744 
745  do {
746  ret = x264_encoder_encode(x4->enc, &nal, &nnal, NULL, &pic_out);
747  } while (ret > 0 && x264_encoder_delayed_frames(x4->enc));
748 
749  for (int i = 0; i < x4->nb_reordered_opaque; i++)
751 
752  if (x4->sei_size < 0)
753  x4->sei_size = -x4->sei_size;
754 }
755 
757 {
758  X264Context *x4 = avctx->priv_data;
759 
760  av_freep(&x4->sei);
761 
762  for (int i = 0; i < x4->nb_reordered_opaque; i++)
765 
766 #if X264_BUILD >= 161
767  x264_param_cleanup(&x4->params);
768 #endif
769 
770  if (x4->enc) {
771  x264_encoder_close(x4->enc);
772  x4->enc = NULL;
773  }
774 
775  return 0;
776 }
777 
778 static int parse_opts(AVCodecContext *avctx, const char *opt, const char *param)
779 {
780  X264Context *x4 = avctx->priv_data;
781  int ret;
782 
783  if ((ret = x264_param_parse(&x4->params, opt, param)) < 0) {
784  if (ret == X264_PARAM_BAD_NAME) {
785  av_log(avctx, AV_LOG_ERROR,
786  "bad option '%s': '%s'\n", opt, param);
787  ret = AVERROR(EINVAL);
788 #if X264_BUILD >= 161
789  } else if (ret == X264_PARAM_ALLOC_FAILED) {
790  av_log(avctx, AV_LOG_ERROR,
791  "out of memory parsing option '%s': '%s'\n", opt, param);
792  ret = AVERROR(ENOMEM);
793 #endif
794  } else {
795  av_log(avctx, AV_LOG_ERROR,
796  "bad value for '%s': '%s'\n", opt, param);
797  ret = AVERROR(EINVAL);
798  }
799  }
800 
801  return ret;
802 }
803 
805 {
806  switch (pix_fmt) {
807  case AV_PIX_FMT_YUV420P:
808  case AV_PIX_FMT_YUVJ420P:
809  case AV_PIX_FMT_YUV420P9:
810  case AV_PIX_FMT_YUV420P10: return X264_CSP_I420;
811  case AV_PIX_FMT_YUV422P:
812  case AV_PIX_FMT_YUVJ422P:
813  case AV_PIX_FMT_YUV422P10: return X264_CSP_I422;
814  case AV_PIX_FMT_YUV444P:
815  case AV_PIX_FMT_YUVJ444P:
816  case AV_PIX_FMT_YUV444P9:
817  case AV_PIX_FMT_YUV444P10: return X264_CSP_I444;
818  case AV_PIX_FMT_BGR0:
819  return X264_CSP_BGRA;
820  case AV_PIX_FMT_BGR24:
821  return X264_CSP_BGR;
822 
823  case AV_PIX_FMT_RGB24:
824  return X264_CSP_RGB;
825  case AV_PIX_FMT_NV12: return X264_CSP_NV12;
826  case AV_PIX_FMT_NV16:
827  case AV_PIX_FMT_NV20: return X264_CSP_NV16;
828 #ifdef X264_CSP_NV21
829  case AV_PIX_FMT_NV21: return X264_CSP_NV21;
830 #endif
831 #ifdef X264_CSP_I400
832  case AV_PIX_FMT_GRAY8:
833  case AV_PIX_FMT_GRAY10: return X264_CSP_I400;
834 #endif
835  };
836  return 0;
837 }
838 
839 #define PARSE_X264_OPT(name, var)\
840  if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
841  av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
842  return AVERROR(EINVAL);\
843  }
844 
845 static av_cold int X264_init(AVCodecContext *avctx)
846 {
847  X264Context *x4 = avctx->priv_data;
848  AVCPBProperties *cpb_props;
849  int sw,sh;
850  int ret;
851 
852  if (avctx->global_quality > 0)
853  av_log(avctx, AV_LOG_WARNING, "-qscale is ignored, -crf is recommended.\n");
854 
855 #if CONFIG_LIBX262_ENCODER
856  if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
857  x4->params.b_mpeg2 = 1;
858  x264_param_default_mpeg2(&x4->params);
859  } else
860 #endif
861  x264_param_default(&x4->params);
862 
863  x4->params.b_deblocking_filter = avctx->flags & AV_CODEC_FLAG_LOOP_FILTER;
864 
865  if (x4->preset || x4->tune)
866  if (x264_param_default_preset(&x4->params, x4->preset, x4->tune) < 0) {
867  int i;
868  av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", x4->preset, x4->tune);
869  av_log(avctx, AV_LOG_INFO, "Possible presets:");
870  for (i = 0; x264_preset_names[i]; i++)
871  av_log(avctx, AV_LOG_INFO, " %s", x264_preset_names[i]);
872  av_log(avctx, AV_LOG_INFO, "\n");
873  av_log(avctx, AV_LOG_INFO, "Possible tunes:");
874  for (i = 0; x264_tune_names[i]; i++)
875  av_log(avctx, AV_LOG_INFO, " %s", x264_tune_names[i]);
876  av_log(avctx, AV_LOG_INFO, "\n");
877  return AVERROR(EINVAL);
878  }
879 
880  if (avctx->level > 0)
881  x4->params.i_level_idc = avctx->level;
882 
883  x4->params.pf_log = X264_log;
884  x4->params.p_log_private = avctx;
885  x4->params.i_log_level = X264_LOG_DEBUG;
886  x4->params.i_csp = convert_pix_fmt(avctx->pix_fmt);
887 #if X264_BUILD >= 153
888  x4->params.i_bitdepth = av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth;
889 #endif
890 
891  PARSE_X264_OPT("weightp", wpredp);
892 
893  if (avctx->bit_rate) {
894  if (avctx->bit_rate / 1000 > INT_MAX || avctx->rc_max_rate / 1000 > INT_MAX) {
895  av_log(avctx, AV_LOG_ERROR, "bit_rate and rc_max_rate > %d000 not supported by libx264\n", INT_MAX);
896  return AVERROR(EINVAL);
897  }
898  x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
899  x4->params.rc.i_rc_method = X264_RC_ABR;
900  }
901  x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
902  x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
903  x4->params.rc.b_stat_write = avctx->flags & AV_CODEC_FLAG_PASS1;
904  if (avctx->flags & AV_CODEC_FLAG_PASS2) {
905  x4->params.rc.b_stat_read = 1;
906  } else {
907  if (x4->crf >= 0) {
908  x4->params.rc.i_rc_method = X264_RC_CRF;
909  x4->params.rc.f_rf_constant = x4->crf;
910  } else if (x4->cqp >= 0) {
911  x4->params.rc.i_rc_method = X264_RC_CQP;
912  x4->params.rc.i_qp_constant = x4->cqp;
913  }
914 
915  if (x4->crf_max >= 0)
916  x4->params.rc.f_rf_constant_max = x4->crf_max;
917  }
918 
919  if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy > 0 &&
920  (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
921  x4->params.rc.f_vbv_buffer_init =
923  }
924 
925  PARSE_X264_OPT("level", level);
926 
927  if (avctx->i_quant_factor > 0)
928  x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor);
929  if (avctx->b_quant_factor > 0)
930  x4->params.rc.f_pb_factor = avctx->b_quant_factor;
931 
932  if (x4->chroma_offset)
933  x4->params.analyse.i_chroma_qp_offset = x4->chroma_offset;
934 
935  if (avctx->gop_size >= 0)
936  x4->params.i_keyint_max = avctx->gop_size;
937  if (avctx->max_b_frames >= 0)
938  x4->params.i_bframe = avctx->max_b_frames;
939 
940  if (x4->scenechange_threshold >= 0)
941  x4->params.i_scenecut_threshold = x4->scenechange_threshold;
942 
943  if (avctx->qmin >= 0)
944  x4->params.rc.i_qp_min = avctx->qmin;
945  if (avctx->qmax >= 0)
946  x4->params.rc.i_qp_max = avctx->qmax;
947  if (avctx->max_qdiff >= 0)
948  x4->params.rc.i_qp_step = avctx->max_qdiff;
949  if (avctx->qblur >= 0)
950  x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */
951  if (avctx->qcompress >= 0)
952  x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
953  if (avctx->refs >= 0)
954  x4->params.i_frame_reference = avctx->refs;
955  else if (x4->params.i_level_idc > 0) {
956  int i;
957  int mbn = AV_CEIL_RSHIFT(avctx->width, 4) * AV_CEIL_RSHIFT(avctx->height, 4);
958  int scale = X264_BUILD < 129 ? 384 : 1;
959 
960  for (i = 0; i<x264_levels[i].level_idc; i++)
961  if (x264_levels[i].level_idc == x4->params.i_level_idc)
962  x4->params.i_frame_reference = av_clip(x264_levels[i].dpb / mbn / scale, 1, x4->params.i_frame_reference);
963  }
964 
965  if (avctx->trellis >= 0)
966  x4->params.analyse.i_trellis = avctx->trellis;
967  if (avctx->me_range >= 0)
968  x4->params.analyse.i_me_range = avctx->me_range;
969  if (x4->noise_reduction >= 0)
970  x4->params.analyse.i_noise_reduction = x4->noise_reduction;
971  if (avctx->me_subpel_quality >= 0)
972  x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
973  if (avctx->keyint_min >= 0)
974  x4->params.i_keyint_min = avctx->keyint_min;
975  if (avctx->me_cmp >= 0)
976  x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
977 
978  if (x4->aq_mode >= 0)
979  x4->params.rc.i_aq_mode = x4->aq_mode;
980  if (x4->aq_strength >= 0)
981  x4->params.rc.f_aq_strength = x4->aq_strength;
982  PARSE_X264_OPT("psy-rd", psy_rd);
983  PARSE_X264_OPT("deblock", deblock);
984  PARSE_X264_OPT("partitions", partitions);
985  PARSE_X264_OPT("stats", stats);
986  if (x4->psy >= 0)
987  x4->params.analyse.b_psy = x4->psy;
988  if (x4->rc_lookahead >= 0)
989  x4->params.rc.i_lookahead = x4->rc_lookahead;
990  if (x4->weightp >= 0)
991  x4->params.analyse.i_weighted_pred = x4->weightp;
992  if (x4->weightb >= 0)
993  x4->params.analyse.b_weighted_bipred = x4->weightb;
994  if (x4->cplxblur >= 0)
995  x4->params.rc.f_complexity_blur = x4->cplxblur;
996 
997  if (x4->ssim >= 0)
998  x4->params.analyse.b_ssim = x4->ssim;
999  if (x4->intra_refresh >= 0)
1000  x4->params.b_intra_refresh = x4->intra_refresh;
1001  if (x4->bluray_compat >= 0) {
1002  x4->params.b_bluray_compat = x4->bluray_compat;
1003  x4->params.b_vfr_input = 0;
1004  }
1005  if (x4->avcintra_class >= 0)
1006 #if X264_BUILD >= 142
1007  x4->params.i_avcintra_class = x4->avcintra_class;
1008 #else
1009  av_log(avctx, AV_LOG_ERROR,
1010  "x264 too old for AVC Intra, at least version 142 needed\n");
1011 #endif
1012 
1013  if (x4->avcintra_class > 200) {
1014 #if X264_BUILD < 164
1015  av_log(avctx, AV_LOG_ERROR,
1016  "x264 too old for AVC Intra 300/480, at least version 164 needed\n");
1017  return AVERROR(EINVAL);
1018 #else
1019  /* AVC-Intra 300/480 only supported by Sony XAVC flavor */
1020  x4->params.i_avcintra_flavor = X264_AVCINTRA_FLAVOR_SONY;
1021 #endif
1022  }
1023 
1024  if (x4->b_bias != INT_MIN)
1025  x4->params.i_bframe_bias = x4->b_bias;
1026  if (x4->b_pyramid >= 0)
1027  x4->params.i_bframe_pyramid = x4->b_pyramid;
1028  if (x4->mixed_refs >= 0)
1029  x4->params.analyse.b_mixed_references = x4->mixed_refs;
1030  if (x4->dct8x8 >= 0)
1031  x4->params.analyse.b_transform_8x8 = x4->dct8x8;
1032  if (x4->fast_pskip >= 0)
1033  x4->params.analyse.b_fast_pskip = x4->fast_pskip;
1034  if (x4->aud >= 0)
1035  x4->params.b_aud = x4->aud;
1036  if (x4->mbtree >= 0)
1037  x4->params.rc.b_mb_tree = x4->mbtree;
1038  if (x4->direct_pred >= 0)
1039  x4->params.analyse.i_direct_mv_pred = x4->direct_pred;
1040 
1041  if (x4->slice_max_size >= 0)
1042  x4->params.i_slice_max_size = x4->slice_max_size;
1043 
1044  if (x4->fastfirstpass)
1045  x264_param_apply_fastfirstpass(&x4->params);
1046 
1047  x4->profile = x4->profile_opt;
1048  /* Allow specifying the x264 profile through AVCodecContext. */
1049  if (!x4->profile)
1050  switch (avctx->profile) {
1052  x4->profile = "baseline";
1053  break;
1054  case AV_PROFILE_H264_HIGH:
1055  x4->profile = "high";
1056  break;
1058  x4->profile = "high10";
1059  break;
1061  x4->profile = "high422";
1062  break;
1064  x4->profile = "high444";
1065  break;
1066  case AV_PROFILE_H264_MAIN:
1067  x4->profile = "main";
1068  break;
1069  default:
1070  break;
1071  }
1072 
1073  if (x4->nal_hrd >= 0)
1074  x4->params.i_nal_hrd = x4->nal_hrd;
1075 
1076  if (x4->motion_est >= 0)
1077  x4->params.analyse.i_me_method = x4->motion_est;
1078 
1079  if (x4->coder >= 0)
1080  x4->params.b_cabac = x4->coder;
1081 
1082  if (x4->b_frame_strategy >= 0)
1083  x4->params.i_bframe_adaptive = x4->b_frame_strategy;
1084 
1085  if (x4->profile)
1086  if (x264_param_apply_profile(&x4->params, x4->profile) < 0) {
1087  int i;
1088  av_log(avctx, AV_LOG_ERROR, "Error setting profile %s.\n", x4->profile);
1089  av_log(avctx, AV_LOG_INFO, "Possible profiles:");
1090  for (i = 0; x264_profile_names[i]; i++)
1091  av_log(avctx, AV_LOG_INFO, " %s", x264_profile_names[i]);
1092  av_log(avctx, AV_LOG_INFO, "\n");
1093  return AVERROR(EINVAL);
1094  }
1095 
1096  x4->params.i_width = avctx->width;
1097  x4->params.i_height = avctx->height;
1098  av_reduce(&sw, &sh, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 4096);
1099  x4->params.vui.i_sar_width = sw;
1100  x4->params.vui.i_sar_height = sh;
1101  x4->params.i_timebase_den = avctx->time_base.den;
1102  x4->params.i_timebase_num = avctx->time_base.num;
1103  if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
1104  x4->params.i_fps_num = avctx->framerate.num;
1105  x4->params.i_fps_den = avctx->framerate.den;
1106  } else {
1107  x4->params.i_fps_num = avctx->time_base.den;
1109  x4->params.i_fps_den = avctx->time_base.num
1110 #if FF_API_TICKS_PER_FRAME
1111  * avctx->ticks_per_frame
1112 #endif
1113  ;
1115  }
1116 
1117  x4->params.analyse.b_psnr = avctx->flags & AV_CODEC_FLAG_PSNR;
1118 
1119  x4->params.i_threads = avctx->thread_count;
1120  if (avctx->thread_type)
1121  x4->params.b_sliced_threads = avctx->thread_type == FF_THREAD_SLICE;
1122 
1123  x4->params.b_interlaced = avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT;
1124 
1125  x4->params.b_open_gop = !(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP);
1126 
1127  x4->params.i_slice_count = avctx->slices;
1128 
1129  if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED)
1130  x4->params.vui.b_fullrange = avctx->color_range == AVCOL_RANGE_JPEG;
1131  else if (avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
1132  avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
1133  avctx->pix_fmt == AV_PIX_FMT_YUVJ444P)
1134  x4->params.vui.b_fullrange = 1;
1135 
1136  if (avctx->colorspace != AVCOL_SPC_UNSPECIFIED)
1137  x4->params.vui.i_colmatrix = avctx->colorspace;
1138  if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED)
1139  x4->params.vui.i_colorprim = avctx->color_primaries;
1140  if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED)
1141  x4->params.vui.i_transfer = avctx->color_trc;
1143  x4->params.vui.i_chroma_loc = avctx->chroma_sample_location - 1;
1144 
1145  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)
1146  x4->params.b_repeat_headers = 0;
1147 
1148  if (avctx->flags & AV_CODEC_FLAG_RECON_FRAME)
1149  x4->params.b_full_recon = 1;
1150 
1151  if(x4->x264opts){
1152  const char *p= x4->x264opts;
1153  while(p){
1154  char param[4096]={0}, val[4096]={0};
1155  if(sscanf(p, "%4095[^:=]=%4095[^:]", param, val) == 1){
1156  ret = parse_opts(avctx, param, "1");
1157  if (ret < 0)
1158  return ret;
1159  } else {
1160  ret = parse_opts(avctx, param, val);
1161  if (ret < 0)
1162  return ret;
1163  }
1164  p= strchr(p, ':');
1165  if (p) {
1166  ++p;
1167  }
1168  }
1169  }
1170 
1171 #if X264_BUILD >= 142
1172  /* Separate headers not supported in AVC-Intra mode */
1173  if (x4->avcintra_class >= 0)
1174  x4->params.b_repeat_headers = 1;
1175 #endif
1176 
1177  {
1178  AVDictionaryEntry *en = NULL;
1179  while (en = av_dict_get(x4->x264_params, "", en, AV_DICT_IGNORE_SUFFIX)) {
1180  if ((ret = x264_param_parse(&x4->params, en->key, en->value)) < 0) {
1181  av_log(avctx, AV_LOG_WARNING,
1182  "Error parsing option '%s = %s'.\n",
1183  en->key, en->value);
1184 #if X264_BUILD >= 161
1185  if (ret == X264_PARAM_ALLOC_FAILED)
1186  return AVERROR(ENOMEM);
1187 #endif
1188  }
1189  }
1190  }
1191 
1192  x4->params.analyse.b_mb_info = x4->mb_info;
1193 
1194  // update AVCodecContext with x264 parameters
1195  avctx->has_b_frames = x4->params.i_bframe ?
1196  x4->params.i_bframe_pyramid ? 2 : 1 : 0;
1197  if (avctx->max_b_frames < 0)
1198  avctx->max_b_frames = 0;
1199 
1200  avctx->bit_rate = x4->params.rc.i_bitrate*1000LL;
1201 
1202  x4->enc = x264_encoder_open(&x4->params);
1203  if (!x4->enc)
1204  return AVERROR_EXTERNAL;
1205 
1206  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
1207  x264_nal_t *nal;
1208  uint8_t *p;
1209  int nnal, s, i;
1210 
1211  s = x264_encoder_headers(x4->enc, &nal, &nnal);
1213  if (!p)
1214  return AVERROR(ENOMEM);
1215 
1216  for (i = 0; i < nnal; i++) {
1217  /* Don't put the SEI in extradata. */
1218  if (nal[i].i_type == NAL_SEI) {
1219  av_log(avctx, AV_LOG_INFO, "%s\n", nal[i].p_payload+25);
1220  x4->sei_size = nal[i].i_payload;
1221  x4->sei = av_malloc(x4->sei_size);
1222  if (!x4->sei)
1223  return AVERROR(ENOMEM);
1224  memcpy(x4->sei, nal[i].p_payload, nal[i].i_payload);
1225  continue;
1226  }
1227  memcpy(p, nal[i].p_payload, nal[i].i_payload);
1228  p += nal[i].i_payload;
1229  }
1230  avctx->extradata_size = p - avctx->extradata;
1231  }
1232 
1233  cpb_props = ff_encode_add_cpb_side_data(avctx);
1234  if (!cpb_props)
1235  return AVERROR(ENOMEM);
1236  cpb_props->buffer_size = x4->params.rc.i_vbv_buffer_size * 1000;
1237  cpb_props->max_bitrate = x4->params.rc.i_vbv_max_bitrate * 1000LL;
1238  cpb_props->avg_bitrate = x4->params.rc.i_bitrate * 1000LL;
1239 
1240  // Overestimate the reordered opaque buffer size, in case a runtime
1241  // reconfigure would increase the delay (which it shouldn't).
1242  x4->nb_reordered_opaque = x264_encoder_maximum_delayed_frames(x4->enc) + 17;
1244  sizeof(*x4->reordered_opaque));
1245  if (!x4->reordered_opaque) {
1246  x4->nb_reordered_opaque = 0;
1247  return AVERROR(ENOMEM);
1248  }
1249 
1250  return 0;
1251 }
1252 
1253 static const enum AVPixelFormat pix_fmts_8bit[] = {
1262 #ifdef X264_CSP_NV21
1264 #endif
1266 };
1267 static const enum AVPixelFormat pix_fmts_9bit[] = {
1271 };
1272 static const enum AVPixelFormat pix_fmts_10bit[] = {
1278 };
1279 static const enum AVPixelFormat pix_fmts_all[] = {
1288 #ifdef X264_CSP_NV21
1290 #endif
1295 #ifdef X264_CSP_I400
1298 #endif
1300 };
1301 #if CONFIG_LIBX264RGB_ENCODER
1302 static const enum AVPixelFormat pix_fmts_8bit_rgb[] = {
1307 };
1308 #endif
1309 
1310 #if X264_BUILD < 153
1311 static av_cold void X264_init_static(FFCodec *codec)
1312 {
1313  if (x264_bit_depth == 8)
1314  codec->p.pix_fmts = pix_fmts_8bit;
1315  else if (x264_bit_depth == 9)
1316  codec->p.pix_fmts = pix_fmts_9bit;
1317  else if (x264_bit_depth == 10)
1318  codec->p.pix_fmts = pix_fmts_10bit;
1319 }
1320 #endif
1321 
1322 #define OFFSET(x) offsetof(X264Context, x)
1323 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1324 static const AVOption options[] = {
1325  { "preset", "Set the encoding preset (cf. x264 --fullhelp)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "medium" }, 0, 0, VE},
1326  { "tune", "Tune the encoding params (cf. x264 --fullhelp)", OFFSET(tune), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
1327  { "profile", "Set profile restrictions (cf. x264 --fullhelp)", OFFSET(profile_opt), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
1328  { "fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE},
1329  {"level", "Specify level (as defined by Annex A)", OFFSET(level), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
1330  {"passlogfile", "Filename for 2 pass stats", OFFSET(stats), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
1331  {"wpredp", "Weighted prediction for P-frames", OFFSET(wpredp), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
1332  {"a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, VE},
1333  {"x264opts", "x264 options", OFFSET(x264opts), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
1334  { "crf", "Select the quality for constant quality mode", OFFSET(crf), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VE },
1335  { "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 },
1336  { "qp", "Constant quantization parameter rate control method",OFFSET(cqp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE },
1337  { "aq-mode", "AQ method", OFFSET(aq_mode), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, "aq_mode"},
1338  { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_NONE}, INT_MIN, INT_MAX, VE, "aq_mode" },
1339  { "variance", "Variance AQ (complexity mask)", 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" },
1340  { "autovariance", "Auto-variance AQ", 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" },
1341 #if X264_BUILD >= 144
1342  { "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" },
1343 #endif
1344  { "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},
1345  { "psy", "Use psychovisual optimizations.", OFFSET(psy), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1346  { "psy-rd", "Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.", OFFSET(psy_rd), AV_OPT_TYPE_STRING, {0 }, 0, 0, VE},
1347  { "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 },
1348  { "weightb", "Weighted prediction for B-frames.", OFFSET(weightb), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1349  { "weightp", "Weighted prediction analysis method.", OFFSET(weightp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, "weightp" },
1350  { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_NONE}, INT_MIN, INT_MAX, VE, "weightp" },
1351  { "simple", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SIMPLE}, INT_MIN, INT_MAX, VE, "weightp" },
1352  { "smart", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SMART}, INT_MIN, INT_MAX, VE, "weightp" },
1353  { "ssim", "Calculate and print SSIM stats.", OFFSET(ssim), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1354  { "intra-refresh", "Use Periodic Intra Refresh instead of IDR frames.",OFFSET(intra_refresh),AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1355  { "bluray-compat", "Bluray compatibility workarounds.", OFFSET(bluray_compat) ,AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
1356  { "b-bias", "Influences how often B-frames are used", OFFSET(b_bias), AV_OPT_TYPE_INT, { .i64 = INT_MIN}, INT_MIN, INT_MAX, VE },
1357  { "b-pyramid", "Keep some B-frames as references.", OFFSET(b_pyramid), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, "b_pyramid" },
1358  { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NONE}, INT_MIN, INT_MAX, VE, "b_pyramid" },
1359  { "strict", "Strictly hierarchical pyramid", 0, AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX, VE, "b_pyramid" },
1360  { "normal", "Non-strict (not Blu-ray compatible)", 0, AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX, VE, "b_pyramid" },
1361  { "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 },
1362  { "8x8dct", "High profile 8x8 transform.", OFFSET(dct8x8), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE},
1363  { "fast-pskip", NULL, OFFSET(fast_pskip), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE},
1364  { "aud", "Use access unit delimiters.", OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE},
1365  { "mbtree", "Use macroblock tree ratecontrol.", OFFSET(mbtree), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE},
1366  { "deblock", "Loop filter parameters, in <alpha:beta> form.", OFFSET(deblock), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
1367  { "cplxblur", "Reduce fluctuations in QP (before curve compression)", OFFSET(cplxblur), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VE},
1368  { "partitions", "A comma-separated list of partitions to consider. "
1369  "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all", OFFSET(partitions), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
1370  { "direct-pred", "Direct MV prediction mode", OFFSET(direct_pred), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, "direct-pred" },
1371  { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_NONE }, 0, 0, VE, "direct-pred" },
1372  { "spatial", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_SPATIAL }, 0, 0, VE, "direct-pred" },
1373  { "temporal", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_TEMPORAL }, 0, 0, VE, "direct-pred" },
1374  { "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_AUTO }, 0, 0, VE, "direct-pred" },
1375  { "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 },
1376  { "stats", "Filename for 2 pass stats", OFFSET(stats), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
1377  { "nal-hrd", "Signal HRD information (requires vbv-bufsize; "
1378  "cbr not allowed in .mp4)", OFFSET(nal_hrd), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, "nal-hrd" },
1379  { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_NONE}, INT_MIN, INT_MAX, VE, "nal-hrd" },
1380  { "vbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_VBR}, INT_MIN, INT_MAX, VE, "nal-hrd" },
1381  { "cbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_CBR}, INT_MIN, INT_MAX, VE, "nal-hrd" },
1382  { "avcintra-class","AVC-Intra class 50/100/200/300/480", OFFSET(avcintra_class),AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 480 , VE},
1383  { "me_method", "Set motion estimation method", OFFSET(motion_est), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, X264_ME_TESA, VE, "motion-est"},
1384  { "motion-est", "Set motion estimation method", OFFSET(motion_est), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, X264_ME_TESA, VE, "motion-est"},
1385  { "dia", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_DIA }, INT_MIN, INT_MAX, VE, "motion-est" },
1386  { "hex", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_HEX }, INT_MIN, INT_MAX, VE, "motion-est" },
1387  { "umh", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_UMH }, INT_MIN, INT_MAX, VE, "motion-est" },
1388  { "esa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_ESA }, INT_MIN, INT_MAX, VE, "motion-est" },
1389  { "tesa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_TESA }, INT_MIN, INT_MAX, VE, "motion-est" },
1390  { "forced-idr", "If forcing keyframes, force them as IDR frames.", OFFSET(forced_idr), AV_OPT_TYPE_BOOL, { .i64 = 0 }, -1, 1, VE },
1391  { "coder", "Coder type", OFFSET(coder), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE, "coder" },
1392  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, INT_MIN, INT_MAX, VE, "coder" },
1393  { "cavlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, "coder" },
1394  { "cabac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "coder" },
1395  { "vlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, "coder" },
1396  { "ac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "coder" },
1397  { "b_strategy", "Strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2, VE },
1398  { "chromaoffset", "QP difference between chroma and luma", OFFSET(chroma_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, VE },
1399  { "sc_threshold", "Scene change threshold", OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX, VE },
1400  { "noise_reduction", "Noise reduction", OFFSET(noise_reduction), AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX, VE },
1401  { "udu_sei", "Use user data unregistered SEI if available", OFFSET(udu_sei), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
1402  { "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 },
1403  { "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 },
1404  { NULL },
1405 };
1406 
1407 static const FFCodecDefault x264_defaults[] = {
1408  { "b", "0" },
1409  { "bf", "-1" },
1410  { "flags2", "0" },
1411  { "g", "-1" },
1412  { "i_qfactor", "-1" },
1413  { "b_qfactor", "-1" },
1414  { "qmin", "-1" },
1415  { "qmax", "-1" },
1416  { "qdiff", "-1" },
1417  { "qblur", "-1" },
1418  { "qcomp", "-1" },
1419 // { "rc_lookahead", "-1" },
1420  { "refs", "-1" },
1421  { "trellis", "-1" },
1422  { "me_range", "-1" },
1423  { "subq", "-1" },
1424  { "keyint_min", "-1" },
1425  { "cmp", "-1" },
1426  { "threads", AV_STRINGIFY(X264_THREADS_AUTO) },
1427  { "thread_type", "0" },
1428  { "flags", "+cgop" },
1429  { "rc_init_occupancy","-1" },
1430  { NULL },
1431 };
1432 
1433 #if CONFIG_LIBX264_ENCODER
1434 static const AVClass x264_class = {
1435  .class_name = "libx264",
1436  .item_name = av_default_item_name,
1437  .option = options,
1438  .version = LIBAVUTIL_VERSION_INT,
1439 };
1440 
1441 #if X264_BUILD >= 153
1442 const
1443 #endif
1444 FFCodec ff_libx264_encoder = {
1445  .p.name = "libx264",
1446  CODEC_LONG_NAME("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
1447  .p.type = AVMEDIA_TYPE_VIDEO,
1448  .p.id = AV_CODEC_ID_H264,
1449  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
1454  .p.priv_class = &x264_class,
1455  .p.wrapper_name = "libx264",
1456  .priv_data_size = sizeof(X264Context),
1457  .init = X264_init,
1459  .flush = X264_flush,
1460  .close = X264_close,
1461  .defaults = x264_defaults,
1462 #if X264_BUILD < 153
1463  .init_static_data = X264_init_static,
1464 #else
1465  .p.pix_fmts = pix_fmts_all,
1466 #endif
1468 #if X264_BUILD < 158
1470 #endif
1471  ,
1472 };
1473 #endif
1474 
1475 #if CONFIG_LIBX264RGB_ENCODER
1476 static const AVClass rgbclass = {
1477  .class_name = "libx264rgb",
1478  .item_name = av_default_item_name,
1479  .option = options,
1480  .version = LIBAVUTIL_VERSION_INT,
1481 };
1482 
1484  .p.name = "libx264rgb",
1485  CODEC_LONG_NAME("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB"),
1486  .p.type = AVMEDIA_TYPE_VIDEO,
1487  .p.id = AV_CODEC_ID_H264,
1488  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
1491  .p.pix_fmts = pix_fmts_8bit_rgb,
1492  .p.priv_class = &rgbclass,
1493  .p.wrapper_name = "libx264",
1494  .priv_data_size = sizeof(X264Context),
1495  .init = X264_init,
1497  .close = X264_close,
1498  .defaults = x264_defaults,
1500 #if X264_BUILD < 158
1502 #endif
1503  ,
1504 };
1505 #endif
1506 
1507 #if CONFIG_LIBX262_ENCODER
1508 static const AVClass X262_class = {
1509  .class_name = "libx262",
1510  .item_name = av_default_item_name,
1511  .option = options,
1512  .version = LIBAVUTIL_VERSION_INT,
1513 };
1514 
1515 const FFCodec ff_libx262_encoder = {
1516  .p.name = "libx262",
1517  CODEC_LONG_NAME("libx262 MPEG2VIDEO"),
1518  .p.type = AVMEDIA_TYPE_VIDEO,
1519  .p.id = AV_CODEC_ID_MPEG2VIDEO,
1520  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
1523  .p.pix_fmts = pix_fmts_8bit,
1524  .p.priv_class = &X262_class,
1525  .p.wrapper_name = "libx264",
1526  .priv_data_size = sizeof(X264Context),
1527  .init = X264_init,
1529  .close = X264_close,
1530  .defaults = x264_defaults,
1531  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
1533 };
1534 #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:426
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
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
level
uint8_t level
Definition: svq3.c:204
av_clip
#define av_clip
Definition: common.h:96
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:990
X264Context
Definition: libx264.c:67
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
opt.h
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1025
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:824
X264Context::avcintra_class
int avcintra_class
Definition: libx264.c:109
stats
static void stats(AVPacket *const *in, int n_in, unsigned *_max, unsigned *_sum)
Definition: vp9_superframe_bsf.c:34
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2936
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:603
X264Context::tune
char * tune
Definition: libx264.c:75
AV_PROFILE_H264_MAIN
#define AV_PROFILE_H264_MAIN
Definition: defs.h:111
rect
Definition: f_ebur128.c:78
X264Context::cplxblur
float cplxblur
Definition: libx264.c:103
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:79
X264Context::fast_pskip
int fast_pskip
Definition: libx264.c:99
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
X264_log
static void X264_log(void *p, int level, const char *fmt, va_list args)
Definition: libx264.c:134
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
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:683
pixdesc.h
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1018
AVFrame::width
int width
Definition: frame.h:412
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:669
ff_libx264rgb_encoder
const FFCodec ff_libx264rgb_encoder
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:374
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:251
encode.h
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:569
X264Context::stats
char * stats
Definition: libx264.c:107
X264Context::nb_reordered_opaque
int nb_reordered_opaque
Definition: libx264.c:122
data
const char data[16]
Definition: mxf.c:148
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:465
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:738
X264Context::sei_size
int sei_size
Definition: libx264.c:73
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:392
AVDictionary
Definition: dict.c:34
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:318
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:330
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:1251
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:93
AVCodecContext::me_subpel_quality
int me_subpel_quality
subpel ME quality
Definition: avcodec.h:895
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:429
X264Context::cqp
int cqp
Definition: libx264.c:84
X264Context::udu_sei
int udu_sei
Definition: libx264.c:118
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
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:129
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:330
video_hint.h
X264_init
static av_cold int X264_init(AVCodecContext *avctx)
Definition: libx264.c:845
X264Context::slice_max_size
int slice_max_size
Definition: libx264.c:106
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:641
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:302
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:1797
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:1311
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2976
AV_CODEC_FLAG_COPY_OPAQUE
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition: avcodec.h:291
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:749
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:115
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:410
fail
#define fail()
Definition: checkasm.h:138
AV_PIX_FMT_NV20
#define AV_PIX_FMT_NV20
Definition: pixfmt.h:512
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1528
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:91
ff_side_data_set_prft
int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp)
Definition: avpacket.c:628
X264Context::pic
x264_picture_t pic
Definition: libx264.c:71
AVCodecContext::refs
int refs
number of reference frames
Definition: avcodec.h:997
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:517
FF_CMP_CHROMA
#define FF_CMP_CHROMA
Definition: avcodec.h:860
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
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
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:69
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:315
X264Context::nal_hrd
int nal_hrd
Definition: libx264.c:108
AV_CODEC_FLAG_LOOP_FILTER
#define AV_CODEC_FLAG_LOOP_FILTER
loop filter.
Definition: avcodec.h:310
X264Context::bluray_compat
int bluray_compat
Definition: libx264.c:94
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:322
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:468
AVFormatContext::bit_rate
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
Definition: avformat.h:1214
preset
preset
Definition: vf_curves.c:46
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1011
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:249
av_cold
#define av_cold
Definition: attributes.h:90
pix_fmts_10bit
static enum AVPixelFormat pix_fmts_10bit[]
Definition: libx264.c:1272
AVRegionOfInterest
Structure describing a single Region Of Interest.
Definition: frame.h:265
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:1308
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:79
X264Context::b_pyramid
int b_pyramid
Definition: libx264.c:96
float
float
Definition: af_crystalizer.c:121
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:539
AVCodecContext::has_b_frames
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:740
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
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:503
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:51
AVRegionOfInterest::bottom
int bottom
Definition: frame.h:281
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1223
X264Context::mixed_refs
int mixed_refs
Definition: libx264.c:97
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:402
pix_fmts_all
static enum AVPixelFormat pix_fmts_all[]
Definition: libx264.c:1279
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
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
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:1538
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:462
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
COMPUTE_MBINFO
#define COMPUTE_MBINFO(mbinfo_filler_, mbinfo_marker_, compute_coords_fn_)
X264Context::weightp
int weightp
Definition: libx264.c:90
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:66
AVCodecContext::rc_max_rate
int64_t rc_max_rate
maximum bitrate
Definition: avcodec.h:1280
AVPacket::opaque
void * opaque
for some private data of the user
Definition: packet.h:399
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:544
AVCPBProperties
This structure describes the bitrate properties of an encoded bitstream.
Definition: defs.h:261
X264Opaque
Definition: libx264.c:56
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:80
AV_PROFILE_H264_HIGH_422
#define AV_PROFILE_H264_HIGH_422
Definition: defs.h:117
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:447
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:398
X264Context::noise_reduction
int noise_reduction
Definition: libx264.c:117
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:446
AVCodecContext::rc_buffer_size
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:1265
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:1267
NULL
#define NULL
Definition: coverity.c:32
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1035
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:83
X264Context::forced_idr
int forced_idr
Definition: libx264.c:111
X264Context::aud
int aud
Definition: libx264.c:100
AVCodecContext::qblur
float qblur
amount of qscale smoothing over time (0.0-1.0)
Definition: avcodec.h:1237
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:78
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:487
sei.h
AV_OPT_TYPE_DICT
@ AV_OPT_TYPE_DICT
Definition: opt.h:232
AVRegionOfInterest::self_size
uint32_t self_size
Must be set to the size of this data structure (that is, sizeof(AVRegionOfInterest)).
Definition: frame.h:270
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:105
X264Context::profile_opt
char * profile_opt
Definition: libx264.c:77
AV_PIX_FMT_BGR0
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:258
time.h
AVCodecContext::me_cmp
int me_cmp
motion estimation comparison function
Definition: avcodec.h:825
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:466
AVCodecContext::trellis
int trellis
trellis RD quantization
Definition: avcodec.h:1315
av_clipf
av_clipf
Definition: af_crystalizer.c:121
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
sei
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
Definition: cbs_h264_syntax_template.c:825
AVCodecContext::level
int level
level
Definition: avcodec.h:1734
free_picture
static void free_picture(x264_picture_t *pic)
Definition: libx264.c:298
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:635
X264Context::preset
char * preset
Definition: libx264.c:74
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:166
X264Context::x264_params
AVDictionary * x264_params
Definition: libx264.c:120
PARSE_X264_OPT
#define PARSE_X264_OPT(name, var)
Definition: libx264.c:839
AVCodecContext::qcompress
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
Definition: avcodec.h:1236
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:559
aud
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
Definition: cbs_h264_syntax_template.c:842
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:342
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
pix_fmts_8bit
static enum AVPixelFormat pix_fmts_8bit[]
Definition: libx264.c:1253
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
AVCodecContext::gop_size
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:639
codec_internal.h
X264_close
static av_cold int X264_close(AVCodecContext *avctx)
Definition: libx264.c:756
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:155
MB_CEIL
#define MB_CEIL(x)
Definition: libx264.c:54
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:904
AVFrameSideData::data
uint8_t * data
Definition: frame.h:248
FF_THREAD_SLICE
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
Definition: avcodec.h:1540
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:689
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:427
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:191
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:373
AV_CODEC_FLAG_PASS2
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:306
X264Context::motion_est
int motion_est
Definition: libx264.c:110
opaque_uninit
static void opaque_uninit(X264Opaque *o)
Definition: libx264.c:149
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:380
X264Context::b_bias
int b_bias
Definition: libx264.c:95
AVCodecInternal
Definition: internal.h:52
AVCPBProperties::avg_bitrate
int64_t avg_bitrate
Average bitrate of the stream, in bits per second.
Definition: defs.h:276
AVRegionOfInterest::right
int right
Definition: frame.h:283
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:725
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
VE
#define VE
Definition: libx264.c:1323
X264Context::sei
uint8_t * sei
Definition: libx264.c:72
AVRegionOfInterest::left
int left
Definition: frame.h:282
X264Context::aq_mode
int aq_mode
Definition: libx264.c:85
X264Opaque::frame_opaque_ref
AVBufferRef * frame_opaque_ref
Definition: libx264.c:64
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:256
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:244
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:367
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:538
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:280
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:266
X264Context::a53_cc
int a53_cc
Definition: libx264.c:113
setup_mb_info
static int setup_mb_info(AVCodecContext *ctx, x264_picture_t *pic, const AVFrame *frame, const AVVideoHint *info)
Definition: libx264.c:354
x264_defaults
static const FFCodecDefault x264_defaults[]
Definition: libx264.c:1407
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:622
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:1042
AV_PIX_FMT_NV21
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
Definition: pixfmt.h:90
csp_to_pixfmt
static enum AVPixelFormat csp_to_pixfmt(int csp)
Definition: libx264.c:308
options
static const AVOption options[]
Definition: libx264.c:1324
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:598
AVCodecContext::height
int height
Definition: avcodec.h:617
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:654
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:636
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:464
avcodec.h
X264Context::profile
const char * profile
Definition: libx264.c:76
X264Context::mbtree
int mbtree
Definition: libx264.c:101
AV_CODEC_FLAG_CLOSED_GOP
#define AV_CODEC_FLAG_CLOSED_GOP
Definition: avcodec.h:344
X264Context::mb_info
int mb_info
Definition: libx264.c:131
ret
ret
Definition: filter_design.txt:187
X264Context::reordered_opaque
X264Opaque * reordered_opaque
Definition: libx264.c:123
X264Opaque::frame_opaque
void * frame_opaque
Definition: libx264.c:63
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:89
X264Context::crf
float crf
Definition: libx264.c:82
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:78
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVCPBProperties::buffer_size
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
Definition: defs.h:282
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
X264Context::wpredp
char * wpredp
Definition: libx264.c:80
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:226
ff_libx262_encoder
const FFCodec ff_libx262_encoder
X264Context::next_reordered_opaque
int next_reordered_opaque
Definition: libx264.c:122
X264Opaque::wallclock
int64_t wallclock
Definition: libx264.c:60
AVCodecInternal::recon_frame
AVFrame * recon_frame
When the AV_CODEC_FLAG_RECON_FRAME flag is used.
Definition: internal.h:108
X264Context::scenechange_threshold
int scenechange_threshold
Definition: libx264.c:116
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
X264Context::x264opts
char * x264opts
Definition: libx264.c:81
AVCodecContext::max_qdiff
int max_qdiff
maximum quantizer difference between frames
Definition: avcodec.h:1258
AVCodecContext
main external API structure.
Definition: avcodec.h:437
AVFrame::height
int height
Definition: frame.h:412
reconfig_encoder
static void reconfig_encoder(AVCodecContext *ctx, const AVFrame *frame)
Definition: libx264.c:198
AV_PROFILE_H264_HIGH
#define AV_PROFILE_H264_HIGH
Definition: defs.h:113
X264Context::coder
int coder
Definition: libx264.c:112
X264Context::aq_strength
float aq_strength
Definition: libx264.c:86
MB_FLOOR
#define MB_FLOOR(x)
Definition: libx264.c:53
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:104
SEI_TYPE_USER_DATA_UNREGISTERED
@ SEI_TYPE_USER_DATA_UNREGISTERED
Definition: sei.h:35
AVCodecContext::qmin
int qmin
minimum quantizer
Definition: avcodec.h:1244
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1592
MB_SIZE
#define MB_SIZE
Definition: libx264.c:51
X264Context::rc_lookahead
int rc_lookahead
Definition: libx264.c:89
AVFrameSideData::type
enum AVFrameSideDataType type
Definition: frame.h:247
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:575
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
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:71
OFFSET
#define OFFSET(x)
Definition: libx264.c:1322
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:98
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:70
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:716
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
X264Context::psy_rd
char * psy_rd
Definition: libx264.c:87
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
setup_frame
static int setup_frame(AVCodecContext *ctx, const AVFrame *frame, x264_picture_t **ppic)
Definition: libx264.c:471
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:246
parse_opts
static int parse_opts(AVCodecContext *avctx, const char *opt, const char *param)
Definition: libx264.c:778
X264Context::deblock
char * deblock
Definition: libx264.c:102
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:1051
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:464
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
X264Context::ssim
int ssim
Definition: libx264.c:92
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:617
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:88
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:385
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
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:869
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:229
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:70
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:624
AVRegionOfInterest::qoffset
AVRational qoffset
Quantisation offset.
Definition: frame.h:307
X264Context::b_frame_strategy
int b_frame_strategy
Definition: libx264.c:114
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1133
mb_info
Definition: cinepakenc.c:88
convert_pix_fmt
static int convert_pix_fmt(enum AVPixelFormat pix_fmt)
Definition: libx264.c:804
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:818
X264Opaque::duration
int64_t duration
Definition: libx264.c:61
AV_CODEC_FLAG_PASS1
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:302
X264Context::partitions
char * partitions
Definition: libx264.c:104