History

avcodec: Add max_pixels options

Michael Niedermayer committed 9 years ago

Commit 2f078301 parent f542b156 files · +23 −6Browse files

Unified · Split

6 files
  1. doc/codecs.texi +4 −0
  2. libavcodec/avcodec.h +8 −0
  3. libavcodec/options_table.h +1 −0
  4. libavcodec/utils.c +6 −6
  5. tests/ref/fate/api-mjpeg-codec-param +2 −0
  6. tests/ref/fate/api-png-codec-param +2 −0
doc/codecs.texi+4−0
@@ -1272,6 +1272,10 @@ ffprobe -dump_separator " · 1271 unmodified lines
1272 " -i ~/videos/matrixbench_mpeg2.mpg1272 " -i ~/videos/matrixbench_mpeg2.mpg
1273@end example1273@end example
1274 1274
1275@item max_pixels @var{integer} (@emph{decoding/encoding,video})
1276Maximum number of pixels per image. This value can be used to avoid out of
1277memory failures due to large images.
1278
1275@end table1279@end table
1276 1280
1277@c man end CODEC OPTIONS1281@c man end CODEC OPTIONS
libavcodec/avcodec.h+8−0
@@ -3570,6 +3570,14 @@ typedef struct AVCodecContext { · 3569 unmodified lines
3570 */3570 */
3571 int trailing_padding;3571 int trailing_padding;
3572 3572
3573 /**
3574 * The number of pixels per image to maximally accept.
3575 *
3576 * - decoding: set by user
3577 * - encoding: set by user
3578 */
3579 int64_t max_pixels;
3580
3573} AVCodecContext;3581} AVCodecContext;
3574 3582
3575AVRational av_codec_get_pkt_timebase (const AVCodecContext *avctx);3583AVRational av_codec_get_pkt_timebase (const AVCodecContext *avctx);
libavcodec/options_table.h+1−0
@@ -570,6 +570,7 @@ static const AVOption avcodec_options[] = { · 569 unmodified lines
570{"codec_whitelist", "List of decoders that are allowed to be used", OFFSET(codec_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, A|V|S|D },570{"codec_whitelist", "List of decoders that are allowed to be used", OFFSET(codec_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, A|V|S|D },
571{"pixel_format", "set pixel format", OFFSET(pix_fmt), AV_OPT_TYPE_PIXEL_FMT, {.i64=AV_PIX_FMT_NONE}, -1, INT_MAX, 0 },571{"pixel_format", "set pixel format", OFFSET(pix_fmt), AV_OPT_TYPE_PIXEL_FMT, {.i64=AV_PIX_FMT_NONE}, -1, INT_MAX, 0 },
572{"video_size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str=NULL}, 0, INT_MAX, 0 },572{"video_size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str=NULL}, 0, INT_MAX, 0 },
573{"max_pixels", "Maximum number of pixels", OFFSET(max_pixels), AV_OPT_TYPE_INT64, {.i64 = INT_MAX }, 0, INT_MAX, A|V|S|D|E },
573{NULL},574{NULL},
574};575};
575 576
libavcodec/utils.c+6−6
@@ -209,7 +209,7 @@ void avcodec_set_dimensions(AVCodecContext *s, int width, int height) · 208 unmodified lines
209 209
210int ff_set_dimensions(AVCodecContext *s, int width, int height)210int ff_set_dimensions(AVCodecContext *s, int width, int height)
211{211{
212 int ret = av_image_check_size(width, height, 0, s);212 int ret = av_image_check_size2(width, height, s->max_pixels, AV_PIX_FMT_NONE, 0, s);
213 213
214 if (ret < 0)214 if (ret < 0)
215 width = height = 0;215 width = height = 0;
@@ -904,7 +904,7 @@ static int get_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags) · 688 unmodified lines
904 int ret;904 int ret;
905 905
906 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {906 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
907 if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0 || avctx->pix_fmt<0) {907 if ((ret = av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx)) < 0 || avctx->pix_fmt<0) {
908 av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");908 av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
909 return AVERROR(EINVAL);909 return AVERROR(EINVAL);
910 }910 }
@@ -1338,8 +1338,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code · 427 unmodified lines
1338 }1338 }
1339 1339
1340 if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)1340 if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
1341 && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 01341 && ( av_image_check_size2(avctx->coded_width, avctx->coded_height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0
1342 || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) {1342 || av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0)) {
1343 av_log(avctx, AV_LOG_WARNING, "Ignoring invalid width/height values\n");1343 av_log(avctx, AV_LOG_WARNING, "Ignoring invalid width/height values\n");
1344 ff_set_dimensions(avctx, 0, 0);1344 ff_set_dimensions(avctx, 0, 0);
1345 }1345 }
@@ -1982,7 +1982,7 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, · 636 unmodified lines
1982 return 0;1982 return 0;
1983 }1983 }
1984 1984
1985 if (av_image_check_size(avctx->width, avctx->height, 0, avctx))1985 if (av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx))
1986 return AVERROR(EINVAL);1986 return AVERROR(EINVAL);
1987 1987
1988 if (frame && frame->format == AV_PIX_FMT_NONE)1988 if (frame && frame->format == AV_PIX_FMT_NONE)
@@ -2233,7 +2233,7 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi · 244 unmodified lines
2233 }2233 }
2234 2234
2235 *got_picture_ptr = 0;2235 *got_picture_ptr = 0;
2236 if ((avctx->coded_width || avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))2236 if ((avctx->coded_width || avctx->coded_height) && av_image_check_size2(avctx->coded_width, avctx->coded_height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx))
2237 return AVERROR(EINVAL);2237 return AVERROR(EINVAL);
2238 2238
2239 avctx->internal->pkt = avpkt;2239 avctx->internal->pkt = avpkt;
tests/ref/fate/api-mjpeg-codec-param+2−0
@@ -155,6 +155,7 @@ stream=0, decode=0 · 154 unmodified lines
155 codec_whitelist=155 codec_whitelist=
156 pixel_format=yuvj422p156 pixel_format=yuvj422p
157 video_size=400x225157 video_size=400x225
158 max_pixels=2147483647
158stream=0, decode=1159stream=0, decode=1
159 b=0160 b=0
160 ab=0161 ab=0
@@ -312,3 +313,4 @@ stream=0, decode=1 · 151 unmodified lines
312 codec_whitelist=313 codec_whitelist=
313 pixel_format=yuvj422p314 pixel_format=yuvj422p
314 video_size=400x225315 video_size=400x225
316 max_pixels=2147483647
tests/ref/fate/api-png-codec-param+2−0
@@ -155,6 +155,7 @@ stream=0, decode=0 · 154 unmodified lines
155 codec_whitelist=155 codec_whitelist=
156 pixel_format=rgba156 pixel_format=rgba
157 video_size=128x128157 video_size=128x128
158 max_pixels=2147483647
158stream=0, decode=1159stream=0, decode=1
159 b=0160 b=0
160 ab=0161 ab=0
@@ -312,3 +313,4 @@ stream=0, decode=1 · 151 unmodified lines
312 codec_whitelist=313 codec_whitelist=
313 pixel_format=rgba314 pixel_format=rgba
314 video_size=128x128315 video_size=128x128
316 max_pixels=2147483647

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