diff options
author | wm4 <wm4@mplayer2.org> | 2012-04-29 07:32:57 +0200 |
---|---|---|
committer | wm4 <wm4@mplayer2.org> | 2012-04-29 10:01:55 +0200 |
commit | 4add4f708e14367833fb9f1308c0802fbe32a808 (patch) | |
tree | 8fb8eef1953017c1d432708ae6073c006020c1f2 /screenshot.c | |
parent | 97ac824124fc5cdfbd9ac74156b79c098bce09c6 (diff) | |
download | mpv-4add4f708e14367833fb9f1308c0802fbe32a808.tar.bz2 mpv-4add4f708e14367833fb9f1308c0802fbe32a808.tar.xz |
screenshot, vo_png: fix dependency on sizeof(AVFrame)
In order to stay binary compatible with libavcodec, applications should
not dependent on sizeof(AVFrame). This means allocating AVFrame on the
stack is not allowed, and the function avcodec_alloc_frame() must be
used to allocate an AVFrame instead.
Partially based on a patch by uau.
Diffstat (limited to 'screenshot.c')
-rw-r--r-- | screenshot.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/screenshot.c b/screenshot.c index ba1a48809f..43e77f22a5 100644 --- a/screenshot.c +++ b/screenshot.c @@ -23,8 +23,6 @@ #include <setjmp.h> #include <time.h> -#include "osdep/io.h" - #include <libswscale/swscale.h> #include <libavcodec/avcodec.h> @@ -34,6 +32,8 @@ #include <jpeglib.h> #endif +#include "osdep/io.h" + #include "talloc.h" #include "screenshot.h" #include "mp_core.h" @@ -82,6 +82,7 @@ static int write_png(screenshot_ctx *ctx, struct mp_image *image, FILE *fp) { void *outbuffer = NULL; int success = 0; + AVFrame *pic = NULL; struct AVCodec *png_codec = avcodec_find_encoder(CODEC_ID_PNG); AVCodecContext *avctx = NULL; @@ -109,13 +110,15 @@ static int write_png(screenshot_ctx *ctx, struct mp_image *image, FILE *fp) if (!outbuffer) goto error_exit; - AVFrame pic; - avcodec_get_frame_defaults(&pic); + pic = avcodec_alloc_frame(); + if (!pic) + goto error_exit; + avcodec_get_frame_defaults(pic); for (int n = 0; n < 4; n++) { - pic.data[n] = image->planes[n]; - pic.linesize[n] = image->stride[n]; + pic->data[n] = image->planes[n]; + pic->linesize[n] = image->stride[n]; } - int size = avcodec_encode_video(avctx, outbuffer, outbuffer_size, &pic); + int size = avcodec_encode_video(avctx, outbuffer, outbuffer_size, pic); if (size < 1) goto error_exit; @@ -126,6 +129,7 @@ error_exit: if (avctx) avcodec_close(avctx); av_free(avctx); + av_free(pic); free(outbuffer); return success; } |