[MPlayer-cvslog] r37337 - trunk/libmpcodecs/vf_screenshot.c

reimar subversion at mplayerhq.hu
Sat Dec 6 22:17:44 CET 2014


Author: reimar
Date: Sat Dec  6 22:17:44 2014
New Revision: 37337

Log:
vf_screenshot: do not silently create empty screenshot files.

On encode error, print a message and don't open the file.

Modified:
   trunk/libmpcodecs/vf_screenshot.c

Modified: trunk/libmpcodecs/vf_screenshot.c
==============================================================================
--- trunk/libmpcodecs/vf_screenshot.c	Sat Dec  6 22:17:43 2014	(r37336)
+++ trunk/libmpcodecs/vf_screenshot.c	Sat Dec  6 22:17:44 2014	(r37337)
@@ -107,18 +107,22 @@ static void write_png(struct vf_priv_s *
     AVPacket pkt;
     int res, got_pkt;
 
+    av_init_packet(&pkt);
+    pkt.data = priv->outbuffer;
+    pkt.size = priv->outbuffer_size;
+    res = avcodec_encode_video2(priv->avctx, &pkt, priv->pic, &got_pkt);
+    if (res < 0 || !got_pkt || pkt.size <= 0) {
+        mp_msg(MSGT_VFILTER,MSGL_ERR,"\nFailed to encode screenshot %s!\n", fname);
+        return;
+    }
+
     fp = fopen (fname, "wb");
     if (fp == NULL) {
         mp_msg(MSGT_VFILTER,MSGL_ERR,"\nPNG Error opening %s for writing!\n", fname);
         return;
     }
 
-    av_init_packet(&pkt);
-    pkt.data = priv->outbuffer;
-    pkt.size = priv->outbuffer_size;
-    res = avcodec_encode_video2(priv->avctx, &pkt, priv->pic, &got_pkt);
-    if (res >= 0 && got_pkt && pkt.size > 0)
-        fwrite(priv->outbuffer, pkt.size, 1, fp);
+    fwrite(priv->outbuffer, pkt.size, 1, fp);
 
     fclose (fp);
     mp_msg(MSGT_VFILTER,MSGL_INFO,"*** screenshot '%s' ***\n",priv->fname);


More information about the MPlayer-cvslog mailing list