This has the advantage that one does not waste some allocations if one errors out because of these checks.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -152,19 +152,16 @@ static av_cold int encode_init(AVCodecContext *avctx) · 151 unmodified lines | |||
| 152 | max_size, max_size); | 152 | max_size, max_size); |
| 153 | return AVERROR(EINVAL); | 153 | return AVERROR(EINVAL); |
| 154 | } | 154 | } |
| 155 | if ((avctx->width & 0xFFF) == 0 && (avctx->height & 0xFFF) == 1) { | ||
| 156 | av_log(avctx, AV_LOG_ERROR, "Width / Height is invalid for MPEG2\n"); | ||
| 157 | return AVERROR(EINVAL); | ||
| 158 | } | ||
| 155 | 159 | ||
| 156 | if ((ret = ff_mpv_encode_init(avctx)) < 0) | 160 | if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) { |
| 157 | return ret; | 161 | if ((avctx->width & 0xFFF) == 0 || (avctx->height & 0xFFF) == 0) { |
| 158 | 162 | av_log(avctx, AV_LOG_ERROR, "Width or Height are not allowed to be multiples of 4096\n" | |
| 159 | if (find_frame_rate_index(s) < 0) { | 163 | "add '-strict %d' if you want to use them anyway.\n", FF_COMPLIANCE_UNOFFICIAL); |
| 160 | if (s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { | ||
| 161 | av_log(avctx, AV_LOG_ERROR, "MPEG-1/2 does not support %d/%d fps\n", | ||
| 162 | avctx->time_base.den, avctx->time_base.num); | ||
| 163 | return AVERROR(EINVAL); | 164 | return AVERROR(EINVAL); |
| 164 | } else { | ||
| 165 | av_log(avctx, AV_LOG_INFO, | ||
| 166 | "MPEG-1/2 does not support %d/%d fps, there may be AV sync issues\n", | ||
| 167 | avctx->time_base.den, avctx->time_base.num); | ||
| 168 | } | 165 | } |
| 169 | } | 166 | } |
| 170 | 167 | ||
| @@ -174,9 +171,9 @@ static av_cold int encode_init(AVCodecContext *avctx) · 3 unmodified lines | |||
| 174 | return AVERROR(EINVAL); | 171 | return AVERROR(EINVAL); |
| 175 | } | 172 | } |
| 176 | /* Main or 4:2:2 */ | 173 | /* Main or 4:2:2 */ |
| 177 | avctx->profile = s->chroma_format == CHROMA_420 ? FF_PROFILE_MPEG2_MAIN : FF_PROFILE_MPEG2_422; | 174 | avctx->profile = avctx->pix_fmt == AV_PIX_FMT_YUV420P ? FF_PROFILE_MPEG2_MAIN |
| 175 | : FF_PROFILE_MPEG2_422; | ||
| 178 | } | 176 | } |
| 179 | |||
| 180 | if (avctx->level == FF_LEVEL_UNKNOWN) { | 177 | if (avctx->level == FF_LEVEL_UNKNOWN) { |
| 181 | if (avctx->profile == FF_PROFILE_MPEG2_422) { /* 4:2:2 */ | 178 | if (avctx->profile == FF_PROFILE_MPEG2_422) { /* 4:2:2 */ |
| 182 | if (avctx->width <= 720 && avctx->height <= 608) | 179 | if (avctx->width <= 720 && avctx->height <= 608) |
| @@ -184,7 +181,8 @@ static av_cold int encode_init(AVCodecContext *avctx) · 1 unmodified line | |||
| 184 | else | 181 | else |
| 185 | avctx->level = 2; /* High */ | 182 | avctx->level = 2; /* High */ |
| 186 | } else { | 183 | } else { |
| 187 | if (avctx->profile != FF_PROFILE_MPEG2_HIGH && s->chroma_format != CHROMA_420) { | 184 | if (avctx->profile != FF_PROFILE_MPEG2_HIGH && |
| 185 | avctx->pix_fmt != AV_PIX_FMT_YUV420P) { | ||
| 188 | av_log(avctx, AV_LOG_ERROR, | 186 | av_log(avctx, AV_LOG_ERROR, |
| 189 | "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n"); | 187 | "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n"); |
| 190 | return AVERROR(EINVAL); | 188 | return AVERROR(EINVAL); |
| @@ -198,16 +196,18 @@ static av_cold int encode_init(AVCodecContext *avctx) · 7 unmodified lines | |||
| 198 | } | 196 | } |
| 199 | } | 197 | } |
| 200 | 198 | ||
| 201 | if ((avctx->width & 0xFFF) == 0 && (avctx->height & 0xFFF) == 1) { | 199 | if ((ret = ff_mpv_encode_init(avctx)) < 0) |
| 202 | av_log(avctx, AV_LOG_ERROR, "Width / Height is invalid for MPEG2\n"); | 200 | return ret; |
| 203 | return AVERROR(EINVAL); | ||
| 204 | } | ||
| 205 | 201 | ||
| 206 | if (s->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) { | 202 | if (find_frame_rate_index(s) < 0) { |
| 207 | if ((avctx->width & 0xFFF) == 0 || (avctx->height & 0xFFF) == 0) { | 203 | if (s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { |
| 208 | av_log(avctx, AV_LOG_ERROR, "Width or Height are not allowed to be multiples of 4096\n" | 204 | av_log(avctx, AV_LOG_ERROR, "MPEG-1/2 does not support %d/%d fps\n", |
| 209 | "add '-strict %d' if you want to use them anyway.\n", FF_COMPLIANCE_UNOFFICIAL); | 205 | avctx->time_base.den, avctx->time_base.num); |
| 210 | return AVERROR(EINVAL); | 206 | return AVERROR(EINVAL); |
| 207 | } else { | ||
| 208 | av_log(avctx, AV_LOG_INFO, | ||
| 209 | "MPEG-1/2 does not support %d/%d fps, there may be AV sync issues\n", | ||
| 210 | avctx->time_base.den, avctx->time_base.num); | ||
| 211 | } | 211 | } |
| 212 | } | 212 | } |
| 213 | 213 | ||