diff options
Diffstat (limited to 'libvo/vo_png.c')
-rw-r--r-- | libvo/vo_png.c | 80 |
1 files changed, 9 insertions, 71 deletions
diff --git a/libvo/vo_png.c b/libvo/vo_png.c index 5b558b3d1e..bce8d05390 100644 --- a/libvo/vo_png.c +++ b/libvo/vo_png.c @@ -26,21 +26,16 @@ #include <stdlib.h> #include <string.h> #include <errno.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <unistd.h> #include "config.h" -#include "fmt-conversion.h" -#include "mp_core.h" +#include "mp_msg.h" #include "mp_msg.h" #include "help_mp.h" #include "video_out.h" #include "video_out_internal.h" #include "subopt-helper.h" #include "libavcodec/avcodec.h" - -#define BUFLENGTH 512 +#include "fmt-conversion.h" static const vo_info_t info = { @@ -53,72 +48,21 @@ static const vo_info_t info = const LIBVO_EXTERN (png) static int z_compression; -static char *png_outdir; static int framenum; static int use_alpha; static AVCodecContext *avctx; static uint8_t *outbuffer; int outbuffer_size; -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(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(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(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(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); - mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning2); - mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning3); + mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_PNG] Warning: compression level set to 0, compression disabled!\n"); + mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_PNG] Info: Use -vo png:z=<n> to set compression level from 0 to 9.\n"); + mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_PNG] Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n"); } - 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; @@ -135,10 +79,10 @@ static uint32_t draw_image(mp_image_t* mpi){ // if -dr or -slices then do nothing: if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE; - snprintf (buf, 100, "%s/%08d.png", png_outdir, ++framenum); + snprintf (buf, 100, "%08d.png", ++framenum); outfile = fopen(buf, "wb"); if (!outfile) { - mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorOpeningForWriting, strerror(errno)); + mp_msg(MSGT_VO,MSGL_WARN, "\n[VO_PNG] Error opening '%s' for writing!\n", strerror(errno)); return 1; } @@ -156,7 +100,7 @@ static uint32_t draw_image(mp_image_t* mpi){ res = avcodec_encode_video(avctx, outbuffer, outbuffer_size, &pic); if(res < 0){ - mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorInCreatePng); + mp_msg(MSGT_VO,MSGL_WARN, "[VO_PNG] Error in create_png.\n"); fclose(outfile); return 1; } @@ -199,10 +143,6 @@ static void uninit(void){ av_freep(&avctx); av_freep(&outbuffer); outbuffer_size = 0; - if (png_outdir) { - free(png_outdir); - png_outdir = NULL; - } } static void check_events(void){} @@ -216,14 +156,12 @@ static int int_zero_to_nine(void *value) static const opt_t subopts[] = { {"alpha", OPT_ARG_BOOL, &use_alpha, NULL}, {"z", OPT_ARG_INT, &z_compression, int_zero_to_nine}, - {"outdir", OPT_ARG_MSTRZ, &png_outdir, NULL}, {NULL} }; static int preinit(const char *arg) { z_compression = 0; - png_outdir = strdup("."); use_alpha = 0; if (subopt_parse(arg, subopts) != 0) { return -1; @@ -238,7 +176,7 @@ static int preinit(const char *arg) return 0; } -static int control(uint32_t request, void *data, ...) +static int control(uint32_t request, void *data) { switch (request) { case VOCTRL_DRAW_IMAGE: |