static int draw_frame(uint8_t *src[]) { static int framecounter = 0, subdircounter = 0; char buf[BUFLENGTH]; static char subdirname[BUFLENGTH] = ""; /* Start writing to new subdirectory after a certain amount of frames */ if ( framecounter == jpeg_maxfiles ) { framecounter = 0; } /* If framecounter is zero (or reset to zero), increment subdirectory * number and create the subdirectory. * If jpeg_subdirs is not set, do nothing and resort to old behaviour. */ if ( !framecounter && jpeg_subdirs ) { subdircounter++; snprintf(subdirname, BUFLENGTH, "%s%08d", jpeg_subdirs, subdircounter); snprintf(buf, BUFLENGTH, "%s/%s", jpeg_outdir, subdirname); jpeg_mkdir(buf, 0); /* This function only returns if creation was successful. If not, the player will exit. */ } framenum++; /* snprintf the full pathname of the outputfile */ snprintf(buf, BUFLENGTH, "%s/%s/%08d.jpg", jpeg_outdir, subdirname, framenum); framecounter++; return jpeg_write(buf, src[0]); }
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]; /* Create outdir. */ snprintf(buf, BUFLENGTH, "%s", jpeg_outdir); jpeg_mkdir(buf, 1); /* This function only returns if creation was successful. If not, the player will exit. */ image_height = height; image_width = width; /* Save for JFIF-Header PAR */ image_d_width = d_width; image_d_height = d_height; return 0; }
static void jpeg_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]; /* Create outdir. */ snprintf(buf, BUFLENGTH, "%s", jpeg_outdir); jpeg_mkdir(buf, 1); /* This function only returns if creation was successful. If not, the player will exit. */ image_height = height; image_width = width; /* Save for JFIF-Header PAR */ image_d_width = d_width; image_d_height = d_height; return 0; }