| 1048 | } |
| 1049 | |
| 1050 | static av_cold int encode_init(AVCodecContext *avctx) |
| 1051 | { |
| 1052 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 1053 | MPEG12EncContext *const mpeg12 = avctx->priv_data; |
| 1054 | MPVMainEncContext *const m = &mpeg12->mpeg; |
| 1055 | MPVEncContext *const s = &m->s; |
| 1056 | int ret; |
| 1057 | int max_size = avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO ? 16383 : 4095; |
| 1058 | |
| 1059 | if (avctx->width > max_size || avctx->height > max_size) { |
| 1060 | av_log(avctx, AV_LOG_ERROR, "%s does not support resolutions above %dx%d\n", |
| 1061 | CONFIG_SMALL ? avctx->codec->name : avctx->codec->long_name, |
| 1062 | max_size, max_size); |
| 1063 | return AVERROR(EINVAL); |
| 1064 | } |
| 1065 | if ((avctx->width & 0xFFF) == 0 && (avctx->height & 0xFFF) == 1) { |
| 1066 | av_log(avctx, AV_LOG_ERROR, "Width / Height is invalid for MPEG2\n"); |
| 1067 | return AVERROR(EINVAL); |
| 1068 | } |
| 1069 | |
| 1070 | if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) { |
| 1071 | if ((avctx->width & 0xFFF) == 0 || (avctx->height & 0xFFF) == 0) { |
| 1072 | av_log(avctx, AV_LOG_ERROR, "Width or Height are not allowed to be multiples of 4096\n" |
| 1073 | "add '-strict %d' if you want to use them anyway.\n", FF_COMPLIANCE_UNOFFICIAL); |
| 1074 | return AVERROR(EINVAL); |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | if (s->c.q_scale_type == 1) { |
| 1079 | if (avctx->qmax > 28) { |
| 1080 | av_log(avctx, AV_LOG_ERROR, |
| 1081 | "non linear quant only supports qmax <= 28 currently\n"); |
| 1082 | return AVERROR_PATCHWELCOME; |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | if (avctx->profile == AV_PROFILE_UNKNOWN) { |
| 1087 | if (avctx->level != AV_LEVEL_UNKNOWN) { |
| 1088 | av_log(avctx, AV_LOG_ERROR, "Set profile and level\n"); |
| 1089 | return AVERROR(EINVAL); |
| 1090 | } |
| 1091 | /* Main or 4:2:2 */ |
| 1092 | avctx->profile = avctx->pix_fmt == AV_PIX_FMT_YUV420P ? AV_PROFILE_MPEG2_MAIN |
| 1093 | : AV_PROFILE_MPEG2_422; |
| 1094 | } |
| 1095 | if (avctx->level == AV_LEVEL_UNKNOWN) { |
| 1096 | if (avctx->profile == AV_PROFILE_MPEG2_422) { /* 4:2:2 */ |
| 1097 | if (avctx->width <= 720 && avctx->height <= 608) |
| 1098 | avctx->level = 5; /* Main */ |
| 1099 | else |
| 1100 | avctx->level = 2; /* High */ |
| 1101 | } else { |
| 1102 | if (avctx->profile != AV_PROFILE_MPEG2_HIGH && |
| 1103 | avctx->pix_fmt != AV_PIX_FMT_YUV420P) { |
| 1104 | av_log(avctx, AV_LOG_ERROR, |
| 1105 | "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n"); |
| 1106 | return AVERROR(EINVAL); |
| 1107 | } |
nothing calls this directly
no test coverage detected