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 | 152 | max_size, max_size); |
| 153 | 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) | |
| 157 | − return ret; | |
| 158 | − | |
| 159 | − if (find_frame_rate_index(s) < 0) { | |
| 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); | |
| 160 | + if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) { | |
| 161 | + if ((avctx->width & 0xFFF) == 0 || (avctx->height & 0xFFF) == 0) { | |
| 162 | + av_log(avctx, AV_LOG_ERROR, "Width or Height are not allowed to be multiples of 4096\n" | |
| 163 | + "add '-strict %d' if you want to use them anyway.\n", FF_COMPLIANCE_UNOFFICIAL); | |
| 163 | 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 | 171 | return AVERROR(EINVAL); |
| 175 | 172 | } |
| 176 | 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 | 177 | if (avctx->level == FF_LEVEL_UNKNOWN) { |
| 181 | 178 | if (avctx->profile == FF_PROFILE_MPEG2_422) { /* 4:2:2 */ |
| 182 | 179 | if (avctx->width <= 720 && avctx->height <= 608) |
| @@ -184,7 +181,8 @@ static av_cold int encode_init(AVCodecContext *avctx) · 1 unmodified line | ||
| 184 | 181 | else |
| 185 | 182 | avctx->level = 2; /* High */ |
| 186 | 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 | 186 | av_log(avctx, AV_LOG_ERROR, |
| 189 | 187 | "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n"); |
| 190 | 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) { | |
| 202 | − av_log(avctx, AV_LOG_ERROR, "Width / Height is invalid for MPEG2\n"); | |
| 203 | − return AVERROR(EINVAL); | |
| 204 | − } | |
| 199 | + if ((ret = ff_mpv_encode_init(avctx)) < 0) | |
| 200 | + return ret; | |
| 205 | 201 | |
| 206 | − if (s->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) { | |
| 207 | − if ((avctx->width & 0xFFF) == 0 || (avctx->height & 0xFFF) == 0) { | |
| 208 | − av_log(avctx, AV_LOG_ERROR, "Width or Height are not allowed to be multiples of 4096\n" | |
| 209 | − "add '-strict %d' if you want to use them anyway.\n", FF_COMPLIANCE_UNOFFICIAL); | |
| 202 | + if (find_frame_rate_index(s) < 0) { | |
| 203 | + if (s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { | |
| 204 | + av_log(avctx, AV_LOG_ERROR, "MPEG-1/2 does not support %d/%d fps\n", | |
| 205 | + avctx->time_base.den, avctx->time_base.num); | |
| 210 | 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 | |