History

avcodec/mpeg12enc: Perform size/level/profile checks earlier

This has the advantage that one does not waste some allocations if one errors out because of these checks.

Andreas Rheinhardt committed 5 years ago

Commit bf61cbb1 parent d5c7e5c1 file · +22 −22Browse files

Unified · Split

libavcodec/mpeg12enc.c+22−22
@@ -152,19 +152,16 @@ static av_cold int encode_init(AVCodecContext *avctx) · 151 unmodified lines
152152 max_size, max_size);
153153 return AVERROR(EINVAL);
154154 }
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+ }
155159
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);
163164 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);
168165 }
169166 }
170167
@@ -174,9 +171,9 @@ static av_cold int encode_init(AVCodecContext *avctx) · 3 unmodified lines
174171 return AVERROR(EINVAL);
175172 }
176173 /* 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;
178176 }
179−
180177 if (avctx->level == FF_LEVEL_UNKNOWN) {
181178 if (avctx->profile == FF_PROFILE_MPEG2_422) { /* 4:2:2 */
182179 if (avctx->width <= 720 && avctx->height <= 608)
@@ -184,7 +181,8 @@ static av_cold int encode_init(AVCodecContext *avctx) · 1 unmodified line
184181 else
185182 avctx->level = 2; /* High */
186183 } 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) {
188186 av_log(avctx, AV_LOG_ERROR,
189187 "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n");
190188 return AVERROR(EINVAL);
@@ -198,16 +196,18 @@ static av_cold int encode_init(AVCodecContext *avctx) · 7 unmodified lines
198196 }
199197 }
200198
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;
205201
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);
210206 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);
211211 }
212212 }
213213

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t