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.

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