| 1061 | } |
| 1062 | |
| 1063 | static av_cold int X264_init(AVCodecContext *avctx) |
| 1064 | { |
| 1065 | X264Context *x4 = avctx->priv_data; |
| 1066 | AVCPBProperties *cpb_props; |
| 1067 | int sw,sh; |
| 1068 | int ret; |
| 1069 | |
| 1070 | if (avctx->global_quality > 0) |
| 1071 | av_log(avctx, AV_LOG_WARNING, "-qscale is ignored, -crf is recommended.\n"); |
| 1072 | |
| 1073 | #if CONFIG_LIBX262_ENCODER |
| 1074 | if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO) { |
| 1075 | x4->params.b_mpeg2 = 1; |
| 1076 | x264_param_default_mpeg2(&x4->params); |
| 1077 | } else |
| 1078 | #endif |
| 1079 | x264_param_default(&x4->params); |
| 1080 | |
| 1081 | x4->params.b_deblocking_filter = avctx->flags & AV_CODEC_FLAG_LOOP_FILTER; |
| 1082 | |
| 1083 | if (x4->preset || x4->tune) |
| 1084 | if (x264_param_default_preset(&x4->params, x4->preset, x4->tune) < 0) { |
| 1085 | int i; |
| 1086 | av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", x4->preset, x4->tune); |
| 1087 | av_log(avctx, AV_LOG_INFO, "Possible presets:"); |
| 1088 | for (i = 0; x264_preset_names[i]; i++) |
| 1089 | av_log(avctx, AV_LOG_INFO, " %s", x264_preset_names[i]); |
| 1090 | av_log(avctx, AV_LOG_INFO, "\n"); |
| 1091 | av_log(avctx, AV_LOG_INFO, "Possible tunes:"); |
| 1092 | for (i = 0; x264_tune_names[i]; i++) |
| 1093 | av_log(avctx, AV_LOG_INFO, " %s", x264_tune_names[i]); |
| 1094 | av_log(avctx, AV_LOG_INFO, "\n"); |
| 1095 | return AVERROR(EINVAL); |
| 1096 | } |
| 1097 | |
| 1098 | if (avctx->level > 0) |
| 1099 | x4->params.i_level_idc = avctx->level; |
| 1100 | |
| 1101 | x4->params.pf_log = X264_log; |
| 1102 | x4->params.p_log_private = avctx; |
| 1103 | x4->params.i_log_level = X264_LOG_DEBUG; |
| 1104 | x4->params.i_csp = convert_pix_fmt(avctx->pix_fmt); |
| 1105 | x4->params.i_bitdepth = av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth; |
| 1106 | |
| 1107 | PARSE_X264_OPT("weightp", wpredp); |
| 1108 | |
| 1109 | if (avctx->bit_rate) { |
| 1110 | if (avctx->bit_rate / 1000 > INT_MAX || avctx->rc_max_rate / 1000 > INT_MAX) { |
| 1111 | av_log(avctx, AV_LOG_ERROR, "bit_rate and rc_max_rate > %d000 not supported by libx264\n", INT_MAX); |
| 1112 | return AVERROR(EINVAL); |
| 1113 | } |
| 1114 | x4->params.rc.i_bitrate = avctx->bit_rate / 1000; |
| 1115 | x4->params.rc.i_rc_method = X264_RC_ABR; |
| 1116 | } |
| 1117 | x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000; |
| 1118 | x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000; |
| 1119 | x4->params.rc.b_stat_write = avctx->flags & AV_CODEC_FLAG_PASS1; |
| 1120 | if (avctx->flags & AV_CODEC_FLAG_PASS2) { |
nothing calls this directly
no test coverage detected