[MPlayer-cvslog] r37239 - in trunk: libmpcodecs/vf_screenshot.c libvo/vo_png.c

reimar subversion at mplayerhq.hu
Sun Jul 13 23:39:33 CEST 2014


Author: reimar
Date: Sun Jul 13 23:39:32 2014
New Revision: 37239

Log:
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.

Modified:
   trunk/libmpcodecs/vf_screenshot.c
   trunk/libvo/vo_png.c

Modified: trunk/libmpcodecs/vf_screenshot.c
==============================================================================
--- trunk/libmpcodecs/vf_screenshot.c	Thu Jul 10 01:20:47 2014	(r37238)
+++ trunk/libmpcodecs/vf_screenshot.c	Sun Jul 13 23:39:32 2014	(r37239)
@@ -76,9 +76,17 @@ static int config(struct vf_instance *vf
                                  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 @@ static int vf_open(vf_instance_t *vf, ch
     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;

Modified: trunk/libvo/vo_png.c
==============================================================================
--- trunk/libvo/vo_png.c	Thu Jul 10 01:20:47 2014	(r37238)
+++ trunk/libvo/vo_png.c	Sun Jul 13 23:39:32 2014	(r37239)
@@ -134,6 +134,8 @@ config(uint32_t width, uint32_t height, 
         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;


More information about the MPlayer-cvslog mailing list