[MPlayer-cvslog] r34723 - trunk/libvo/vo_png.c

iive subversion at mplayerhq.hu
Tue Feb 14 18:06:09 CET 2012


Author: iive
Date: Tue Feb 14 18:06:09 2012
New Revision: 34723

Log:
Fix vo_png after FFmpeg merge.

Now avcodec_open2() function wants a valid avctx->pix_fmt to be set,
but the current vo_png opens the encoder in preinit() function,
long before the exact pixel format is know.

The fix moves the avcodec_open2() function to vo_png::config() and
adds a check for changed pixel format in case there are more config() calls.

Modified:
   trunk/libvo/vo_png.c

Modified: trunk/libvo/vo_png.c
==============================================================================
--- trunk/libvo/vo_png.c	Tue Feb 14 17:50:42 2012	(r34722)
+++ trunk/libvo/vo_png.c	Tue Feb 14 18:06:09 2012	(r34723)
@@ -55,6 +55,7 @@ const LIBVO_EXTERN (png)
 static int z_compression;
 static char *png_outdir;
 static char *png_outfile_prefix;
+static uint32_t png_format;
 static int framenum;
 static int use_alpha;
 static AVCodecContext *avctx;
@@ -122,6 +123,22 @@ config(uint32_t width, uint32_t height, 
     png_mkdir(buf, 1);
     mp_msg(MSGT_VO,MSGL_DBG2, "PNG Compression level %i\n", z_compression);
 
+
+    if (avctx && png_format != format) {
+        avcodec_close(avctx);
+        av_freep(&avctx);
+    }
+
+    if (!avctx) {
+        avctx = avcodec_alloc_context3(NULL);
+        avctx->compression_level = z_compression;
+        avctx->pix_fmt = imgfmt2pixfmt(format);
+        if (avcodec_open2(avctx, avcodec_find_encoder(CODEC_ID_PNG), NULL) < 0) {
+            uninit();
+            return -1;
+        }
+        png_format = format;
+    }
     return 0;
 }
 
@@ -145,7 +162,6 @@ static uint32_t draw_image(mp_image_t* m
 
     avctx->width = mpi->w;
     avctx->height = mpi->h;
-    avctx->pix_fmt = imgfmt2pixfmt(mpi->imgfmt);
     pic.data[0] = mpi->planes[0];
     pic.linesize[0] = mpi->stride[0];
     buffersize = mpi->w * mpi->h * 8;
@@ -232,12 +248,6 @@ static int preinit(const char *arg)
         return -1;
     }
     avcodec_register_all();
-    avctx = avcodec_alloc_context3(NULL);
-    if (avcodec_open2(avctx, avcodec_find_encoder(CODEC_ID_PNG), NULL) < 0) {
-        uninit();
-        return -1;
-    }
-    avctx->compression_level = z_compression;
     return 0;
 }
 


More information about the MPlayer-cvslog mailing list