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.

562 lines
22KB

  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 "libavutil/pixdesc.h"
  23. #include "avcodec.h"
  24. #include "internal.h"
  25. #include <x264.h>
  26. #include <float.h>
  27. #include <math.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. typedef struct X264Context {
  32. AVClass *class;
  33. x264_param_t params;
  34. x264_t *enc;
  35. x264_picture_t pic;
  36. uint8_t *sei;
  37. int sei_size;
  38. AVFrame out_pic;
  39. char *preset;
  40. char *tune;
  41. char *profile;
  42. int fastfirstpass;
  43. float crf;
  44. float crf_max;
  45. int cqp;
  46. int aq_mode;
  47. float aq_strength;
  48. char *psy_rd;
  49. int psy;
  50. int rc_lookahead;
  51. int weightp;
  52. int weightb;
  53. int ssim;
  54. int intra_refresh;
  55. int b_bias;
  56. int b_pyramid;
  57. int mixed_refs;
  58. int dct8x8;
  59. int fast_pskip;
  60. int aud;
  61. int mbtree;
  62. char *deblock;
  63. float cplxblur;
  64. char *partitions;
  65. int direct_pred;
  66. int slice_max_size;
  67. char *stats;
  68. } X264Context;
  69. static void X264_log(void *p, int level, const char *fmt, va_list args)
  70. {
  71. static const int level_map[] = {
  72. [X264_LOG_ERROR] = AV_LOG_ERROR,
  73. [X264_LOG_WARNING] = AV_LOG_WARNING,
  74. [X264_LOG_INFO] = AV_LOG_INFO,
  75. [X264_LOG_DEBUG] = AV_LOG_DEBUG
  76. };
  77. if (level < 0 || level > X264_LOG_DEBUG)
  78. return;
  79. av_vlog(p, level_map[level], fmt, args);
  80. }
  81. static int encode_nals(AVCodecContext *ctx, AVPacket *pkt,
  82. x264_nal_t *nals, int nnal)
  83. {
  84. X264Context *x4 = ctx->priv_data;
  85. uint8_t *p;
  86. int i, size = x4->sei_size, ret;
  87. if (!nnal)
  88. return 0;
  89. for (i = 0; i < nnal; i++)
  90. size += nals[i].i_payload;
  91. if ((ret = ff_alloc_packet(pkt, size)) < 0)
  92. return ret;
  93. p = pkt->data;
  94. /* Write the SEI as part of the first frame. */
  95. if (x4->sei_size > 0 && nnal > 0) {
  96. memcpy(p, x4->sei, x4->sei_size);
  97. p += x4->sei_size;
  98. x4->sei_size = 0;
  99. }
  100. for (i = 0; i < nnal; i++){
  101. memcpy(p, nals[i].p_payload, nals[i].i_payload);
  102. p += nals[i].i_payload;
  103. }
  104. return 1;
  105. }
  106. static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
  107. int *got_packet)
  108. {
  109. X264Context *x4 = ctx->priv_data;
  110. x264_nal_t *nal;
  111. int nnal, i, ret;
  112. x264_picture_t pic_out;
  113. x264_picture_init( &x4->pic );
  114. x4->pic.img.i_csp = x4->params.i_csp;
  115. if (x264_bit_depth > 8)
  116. x4->pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
  117. x4->pic.img.i_plane = 3;
  118. if (frame) {
  119. for (i = 0; i < 3; i++) {
  120. x4->pic.img.plane[i] = frame->data[i];
  121. x4->pic.img.i_stride[i] = frame->linesize[i];
  122. }
  123. x4->pic.i_pts = frame->pts;
  124. x4->pic.i_type =
  125. frame->pict_type == AV_PICTURE_TYPE_I ? X264_TYPE_KEYFRAME :
  126. frame->pict_type == AV_PICTURE_TYPE_P ? X264_TYPE_P :
  127. frame->pict_type == AV_PICTURE_TYPE_B ? X264_TYPE_B :
  128. X264_TYPE_AUTO;
  129. if (x4->params.b_tff != frame->top_field_first) {
  130. x4->params.b_tff = frame->top_field_first;
  131. x264_encoder_reconfig(x4->enc, &x4->params);
  132. }
  133. }
  134. do {
  135. if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
  136. return -1;
  137. ret = encode_nals(ctx, pkt, nal, nnal);
  138. if (ret < 0)
  139. return -1;
  140. } while (!ret && !frame && x264_encoder_delayed_frames(x4->enc));
  141. pkt->pts = pic_out.i_pts;
  142. pkt->dts = pic_out.i_dts;
  143. switch (pic_out.i_type) {
  144. case X264_TYPE_IDR:
  145. case X264_TYPE_I:
  146. x4->out_pic.pict_type = AV_PICTURE_TYPE_I;
  147. break;
  148. case X264_TYPE_P:
  149. x4->out_pic.pict_type = AV_PICTURE_TYPE_P;
  150. break;
  151. case X264_TYPE_B:
  152. case X264_TYPE_BREF:
  153. x4->out_pic.pict_type = AV_PICTURE_TYPE_B;
  154. break;
  155. }
  156. pkt->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe;
  157. if (ret)
  158. x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
  159. *got_packet = ret;
  160. return 0;
  161. }
  162. static av_cold int X264_close(AVCodecContext *avctx)
  163. {
  164. X264Context *x4 = avctx->priv_data;
  165. av_freep(&avctx->extradata);
  166. av_free(x4->sei);
  167. if (x4->enc)
  168. x264_encoder_close(x4->enc);
  169. return 0;
  170. }
  171. static int convert_pix_fmt(enum PixelFormat pix_fmt)
  172. {
  173. switch (pix_fmt) {
  174. case PIX_FMT_YUV420P:
  175. case PIX_FMT_YUVJ420P:
  176. case PIX_FMT_YUV420P9:
  177. case PIX_FMT_YUV420P10: return X264_CSP_I420;
  178. case PIX_FMT_YUV422P:
  179. case PIX_FMT_YUV422P10: return X264_CSP_I422;
  180. case PIX_FMT_YUV444P:
  181. case PIX_FMT_YUV444P9:
  182. case PIX_FMT_YUV444P10: return X264_CSP_I444;
  183. };
  184. return 0;
  185. }
  186. #define PARSE_X264_OPT(name, var)\
  187. if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
  188. av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
  189. return AVERROR(EINVAL);\
  190. }
  191. static av_cold int X264_init(AVCodecContext *avctx)
  192. {
  193. X264Context *x4 = avctx->priv_data;
  194. x264_param_default(&x4->params);
  195. x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER;
  196. if (x4->preset || x4->tune)
  197. if (x264_param_default_preset(&x4->params, x4->preset, x4->tune) < 0) {
  198. av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", x4->preset, x4->tune);
  199. return AVERROR(EINVAL);
  200. }
  201. if (avctx->level > 0)
  202. x4->params.i_level_idc = avctx->level;
  203. x4->params.pf_log = X264_log;
  204. x4->params.p_log_private = avctx;
  205. x4->params.i_log_level = X264_LOG_DEBUG;
  206. x4->params.i_csp = convert_pix_fmt(avctx->pix_fmt);
  207. if (avctx->bit_rate) {
  208. x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
  209. x4->params.rc.i_rc_method = X264_RC_ABR;
  210. }
  211. x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
  212. x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
  213. x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1;
  214. if (avctx->flags & CODEC_FLAG_PASS2) {
  215. x4->params.rc.b_stat_read = 1;
  216. } else {
  217. if (x4->crf >= 0) {
  218. x4->params.rc.i_rc_method = X264_RC_CRF;
  219. x4->params.rc.f_rf_constant = x4->crf;
  220. } else if (x4->cqp >= 0) {
  221. x4->params.rc.i_rc_method = X264_RC_CQP;
  222. x4->params.rc.i_qp_constant = x4->cqp;
  223. }
  224. if (x4->crf_max >= 0)
  225. x4->params.rc.f_rf_constant_max = x4->crf_max;
  226. }
  227. if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy &&
  228. (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
  229. x4->params.rc.f_vbv_buffer_init =
  230. (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size;
  231. }
  232. x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor);
  233. x4->params.rc.f_pb_factor = avctx->b_quant_factor;
  234. x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;
  235. if (avctx->me_method == ME_EPZS)
  236. x4->params.analyse.i_me_method = X264_ME_DIA;
  237. else if (avctx->me_method == ME_HEX)
  238. x4->params.analyse.i_me_method = X264_ME_HEX;
  239. else if (avctx->me_method == ME_UMH)
  240. x4->params.analyse.i_me_method = X264_ME_UMH;
  241. else if (avctx->me_method == ME_FULL)
  242. x4->params.analyse.i_me_method = X264_ME_ESA;
  243. else if (avctx->me_method == ME_TESA)
  244. x4->params.analyse.i_me_method = X264_ME_TESA;
  245. if (avctx->gop_size >= 0)
  246. x4->params.i_keyint_max = avctx->gop_size;
  247. if (avctx->max_b_frames >= 0)
  248. x4->params.i_bframe = avctx->max_b_frames;
  249. if (avctx->scenechange_threshold >= 0)
  250. x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
  251. if (avctx->qmin >= 0)
  252. x4->params.rc.i_qp_min = avctx->qmin;
  253. if (avctx->qmax >= 0)
  254. x4->params.rc.i_qp_max = avctx->qmax;
  255. if (avctx->max_qdiff >= 0)
  256. x4->params.rc.i_qp_step = avctx->max_qdiff;
  257. if (avctx->qblur >= 0)
  258. x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */
  259. if (avctx->qcompress >= 0)
  260. x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
  261. if (avctx->refs >= 0)
  262. x4->params.i_frame_reference = avctx->refs;
  263. if (avctx->trellis >= 0)
  264. x4->params.analyse.i_trellis = avctx->trellis;
  265. if (avctx->me_range >= 0)
  266. x4->params.analyse.i_me_range = avctx->me_range;
  267. if (avctx->noise_reduction >= 0)
  268. x4->params.analyse.i_noise_reduction = avctx->noise_reduction;
  269. if (avctx->me_subpel_quality >= 0)
  270. x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
  271. if (avctx->b_frame_strategy >= 0)
  272. x4->params.i_bframe_adaptive = avctx->b_frame_strategy;
  273. if (avctx->keyint_min >= 0)
  274. x4->params.i_keyint_min = avctx->keyint_min;
  275. if (avctx->coder_type >= 0)
  276. x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC;
  277. if (avctx->me_cmp >= 0)
  278. x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
  279. if (x4->aq_mode >= 0)
  280. x4->params.rc.i_aq_mode = x4->aq_mode;
  281. if (x4->aq_strength >= 0)
  282. x4->params.rc.f_aq_strength = x4->aq_strength;
  283. PARSE_X264_OPT("psy-rd", psy_rd);
  284. PARSE_X264_OPT("deblock", deblock);
  285. PARSE_X264_OPT("partitions", partitions);
  286. PARSE_X264_OPT("stats", stats);
  287. if (x4->psy >= 0)
  288. x4->params.analyse.b_psy = x4->psy;
  289. if (x4->rc_lookahead >= 0)
  290. x4->params.rc.i_lookahead = x4->rc_lookahead;
  291. if (x4->weightp >= 0)
  292. x4->params.analyse.i_weighted_pred = x4->weightp;
  293. if (x4->weightb >= 0)
  294. x4->params.analyse.b_weighted_bipred = x4->weightb;
  295. if (x4->cplxblur >= 0)
  296. x4->params.rc.f_complexity_blur = x4->cplxblur;
  297. if (x4->ssim >= 0)
  298. x4->params.analyse.b_ssim = x4->ssim;
  299. if (x4->intra_refresh >= 0)
  300. x4->params.b_intra_refresh = x4->intra_refresh;
  301. if (x4->b_bias != INT_MIN)
  302. x4->params.i_bframe_bias = x4->b_bias;
  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->mbtree >= 0)
  314. x4->params.rc.b_mb_tree = x4->mbtree;
  315. if (x4->direct_pred >= 0)
  316. x4->params.analyse.i_direct_mv_pred = x4->direct_pred;
  317. if (x4->slice_max_size >= 0)
  318. x4->params.i_slice_max_size = x4->slice_max_size;
  319. if (x4->fastfirstpass)
  320. x264_param_apply_fastfirstpass(&x4->params);
  321. if (x4->profile)
  322. if (x264_param_apply_profile(&x4->params, x4->profile) < 0) {
  323. av_log(avctx, AV_LOG_ERROR, "Error setting profile %s.\n", x4->profile);
  324. return AVERROR(EINVAL);
  325. }
  326. x4->params.i_width = avctx->width;
  327. x4->params.i_height = avctx->height;
  328. x4->params.vui.i_sar_width = avctx->sample_aspect_ratio.num;
  329. x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den;
  330. x4->params.i_fps_num = x4->params.i_timebase_den = avctx->time_base.den;
  331. x4->params.i_fps_den = x4->params.i_timebase_num = avctx->time_base.num;
  332. x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR;
  333. x4->params.i_threads = avctx->thread_count;
  334. if (avctx->thread_type)
  335. x4->params.b_sliced_threads = avctx->thread_type == FF_THREAD_SLICE;
  336. x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT;
  337. x4->params.b_open_gop = !(avctx->flags & CODEC_FLAG_CLOSED_GOP);
  338. x4->params.i_slice_count = avctx->slices;
  339. x4->params.vui.b_fullrange = avctx->pix_fmt == PIX_FMT_YUVJ420P;
  340. if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER)
  341. x4->params.b_repeat_headers = 0;
  342. // update AVCodecContext with x264 parameters
  343. avctx->has_b_frames = x4->params.i_bframe ?
  344. x4->params.i_bframe_pyramid ? 2 : 1 : 0;
  345. if (avctx->max_b_frames < 0)
  346. avctx->max_b_frames = 0;
  347. avctx->bit_rate = x4->params.rc.i_bitrate*1000;
  348. x4->enc = x264_encoder_open(&x4->params);
  349. if (!x4->enc)
  350. return -1;
  351. avctx->coded_frame = &x4->out_pic;
  352. if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
  353. x264_nal_t *nal;
  354. uint8_t *p;
  355. int nnal, s, i;
  356. s = x264_encoder_headers(x4->enc, &nal, &nnal);
  357. avctx->extradata = p = av_malloc(s);
  358. for (i = 0; i < nnal; i++) {
  359. /* Don't put the SEI in extradata. */
  360. if (nal[i].i_type == NAL_SEI) {
  361. av_log(avctx, AV_LOG_INFO, "%s\n", nal[i].p_payload+25);
  362. x4->sei_size = nal[i].i_payload;
  363. x4->sei = av_malloc(x4->sei_size);
  364. memcpy(x4->sei, nal[i].p_payload, nal[i].i_payload);
  365. continue;
  366. }
  367. memcpy(p, nal[i].p_payload, nal[i].i_payload);
  368. p += nal[i].i_payload;
  369. }
  370. avctx->extradata_size = p - avctx->extradata;
  371. }
  372. return 0;
  373. }
  374. static const enum PixelFormat pix_fmts_8bit[] = {
  375. PIX_FMT_YUV420P,
  376. PIX_FMT_YUVJ420P,
  377. PIX_FMT_YUV422P,
  378. PIX_FMT_YUV444P,
  379. PIX_FMT_NONE
  380. };
  381. static const enum PixelFormat pix_fmts_9bit[] = {
  382. PIX_FMT_YUV420P9,
  383. PIX_FMT_YUV444P9,
  384. PIX_FMT_NONE
  385. };
  386. static const enum PixelFormat pix_fmts_10bit[] = {
  387. PIX_FMT_YUV420P10,
  388. PIX_FMT_YUV422P10,
  389. PIX_FMT_YUV444P10,
  390. PIX_FMT_NONE
  391. };
  392. static av_cold void X264_init_static(AVCodec *codec)
  393. {
  394. if (x264_bit_depth == 8)
  395. codec->pix_fmts = pix_fmts_8bit;
  396. else if (x264_bit_depth == 9)
  397. codec->pix_fmts = pix_fmts_9bit;
  398. else if (x264_bit_depth == 10)
  399. codec->pix_fmts = pix_fmts_10bit;
  400. }
  401. #define OFFSET(x) offsetof(X264Context, x)
  402. #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  403. static const AVOption options[] = {
  404. { "preset", "Set the encoding preset (cf. x264 --fullhelp)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "medium" }, 0, 0, VE},
  405. { "tune", "Tune the encoding params (cf. x264 --fullhelp)", OFFSET(tune), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
  406. { "profile", "Set profile restrictions (cf. x264 --fullhelp) ", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
  407. { "fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), AV_OPT_TYPE_INT, { 1 }, 0, 1, VE},
  408. { "crf", "Select the quality for constant quality mode", OFFSET(crf), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE },
  409. { "crf_max", "In CRF mode, prevents VBV from lowering quality beyond this point.",OFFSET(crf_max), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE },
  410. { "qp", "Constant quantization parameter rate control method",OFFSET(cqp), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE },
  411. { "aq-mode", "AQ method", OFFSET(aq_mode), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "aq_mode"},
  412. { "none", NULL, 0, AV_OPT_TYPE_CONST, {X264_AQ_NONE}, INT_MIN, INT_MAX, VE, "aq_mode" },
  413. { "variance", "Variance AQ (complexity mask)", 0, AV_OPT_TYPE_CONST, {X264_AQ_VARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" },
  414. { "autovariance", "Auto-variance AQ (experimental)", 0, AV_OPT_TYPE_CONST, {X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" },
  415. { "aq-strength", "AQ strength. Reduces blocking and blurring in flat and textured areas.", OFFSET(aq_strength), AV_OPT_TYPE_FLOAT, {-1}, -1, FLT_MAX, VE},
  416. { "psy", "Use psychovisual optimizations.", OFFSET(psy), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE },
  417. { "psy-rd", "Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.", OFFSET(psy_rd), AV_OPT_TYPE_STRING, {0 }, 0, 0, VE},
  418. { "rc-lookahead", "Number of frames to look ahead for frametype and ratecontrol", OFFSET(rc_lookahead), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE },
  419. { "weightb", "Weighted prediction for B-frames.", OFFSET(weightb), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE },
  420. { "weightp", "Weighted prediction analysis method.", OFFSET(weightp), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "weightp" },
  421. { "none", NULL, 0, AV_OPT_TYPE_CONST, {X264_WEIGHTP_NONE}, INT_MIN, INT_MAX, VE, "weightp" },
  422. { "simple", NULL, 0, AV_OPT_TYPE_CONST, {X264_WEIGHTP_SIMPLE}, INT_MIN, INT_MAX, VE, "weightp" },
  423. { "smart", NULL, 0, AV_OPT_TYPE_CONST, {X264_WEIGHTP_SMART}, INT_MIN, INT_MAX, VE, "weightp" },
  424. { "ssim", "Calculate and print SSIM stats.", OFFSET(ssim), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE },
  425. { "intra-refresh", "Use Periodic Intra Refresh instead of IDR frames.",OFFSET(intra_refresh),AV_OPT_TYPE_INT, {-1 }, -1, 1, VE },
  426. { "b-bias", "Influences how often B-frames are used", OFFSET(b_bias), AV_OPT_TYPE_INT, {INT_MIN}, INT_MIN, INT_MAX, VE },
  427. { "b-pyramid", "Keep some B-frames as references.", OFFSET(b_pyramid), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "b_pyramid" },
  428. { "none", NULL, 0, AV_OPT_TYPE_CONST, {X264_B_PYRAMID_NONE}, INT_MIN, INT_MAX, VE, "b_pyramid" },
  429. { "strict", "Strictly hierarchical pyramid", 0, AV_OPT_TYPE_CONST, {X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX, VE, "b_pyramid" },
  430. { "normal", "Non-strict (not Blu-ray compatible)", 0, AV_OPT_TYPE_CONST, {X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX, VE, "b_pyramid" },
  431. { "mixed-refs", "One reference per partition, as opposed to one reference per macroblock", OFFSET(mixed_refs), AV_OPT_TYPE_INT, {-1}, -1, 1, VE },
  432. { "8x8dct", "High profile 8x8 transform.", OFFSET(dct8x8), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
  433. { "fast-pskip", NULL, OFFSET(fast_pskip), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
  434. { "aud", "Use access unit delimiters.", OFFSET(aud), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
  435. { "mbtree", "Use macroblock tree ratecontrol.", OFFSET(mbtree), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
  436. { "deblock", "Loop filter parameters, in <alpha:beta> form.", OFFSET(deblock), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
  437. { "cplxblur", "Reduce fluctuations in QP (before curve compression)", OFFSET(cplxblur), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE},
  438. { "partitions", "A comma-separated list of partitions to consider. "
  439. "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all", OFFSET(partitions), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
  440. { "direct-pred", "Direct MV prediction mode", OFFSET(direct_pred), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "direct-pred" },
  441. { "none", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_NONE }, 0, 0, VE, "direct-pred" },
  442. { "spatial", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_SPATIAL }, 0, 0, VE, "direct-pred" },
  443. { "temporal", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_TEMPORAL }, 0, 0, VE, "direct-pred" },
  444. { "auto", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_AUTO }, 0, 0, VE, "direct-pred" },
  445. { "slice-max-size","Limit the size of each slice in bytes", OFFSET(slice_max_size),AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE },
  446. { "stats", "Filename for 2 pass stats", OFFSET(stats), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
  447. { NULL },
  448. };
  449. static const AVClass class = {
  450. .class_name = "libx264",
  451. .item_name = av_default_item_name,
  452. .option = options,
  453. .version = LIBAVUTIL_VERSION_INT,
  454. };
  455. static const AVCodecDefault x264_defaults[] = {
  456. { "b", "0" },
  457. { "bf", "-1" },
  458. { "g", "-1" },
  459. { "qmin", "-1" },
  460. { "qmax", "-1" },
  461. { "qdiff", "-1" },
  462. { "qblur", "-1" },
  463. { "qcomp", "-1" },
  464. { "refs", "-1" },
  465. { "sc_threshold", "-1" },
  466. { "trellis", "-1" },
  467. { "nr", "-1" },
  468. { "me_range", "-1" },
  469. { "me_method", "-1" },
  470. { "subq", "-1" },
  471. { "b_strategy", "-1" },
  472. { "keyint_min", "-1" },
  473. { "coder", "-1" },
  474. { "cmp", "-1" },
  475. { "threads", AV_STRINGIFY(X264_THREADS_AUTO) },
  476. { "thread_type", "0" },
  477. { NULL },
  478. };
  479. AVCodec ff_libx264_encoder = {
  480. .name = "libx264",
  481. .type = AVMEDIA_TYPE_VIDEO,
  482. .id = CODEC_ID_H264,
  483. .priv_data_size = sizeof(X264Context),
  484. .init = X264_init,
  485. .encode2 = X264_frame,
  486. .close = X264_close,
  487. .capabilities = CODEC_CAP_DELAY | CODEC_CAP_AUTO_THREADS,
  488. .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
  489. .priv_class = &class,
  490. .defaults = x264_defaults,
  491. .init_static_data = X264_init_static,
  492. };