# HG changeset patch # User reimar # Date 1405287572 0 # Node ID 88b4aa330150db5b06df5c5d4e94e4f15ed19703 # Parent 7ef7684adaa0b764b77e261e85a5851b2cebc40f 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. diff -r 7ef7684adaa0 -r 88b4aa330150 libmpcodecs/vf_screenshot.c --- a/libmpcodecs/vf_screenshot.c Wed Jul 09 23:20:47 2014 +0000 +++ b/libmpcodecs/vf_screenshot.c Sun Jul 13 21:39:32 2014 +0000 @@ -76,9 +76,17 @@ d_width, d_height, IMGFMT_RGB24); av_fast_malloc(&vf->priv->outbuffer, &vf->priv->outbuffer_size, d_width * d_height * 3 * 2); - vf->priv->avctx->width = d_width; - vf->priv->avctx->height = d_height; - vf->priv->avctx->compression_level = 0; + if (!vf->priv->avctx) { + vf->priv->avctx = avcodec_alloc_context3(NULL); + vf->priv->avctx->pix_fmt = PIX_FMT_RGB24; + vf->priv->avctx->width = d_width; + vf->priv->avctx->height = d_height; + vf->priv->avctx->compression_level = 0; + if (avcodec_open2(vf->priv->avctx, avcodec_find_encoder(AV_CODEC_ID_PNG), NULL)) { + mp_msg(MSGT_VFILTER, MSGL_FATAL, "Could not open libavcodec PNG encoder\n"); + return 0; + } + } vf->priv->dw = d_width; vf->priv->dh = d_height; vf->priv->pic->linesize[0] = (3*vf->priv->dw+15)&~15; @@ -284,11 +292,9 @@ vf->priv = calloc(1, sizeof(struct vf_priv_s)); vf->priv->pic = av_frame_alloc(); vf->priv->prefix = strdup(args ? args : "shot"); - vf->priv->avctx = avcodec_alloc_context3(NULL); - vf->priv->avctx->pix_fmt = PIX_FMT_RGB24; avcodec_register_all(); - if (avcodec_open2(vf->priv->avctx, avcodec_find_encoder(AV_CODEC_ID_PNG), NULL)) { - mp_msg(MSGT_VFILTER, MSGL_FATAL, "Could not open libavcodec PNG encoder\n"); + if (!avcodec_find_encoder(AV_CODEC_ID_PNG)) { + mp_msg(MSGT_VFILTER, MSGL_FATAL, "Could not find libavcodec PNG encoder\n"); return 0; } return 1; diff -r 7ef7684adaa0 -r 88b4aa330150 libvo/vo_png.c --- a/libvo/vo_png.c Wed Jul 09 23:20:47 2014 +0000 +++ b/libvo/vo_png.c Sun Jul 13 21:39:32 2014 +0000 @@ -134,6 +134,8 @@ avctx = avcodec_alloc_context3(NULL); avctx->compression_level = z_compression; avctx->pix_fmt = imgfmt2pixfmt(format); + avctx->width = width; + avctx->height = height; if (avcodec_open2(avctx, avcodec_find_encoder(AV_CODEC_ID_PNG), NULL) < 0) { uninit(); return -1;