You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

489 lines
20KB

  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 Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/opt.h"
  22. #include "avcodec.h"
  23. #include "internal.h"
  24. #include <x264.h>
  25. #include <float.h>
  26. #include <math.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. typedef struct X264Context {
  31. AVClass *class;
  32. x264_param_t params;
  33. x264_t *enc;
  34. x264_picture_t pic;
  35. uint8_t *sei;
  36. int sei_size;
  37. AVFrame out_pic;
  38. char *preset;
  39. char *tune;
  40. char *profile;
  41. int fastfirstpass;
  42. float crf;
  43. float crf_max;
  44. int cqp;
  45. int aq_mode;
  46. float aq_strength;
  47. char *psy_rd;
  48. int rc_lookahead;
  49. int weightp;
  50. int weightb;
  51. int ssim;
  52. int intra_refresh;
  53. int b_pyramid;
  54. int mixed_refs;
  55. int dct8x8;
  56. int fast_pskip;
  57. int aud;
  58. } X264Context;
  59. static void X264_log(void *p, int level, const char *fmt, va_list args)
  60. {
  61. static const int level_map[] = {
  62. [X264_LOG_ERROR] = AV_LOG_ERROR,
  63. [X264_LOG_WARNING] = AV_LOG_WARNING,
  64. [X264_LOG_INFO] = AV_LOG_INFO,
  65. [X264_LOG_DEBUG] = AV_LOG_DEBUG
  66. };
  67. if (level < 0 || level > X264_LOG_DEBUG)
  68. return;
  69. av_vlog(p, level_map[level], fmt, args);
  70. }
  71. static int encode_nals(AVCodecContext *ctx, uint8_t *buf, int size,
  72. x264_nal_t *nals, int nnal, int skip_sei)
  73. {
  74. X264Context *x4 = ctx->priv_data;
  75. uint8_t *p = buf;
  76. int i;
  77. /* Write the SEI as part of the first frame. */
  78. if (x4->sei_size > 0 && nnal > 0) {
  79. memcpy(p, x4->sei, x4->sei_size);
  80. p += x4->sei_size;
  81. x4->sei_size = 0;
  82. }
  83. for (i = 0; i < nnal; i++){
  84. /* Don't put the SEI in extradata. */
  85. if (skip_sei && nals[i].i_type == NAL_SEI) {
  86. x4->sei_size = nals[i].i_payload;
  87. x4->sei = av_malloc(x4->sei_size);
  88. memcpy(x4->sei, nals[i].p_payload, nals[i].i_payload);
  89. continue;
  90. }
  91. memcpy(p, nals[i].p_payload, nals[i].i_payload);
  92. p += nals[i].i_payload;
  93. }
  94. return p - buf;
  95. }
  96. static int X264_frame(AVCodecContext *ctx, uint8_t *buf,
  97. int bufsize, void *data)
  98. {
  99. X264Context *x4 = ctx->priv_data;
  100. AVFrame *frame = data;
  101. x264_nal_t *nal;
  102. int nnal, i;
  103. x264_picture_t pic_out;
  104. x264_picture_init( &x4->pic );
  105. x4->pic.img.i_csp = X264_CSP_I420;
  106. x4->pic.img.i_plane = 3;
  107. if (frame) {
  108. for (i = 0; i < 3; i++) {
  109. x4->pic.img.plane[i] = frame->data[i];
  110. x4->pic.img.i_stride[i] = frame->linesize[i];
  111. }
  112. x4->pic.i_pts = frame->pts;
  113. x4->pic.i_type =
  114. frame->pict_type == AV_PICTURE_TYPE_I ? X264_TYPE_KEYFRAME :
  115. frame->pict_type == AV_PICTURE_TYPE_P ? X264_TYPE_P :
  116. frame->pict_type == AV_PICTURE_TYPE_B ? X264_TYPE_B :
  117. X264_TYPE_AUTO;
  118. if (x4->params.b_tff != frame->top_field_first) {
  119. x4->params.b_tff = frame->top_field_first;
  120. x264_encoder_reconfig(x4->enc, &x4->params);
  121. }
  122. }
  123. do {
  124. if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
  125. return -1;
  126. bufsize = encode_nals(ctx, buf, bufsize, nal, nnal, 0);
  127. if (bufsize < 0)
  128. return -1;
  129. } while (!bufsize && !frame && x264_encoder_delayed_frames(x4->enc));
  130. /* FIXME: libx264 now provides DTS, but AVFrame doesn't have a field for it. */
  131. x4->out_pic.pts = pic_out.i_pts;
  132. switch (pic_out.i_type) {
  133. case X264_TYPE_IDR:
  134. case X264_TYPE_I:
  135. x4->out_pic.pict_type = AV_PICTURE_TYPE_I;
  136. break;
  137. case X264_TYPE_P:
  138. x4->out_pic.pict_type = AV_PICTURE_TYPE_P;
  139. break;
  140. case X264_TYPE_B:
  141. case X264_TYPE_BREF:
  142. x4->out_pic.pict_type = AV_PICTURE_TYPE_B;
  143. break;
  144. }
  145. x4->out_pic.key_frame = pic_out.b_keyframe;
  146. if (bufsize)
  147. x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
  148. return bufsize;
  149. }
  150. static av_cold int X264_close(AVCodecContext *avctx)
  151. {
  152. X264Context *x4 = avctx->priv_data;
  153. av_freep(&avctx->extradata);
  154. av_free(x4->sei);
  155. if (x4->enc)
  156. x264_encoder_close(x4->enc);
  157. return 0;
  158. }
  159. static av_cold int X264_init(AVCodecContext *avctx)
  160. {
  161. X264Context *x4 = avctx->priv_data;
  162. x4->sei_size = 0;
  163. x264_param_default(&x4->params);
  164. x4->params.i_keyint_max = avctx->gop_size;
  165. x4->params.i_bframe = avctx->max_b_frames;
  166. x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC;
  167. x4->params.i_bframe_adaptive = avctx->b_frame_strategy;
  168. x4->params.i_bframe_bias = avctx->bframebias;
  169. x4->params.i_keyint_min = avctx->keyint_min;
  170. if (x4->params.i_keyint_min > x4->params.i_keyint_max)
  171. x4->params.i_keyint_min = x4->params.i_keyint_max;
  172. x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
  173. x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER;
  174. x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha;
  175. x4->params.i_deblocking_filter_beta = avctx->deblockbeta;
  176. x4->params.rc.i_qp_min = avctx->qmin;
  177. x4->params.rc.i_qp_max = avctx->qmax;
  178. x4->params.rc.i_qp_step = avctx->max_qdiff;
  179. x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
  180. x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */
  181. x4->params.rc.f_complexity_blur = avctx->complexityblur;
  182. x4->params.i_frame_reference = avctx->refs;
  183. x4->params.analyse.inter = 0;
  184. if (avctx->partitions) {
  185. if (avctx->partitions & X264_PART_I4X4)
  186. x4->params.analyse.inter |= X264_ANALYSE_I4x4;
  187. if (avctx->partitions & X264_PART_I8X8)
  188. x4->params.analyse.inter |= X264_ANALYSE_I8x8;
  189. if (avctx->partitions & X264_PART_P8X8)
  190. x4->params.analyse.inter |= X264_ANALYSE_PSUB16x16;
  191. if (avctx->partitions & X264_PART_P4X4)
  192. x4->params.analyse.inter |= X264_ANALYSE_PSUB8x8;
  193. if (avctx->partitions & X264_PART_B8X8)
  194. x4->params.analyse.inter |= X264_ANALYSE_BSUB16x16;
  195. }
  196. x4->params.analyse.i_direct_mv_pred = avctx->directpred;
  197. if (avctx->me_method == ME_EPZS)
  198. x4->params.analyse.i_me_method = X264_ME_DIA;
  199. else if (avctx->me_method == ME_HEX)
  200. x4->params.analyse.i_me_method = X264_ME_HEX;
  201. else if (avctx->me_method == ME_UMH)
  202. x4->params.analyse.i_me_method = X264_ME_UMH;
  203. else if (avctx->me_method == ME_FULL)
  204. x4->params.analyse.i_me_method = X264_ME_ESA;
  205. else if (avctx->me_method == ME_TESA)
  206. x4->params.analyse.i_me_method = X264_ME_TESA;
  207. else x4->params.analyse.i_me_method = X264_ME_HEX;
  208. x4->params.analyse.b_psy = avctx->flags2 & CODEC_FLAG2_PSY;
  209. x4->params.analyse.i_me_range = avctx->me_range;
  210. x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
  211. x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
  212. x4->params.analyse.i_trellis = avctx->trellis;
  213. x4->params.analyse.i_noise_reduction = avctx->noise_reduction;
  214. if (avctx->level > 0)
  215. x4->params.i_level_idc = avctx->level;
  216. if (x4->preset || x4->tune)
  217. if (x264_param_default_preset(&x4->params, x4->preset, x4->tune) < 0) {
  218. av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", x4->preset, x4->tune);
  219. return AVERROR(EINVAL);
  220. }
  221. x4->params.pf_log = X264_log;
  222. x4->params.p_log_private = avctx;
  223. x4->params.i_log_level = X264_LOG_DEBUG;
  224. if (avctx->bit_rate) {
  225. x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
  226. x4->params.rc.i_rc_method = X264_RC_ABR;
  227. }
  228. x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
  229. x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
  230. x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1;
  231. if (avctx->flags & CODEC_FLAG_PASS2) {
  232. x4->params.rc.b_stat_read = 1;
  233. } else {
  234. #if FF_API_X264_GLOBAL_OPTS
  235. if (avctx->crf) {
  236. x4->params.rc.i_rc_method = X264_RC_CRF;
  237. x4->params.rc.f_rf_constant = avctx->crf;
  238. x4->params.rc.f_rf_constant_max = avctx->crf_max;
  239. } else if (avctx->cqp > -1) {
  240. x4->params.rc.i_rc_method = X264_RC_CQP;
  241. x4->params.rc.i_qp_constant = avctx->cqp;
  242. }
  243. #endif
  244. if (x4->crf >= 0) {
  245. x4->params.rc.i_rc_method = X264_RC_CRF;
  246. x4->params.rc.f_rf_constant = x4->crf;
  247. } else if (x4->cqp >= 0) {
  248. x4->params.rc.i_rc_method = X264_RC_CQP;
  249. x4->params.rc.i_qp_constant = x4->cqp;
  250. }
  251. if (x4->crf_max >= 0)
  252. x4->params.rc.f_rf_constant_max = x4->crf_max;
  253. }
  254. if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy &&
  255. (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
  256. x4->params.rc.f_vbv_buffer_init =
  257. (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size;
  258. }
  259. x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE);
  260. x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor);
  261. x4->params.rc.f_pb_factor = avctx->b_quant_factor;
  262. x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;
  263. #if FF_API_X264_GLOBAL_OPTS
  264. if (avctx->aq_mode >= 0)
  265. x4->params.rc.i_aq_mode = avctx->aq_mode;
  266. if (avctx->aq_strength >= 0)
  267. x4->params.rc.f_aq_strength = avctx->aq_strength;
  268. if (avctx->psy_rd >= 0)
  269. x4->params.analyse.f_psy_rd = avctx->psy_rd;
  270. if (avctx->psy_trellis >= 0)
  271. x4->params.analyse.f_psy_trellis = avctx->psy_trellis;
  272. if (avctx->rc_lookahead >= 0)
  273. x4->params.rc.i_lookahead = avctx->rc_lookahead;
  274. if (avctx->weighted_p_pred >= 0)
  275. x4->params.analyse.i_weighted_pred = avctx->weighted_p_pred;
  276. x4->params.analyse.b_ssim = avctx->flags2 & CODEC_FLAG2_SSIM;
  277. x4->params.b_intra_refresh = avctx->flags2 & CODEC_FLAG2_INTRA_REFRESH;
  278. x4->params.i_bframe_pyramid = avctx->flags2 & CODEC_FLAG2_BPYRAMID ? X264_B_PYRAMID_NORMAL : X264_B_PYRAMID_NONE;
  279. x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED;
  280. x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS;
  281. x4->params.analyse.b_transform_8x8 = avctx->flags2 & CODEC_FLAG2_8X8DCT;
  282. x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP;
  283. x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD;
  284. #endif
  285. if (x4->aq_mode >= 0)
  286. x4->params.rc.i_aq_mode = x4->aq_mode;
  287. if (x4->aq_strength >= 0)
  288. x4->params.rc.f_aq_strength = x4->aq_strength;
  289. if (x4->psy_rd && x264_param_parse(&x4->params, "psy-rd", x4->psy_rd) < 0) {
  290. av_log(avctx, AV_LOG_ERROR, "Error parsing option 'psy-rd' with value '%s'.\n", x4->psy_rd);
  291. return AVERROR(EINVAL);
  292. }
  293. if (x4->rc_lookahead >= 0)
  294. x4->params.rc.i_lookahead = x4->rc_lookahead;
  295. if (x4->weightp >= 0)
  296. x4->params.analyse.i_weighted_pred = x4->weightp;
  297. if (x4->weightb >= 0)
  298. x4->params.analyse.b_weighted_bipred = x4->weightb;
  299. if (x4->ssim >= 0)
  300. x4->params.analyse.b_ssim = x4->ssim;
  301. if (x4->intra_refresh >= 0)
  302. x4->params.b_intra_refresh = x4->intra_refresh;
  303. if (x4->b_pyramid >= 0)
  304. x4->params.i_bframe_pyramid = x4->b_pyramid;
  305. if (x4->mixed_refs >= 0)
  306. x4->params.analyse.b_mixed_references = x4->mixed_refs;
  307. if (x4->dct8x8 >= 0)
  308. x4->params.analyse.b_transform_8x8 = x4->dct8x8;
  309. if (x4->fast_pskip >= 0)
  310. x4->params.analyse.b_fast_pskip = x4->fast_pskip;
  311. if (x4->aud >= 0)
  312. x4->params.b_aud = x4->aud;
  313. if (x4->fastfirstpass)
  314. x264_param_apply_fastfirstpass(&x4->params);
  315. if (x4->profile)
  316. if (x264_param_apply_profile(&x4->params, x4->profile) < 0) {
  317. av_log(avctx, AV_LOG_ERROR, "Error setting profile %s.\n", x4->profile);
  318. return AVERROR(EINVAL);
  319. }
  320. x4->params.i_width = avctx->width;
  321. x4->params.i_height = avctx->height;
  322. x4->params.vui.i_sar_width = avctx->sample_aspect_ratio.num;
  323. x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den;
  324. x4->params.i_fps_num = x4->params.i_timebase_den = avctx->time_base.den;
  325. x4->params.i_fps_den = x4->params.i_timebase_num = avctx->time_base.num;
  326. x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR;
  327. x4->params.i_threads = avctx->thread_count;
  328. x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT;
  329. x4->params.b_open_gop = !(avctx->flags & CODEC_FLAG_CLOSED_GOP);
  330. x4->params.i_slice_count = avctx->slices;
  331. x4->params.vui.b_fullrange = avctx->pix_fmt == PIX_FMT_YUVJ420P;
  332. if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER)
  333. x4->params.b_repeat_headers = 0;
  334. // update AVCodecContext with x264 parameters
  335. avctx->has_b_frames = x4->params.i_bframe ?
  336. x4->params.i_bframe_pyramid ? 2 : 1 : 0;
  337. avctx->bit_rate = x4->params.rc.i_bitrate*1000;
  338. #if FF_API_X264_GLOBAL_OPTS
  339. avctx->crf = x4->params.rc.f_rf_constant;
  340. #endif
  341. x4->enc = x264_encoder_open(&x4->params);
  342. if (!x4->enc)
  343. return -1;
  344. avctx->coded_frame = &x4->out_pic;
  345. if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
  346. x264_nal_t *nal;
  347. int nnal, s, i;
  348. s = x264_encoder_headers(x4->enc, &nal, &nnal);
  349. for (i = 0; i < nnal; i++)
  350. if (nal[i].i_type == NAL_SEI)
  351. av_log(avctx, AV_LOG_INFO, "%s\n", nal[i].p_payload+25);
  352. avctx->extradata = av_malloc(s);
  353. avctx->extradata_size = encode_nals(avctx, avctx->extradata, s, nal, nnal, 1);
  354. }
  355. return 0;
  356. }
  357. #define OFFSET(x) offsetof(X264Context, x)
  358. #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  359. static const AVOption options[] = {
  360. { "preset", "Set the encoding preset (cf. x264 --fullhelp)", OFFSET(preset), FF_OPT_TYPE_STRING, { .str = "medium" }, 0, 0, VE},
  361. { "tune", "Tune the encoding params (cf. x264 --fullhelp)", OFFSET(tune), FF_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
  362. { "profile", "Set profile restrictions (cf. x264 --fullhelp) ", OFFSET(profile), FF_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
  363. { "fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), FF_OPT_TYPE_INT, { 1 }, 0, 1, VE},
  364. { "crf", "Select the quality for constant quality mode", OFFSET(crf), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE },
  365. { "crf_max", "In CRF mode, prevents VBV from lowering quality beyond this point.",OFFSET(crf_max), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE },
  366. { "qp", "Constant quantization parameter rate control method",OFFSET(cqp), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE },
  367. { "aq-mode", "AQ method", OFFSET(aq_mode), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "aq_mode"},
  368. { "none", NULL, 0, FF_OPT_TYPE_CONST, {X264_AQ_NONE}, INT_MIN, INT_MAX, VE, "aq_mode" },
  369. { "variance", "Variance AQ (complexity mask)", 0, FF_OPT_TYPE_CONST, {X264_AQ_VARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" },
  370. { "autovariance", "Auto-variance AQ (experimental)", 0, FF_OPT_TYPE_CONST, {X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" },
  371. { "aq-strength", "AQ strength. Reduces blocking and blurring in flat and textured areas.", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, {-1}, -1, FLT_MAX, VE},
  372. { "psy-rd", "Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.", OFFSET(psy_rd), FF_OPT_TYPE_STRING, {0 }, 0, 0, VE},
  373. { "rc-lookahead", "Number of frames to look ahead for frametype and ratecontrol", OFFSET(rc_lookahead), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE },
  374. { "weightb", "Weighted prediction for B-frames.", OFFSET(weightb), FF_OPT_TYPE_INT, {-1 }, -1, 1, VE },
  375. { "weightp", "Weighted prediction analysis method.", OFFSET(weightp), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "weightp" },
  376. { "none", NULL, 0, FF_OPT_TYPE_CONST, {X264_WEIGHTP_NONE}, INT_MIN, INT_MAX, VE, "weightp" },
  377. { "simple", NULL, 0, FF_OPT_TYPE_CONST, {X264_WEIGHTP_SIMPLE}, INT_MIN, INT_MAX, VE, "weightp" },
  378. { "smart", NULL, 0, FF_OPT_TYPE_CONST, {X264_WEIGHTP_SMART}, INT_MIN, INT_MAX, VE, "weightp" },
  379. { "ssim", "Calculate and print SSIM stats.", OFFSET(ssim), FF_OPT_TYPE_INT, {-1 }, -1, 1, VE },
  380. { "intra-refresh", "Use Periodic Intra Refresh instead of IDR frames.",OFFSET(intra_refresh),FF_OPT_TYPE_INT, {-1 }, -1, 1, VE },
  381. { "b-pyramid", "Keep some B-frames as references.", OFFSET(b_pyramid), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "b_pyramid" },
  382. { "none", NULL, 0, FF_OPT_TYPE_CONST, {X264_B_PYRAMID_NONE}, INT_MIN, INT_MAX, VE, "b_pyramid" },
  383. { "strict", "Strictly hierarchical pyramid", 0, FF_OPT_TYPE_CONST, {X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX, VE, "b_pyramid" },
  384. { "normal", "Non-strict (not Blu-ray compatible)", 0, FF_OPT_TYPE_CONST, {X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX, VE, "b_pyramid" },
  385. { "mixed-refs", "One reference per partition, as opposed to one reference per macroblock", OFFSET(mixed_refs), FF_OPT_TYPE_INT, {-1}, -1, 1, VE },
  386. { "8x8dct", "High profile 8x8 transform.", OFFSET(dct8x8), FF_OPT_TYPE_INT, {-1 }, -1, 1, VE},
  387. { "fast-pskip", NULL, OFFSET(fast_pskip), FF_OPT_TYPE_INT, {-1 }, -1, 1, VE},
  388. { "aud", "Use access unit delimiters.", OFFSET(aud), FF_OPT_TYPE_INT, {-1 }, -1, 1, VE},
  389. { NULL },
  390. };
  391. static const AVClass class = {
  392. .class_name = "libx264",
  393. .item_name = av_default_item_name,
  394. .option = options,
  395. .version = LIBAVUTIL_VERSION_INT,
  396. };
  397. static const AVCodecDefault x264_defaults[] = {
  398. { "b", "0" },
  399. { NULL },
  400. };
  401. AVCodec ff_libx264_encoder = {
  402. .name = "libx264",
  403. .type = AVMEDIA_TYPE_VIDEO,
  404. .id = CODEC_ID_H264,
  405. .priv_data_size = sizeof(X264Context),
  406. .init = X264_init,
  407. .encode = X264_frame,
  408. .close = X264_close,
  409. .capabilities = CODEC_CAP_DELAY,
  410. .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV420P, PIX_FMT_YUVJ420P, PIX_FMT_NONE },
  411. .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
  412. .priv_class = &class,
  413. .defaults = x264_defaults,
  414. };