Mercurial > mplayer.hg
comparison libmpcodecs/vf_screenshot.c @ 37143:88b4aa330150
Ensure dimensions are set before opening libavcodec encoder.
This is a requirement that was added some time ago, we
so far relied on a hack in libavcodec, but that isn't
really a good idea.
Only lightly tested.
author | reimar |
---|---|
date | Sun, 13 Jul 2014 21:39:32 +0000 |
parents | 0fa1993a31c3 |
children |
comparison
equal
deleted
inserted
replaced
37142:7ef7684adaa0 | 37143:88b4aa330150 |
---|---|
74 if (vf->priv->ctx) sws_freeContext(vf->priv->ctx); | 74 if (vf->priv->ctx) sws_freeContext(vf->priv->ctx); |
75 vf->priv->ctx=sws_getContextFromCmdLine(width, height, outfmt, | 75 vf->priv->ctx=sws_getContextFromCmdLine(width, height, outfmt, |
76 d_width, d_height, IMGFMT_RGB24); | 76 d_width, d_height, IMGFMT_RGB24); |
77 | 77 |
78 av_fast_malloc(&vf->priv->outbuffer, &vf->priv->outbuffer_size, d_width * d_height * 3 * 2); | 78 av_fast_malloc(&vf->priv->outbuffer, &vf->priv->outbuffer_size, d_width * d_height * 3 * 2); |
79 vf->priv->avctx->width = d_width; | 79 if (!vf->priv->avctx) { |
80 vf->priv->avctx->height = d_height; | 80 vf->priv->avctx = avcodec_alloc_context3(NULL); |
81 vf->priv->avctx->compression_level = 0; | 81 vf->priv->avctx->pix_fmt = PIX_FMT_RGB24; |
82 vf->priv->avctx->width = d_width; | |
83 vf->priv->avctx->height = d_height; | |
84 vf->priv->avctx->compression_level = 0; | |
85 if (avcodec_open2(vf->priv->avctx, avcodec_find_encoder(AV_CODEC_ID_PNG), NULL)) { | |
86 mp_msg(MSGT_VFILTER, MSGL_FATAL, "Could not open libavcodec PNG encoder\n"); | |
87 return 0; | |
88 } | |
89 } | |
82 vf->priv->dw = d_width; | 90 vf->priv->dw = d_width; |
83 vf->priv->dh = d_height; | 91 vf->priv->dh = d_height; |
84 vf->priv->pic->linesize[0] = (3*vf->priv->dw+15)&~15; | 92 vf->priv->pic->linesize[0] = (3*vf->priv->dw+15)&~15; |
85 | 93 |
86 av_freep(&vf->priv->pic->data[0]); // probably reconfigured | 94 av_freep(&vf->priv->pic->data[0]); // probably reconfigured |
282 vf->get_image=get_image; | 290 vf->get_image=get_image; |
283 vf->uninit=uninit; | 291 vf->uninit=uninit; |
284 vf->priv = calloc(1, sizeof(struct vf_priv_s)); | 292 vf->priv = calloc(1, sizeof(struct vf_priv_s)); |
285 vf->priv->pic = av_frame_alloc(); | 293 vf->priv->pic = av_frame_alloc(); |
286 vf->priv->prefix = strdup(args ? args : "shot"); | 294 vf->priv->prefix = strdup(args ? args : "shot"); |
287 vf->priv->avctx = avcodec_alloc_context3(NULL); | |
288 vf->priv->avctx->pix_fmt = PIX_FMT_RGB24; | |
289 avcodec_register_all(); | 295 avcodec_register_all(); |
290 if (avcodec_open2(vf->priv->avctx, avcodec_find_encoder(AV_CODEC_ID_PNG), NULL)) { | 296 if (!avcodec_find_encoder(AV_CODEC_ID_PNG)) { |
291 mp_msg(MSGT_VFILTER, MSGL_FATAL, "Could not open libavcodec PNG encoder\n"); | 297 mp_msg(MSGT_VFILTER, MSGL_FATAL, "Could not find libavcodec PNG encoder\n"); |
292 return 0; | 298 return 0; |
293 } | 299 } |
294 return 1; | 300 return 1; |
295 } | 301 } |
296 | 302 |