changeset 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 7ef7684adaa0
children 1294b0ff7e06
files libmpcodecs/vf_screenshot.c libvo/vo_png.c
diffstat 2 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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;
--- 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;