changeset 27618:9badbf52f33c

add outdir sub-option to vo png
author ben
date Sat, 20 Sep 2008 13:13:02 +0000
parents 226a78c5b2d9
children ca11fb4eaea5
files DOCS/man/en/mplayer.1 DOCS/man/fr/mplayer.1 libvo/vo_png.c
diffstat 3 files changed, 68 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/man/en/mplayer.1	Sat Sep 20 08:16:05 2008 +0000
+++ b/DOCS/man/en/mplayer.1	Sat Sep 20 13:13:02 2008 +0000
@@ -4200,6 +4200,8 @@
 .IPs z=<0\-9>
 Specifies the compression level.
 0 is no compression, 9 is maximum compression.
+.IPs outdir=<dirname>
+Specify the directory to save the PNG files to (default: ./).
 .RE
 .PD 1
 .
--- a/DOCS/man/fr/mplayer.1	Sat Sep 20 08:16:05 2008 +0000
+++ b/DOCS/man/fr/mplayer.1	Sat Sep 20 13:13:02 2008 +0000
@@ -4434,6 +4434,8 @@
 .IPs z=<0\-9>
 Définit le taux de compression.
 0 équivaut à pas de compression et 9 à la compression maximale.
+.IPs outdir=<chemin>
+Définit le répertoire où sauver les fichiers PNG (par défaut\ ./).
 .RE
 .PD 1
 .
--- a/libvo/vo_png.c	Sat Sep 20 08:16:05 2008 +0000
+++ b/libvo/vo_png.c	Sat Sep 20 13:13:02 2008 +0000
@@ -11,6 +11,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #include <png.h>
 
@@ -22,6 +25,8 @@
 #include "video_out_internal.h"
 #include "subopt-helper.h"
 
+#define BUFLENGTH 512
+
 static const vo_info_t info = 
 {
 	"PNG file",
@@ -33,6 +38,7 @@
 const LIBVO_EXTERN (png)
 
 static int z_compression = Z_NO_COMPRESSION;
+static char *png_outdir = NULL;
 static int framenum = 0;
 
 struct pngdata {
@@ -42,9 +48,56 @@
 	enum {OK,ERROR} status;  
 };
 
+static void png_mkdir(char *buf, int verbose) { 
+    struct stat stat_p;
+
+#ifndef __MINGW32__	
+    if ( mkdir(buf, 0755) < 0 ) {
+#else
+    if ( mkdir(buf) < 0 ) {
+#endif
+        switch (errno) { /* use switch in case other errors need to be caught
+                            and handled in the future */
+            case EEXIST:
+                if ( stat(buf, &stat_p ) < 0 ) {
+                    mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
+                            MSGTR_VO_GenericError, strerror(errno) );
+                    mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,
+                            MSGTR_VO_UnableToAccess,buf);
+                    exit_player(MSGTR_Exit_error);
+                }
+                if ( !S_ISDIR(stat_p.st_mode) ) {
+                    mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,
+                            buf, MSGTR_VO_ExistsButNoDirectory);
+                    exit_player(MSGTR_Exit_error);
+                }
+                if ( !(stat_p.st_mode & S_IWUSR) ) {
+                    mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name,
+                            buf, MSGTR_VO_DirExistsButNotWritable);
+                    exit_player(MSGTR_Exit_error);
+                }
+                
+                mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name,
+                        buf, MSGTR_VO_DirExistsAndIsWritable);
+                break;
+
+            default:
+                mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
+                        MSGTR_VO_GenericError, strerror(errno) );
+                mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name,
+                        buf, MSGTR_VO_CantCreateDirectory);
+                exit_player(MSGTR_Exit_error);
+        } /* end switch */
+    } else if ( verbose ) {  
+        mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name,
+                buf, MSGTR_VO_DirectoryCreateSuccess);
+    } /* end if */
+}
+    
 static int
 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
 {
+    char buf[BUFLENGTH];
     
 	    if(z_compression == 0) {
  		    mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning1);
@@ -52,6 +105,8 @@
  		    mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning3);
 	    }	    
     
+    snprintf(buf, BUFLENGTH, "%s", png_outdir);
+    png_mkdir(buf, 1);
     mp_msg(MSGT_VO,MSGL_DBG2, "PNG Compression level %i\n", z_compression);
 	  	
     return 0;
@@ -148,7 +203,7 @@
     // if -dr or -slices then do nothing:
     if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE;
     
-    snprintf (buf, 100, "%08d.png", ++framenum);
+    snprintf (buf, 100, "%s/%08d.png", png_outdir, ++framenum);
 
     png = create_png(buf, mpi->w, mpi->h, IMGFMT_IS_BGR(mpi->imgfmt));
 
@@ -198,7 +253,12 @@
     return 0;
 }
 
-static void uninit(void){}
+static void uninit(void){
+    if (png_outdir) {
+        free(png_outdir);
+        png_outdir = NULL;
+    }
+}
 
 static void check_events(void){}
 
@@ -211,12 +271,14 @@
 
 static opt_t subopts[] = {
     {"z",   OPT_ARG_INT, &z_compression, (opt_test_f)int_zero_to_nine},
+    {"outdir",      OPT_ARG_MSTRZ,  &png_outdir,           NULL, 0},
     {NULL}
 };
 
 static int preinit(const char *arg)
 {
     z_compression = 0;
+    png_outdir = strdup(".");
     if (subopt_parse(arg, subopts) != 0) {
         return -1;
     }