Mercurial > mplayer.hg
comparison libvo/vo_jpeg.c @ 13158:b872a27aea9e
Added output to multiple directories for vo_jpeg.
Updated the manual page to describe the new options.
author | ivo |
---|---|
date | Thu, 26 Aug 2004 22:18:25 +0000 |
parents | db49cdedb88d |
children | 43fe55f36522 |
comparison
equal
deleted
inserted
replaced
13157:0d44af5bec83 | 13158:b872a27aea9e |
---|---|
1 /* | 1 /* |
2 * vo_jpeg.c, JPEG Renderer for MPlayer | 2 * vo_jpeg.c, JPEG Renderer for MPlayer |
3 * | 3 * |
4 * Copyright 2002 by Pontscho (pontscho@makacs.poliod.hu) | 4 * Copyright 2002 by Pontscho (pontscho@makacs.poliod.hu) |
5 * 25/04/2003: Spring cleanup -- alex | 5 * 25/04/2003: Spring cleanup -- alex |
6 * 04/08/2004: Added multiple subdirectory support -- ivop@euronet.nl | |
6 * | 7 * |
7 */ | 8 */ |
8 | 9 |
9 #include <stdio.h> | 10 #include <stdio.h> |
10 #include <stdlib.h> | 11 #include <stdlib.h> |
12 #include <errno.h> | 13 #include <errno.h> |
13 | 14 |
14 #include <jpeglib.h> | 15 #include <jpeglib.h> |
15 | 16 |
16 #include "config.h" | 17 #include "config.h" |
18 #include "mp_msg.h" | |
17 #include "video_out.h" | 19 #include "video_out.h" |
18 #include "video_out_internal.h" | 20 #include "video_out_internal.h" |
21 #include "mplayer.h" /* for exit_player() */ | |
22 #include "help_mp.h" | |
23 | |
24 #include <sys/stat.h> | |
25 #include <sys/types.h> | |
26 #include <unistd.h> | |
27 | |
28 /* Used for temporary buffers to store file- and pathnames */ | |
29 #define BUFLENGTH 512 | |
19 | 30 |
20 static vo_info_t info= | 31 static vo_info_t info= |
21 { | 32 { |
22 "JPEG file", | 33 "JPEG file", |
23 "jpeg", | 34 "jpeg", |
34 int jpeg_progressive_mode = 0; | 45 int jpeg_progressive_mode = 0; |
35 int jpeg_optimize = 100; | 46 int jpeg_optimize = 100; |
36 int jpeg_smooth = 0; | 47 int jpeg_smooth = 0; |
37 int jpeg_quality = 75; | 48 int jpeg_quality = 75; |
38 char * jpeg_outdir = "."; | 49 char * jpeg_outdir = "."; |
50 char * jpeg_subdirs = NULL; | |
51 int jpeg_maxfiles=1000; | |
39 | 52 |
40 static int framenum=0; | 53 static int framenum=0; |
41 | 54 |
42 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) | 55 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) |
43 { | 56 { |
44 image_height=height; | 57 char buf[BUFLENGTH]; |
45 image_width=width; | 58 struct stat stat_p; |
59 | |
60 /* Create outdir. If it already exists, test if it's a writable directory */ | |
61 | |
62 snprintf (buf, BUFLENGTH, "%s", jpeg_outdir); | |
63 | |
64 if (mkdir (buf, 0755)<0) { | |
65 switch (errno) { /* use switch in case other errors need to be caught and handled in the future */ | |
66 case EEXIST: | |
67 if ( stat(buf, &stat_p) < 0 ) { | |
68 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
69 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, MSGTR_VO_JPEG_UnableToAccess,buf); | |
70 exit_player(MSGTR_Exit_error); | |
71 } | |
72 if ( !S_ISDIR(stat_p.st_mode) ) { | |
73 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, buf, MSGTR_VO_JPEG_ExistsButNoDirectory); | |
74 exit_player(MSGTR_Exit_error); | |
75 } | |
76 if ( !(stat_p.st_mode & S_IWUSR) ) { | |
77 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, MSGTR_VO_JPEG_DirExistsButNotWritable); | |
78 exit_player(MSGTR_Exit_error); | |
79 } | |
80 | |
81 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, MSGTR_VO_JPEG_DirExistsAndIsWritable); | |
82 break; | |
83 | |
84 default: | |
85 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
86 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, MSGTR_VO_JPEG_CantCreateDirectory); | |
87 exit_player(MSGTR_Exit_error); | |
88 } /* end switch */ | |
89 } else { | |
90 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, MSGTR_VO_JPEG_DirectoryCreateSuccess); | |
91 } /* end if */ | |
92 | |
93 image_height=height; | |
94 image_width=width; | |
46 | 95 |
47 return 0; | 96 return 0; |
48 } | 97 } |
49 | 98 |
50 static uint32_t jpeg_write( uint8_t * name,uint8_t * buffer ) | 99 static uint32_t jpeg_write( uint8_t * name,uint8_t * buffer ) |
89 return 0; | 138 return 0; |
90 } | 139 } |
91 | 140 |
92 static uint32_t draw_frame(uint8_t * src[]) | 141 static uint32_t draw_frame(uint8_t * src[]) |
93 { | 142 { |
94 char buf[256]; | 143 static uint32_t framecounter=0, subdircounter=0; |
144 char buf[BUFLENGTH]; | |
95 uint8_t *dst= src[0]; | 145 uint8_t *dst= src[0]; |
96 | 146 static char subdirname[BUFLENGTH] = ""; |
97 snprintf (buf, 256, "%s/%08d.jpg", jpeg_outdir, ++framenum); | 147 struct stat stat_p; |
148 | |
149 /* Start writing to new subdirectory after a certain amount of frames */ | |
150 if ( framecounter == jpeg_maxfiles ) { | |
151 framecounter = 0; | |
152 } | |
153 | |
154 /* If framecounter is zero (or reset to zero), increment subdirectory number | |
155 * and create the subdirectory. | |
156 * If jpeg_subdirs is not set, do nothing and resort to old behaviour. */ | |
157 if ( !framecounter && jpeg_subdirs ) { | |
158 snprintf (subdirname, BUFLENGTH, "%s%08d", jpeg_subdirs, ++subdircounter); | |
159 snprintf (buf, BUFLENGTH, "%s/%s", jpeg_outdir, subdirname); | |
160 if (mkdir (buf, 0755)<0) { | |
161 switch (errno) { /* use switch in case other errors need to be caught and handled in the future */ | |
162 case EEXIST: | |
163 if ( stat(buf, &stat_p) < 0 ) { | |
164 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
165 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, MSGTR_VO_JPEG_UnableToAccess, buf); | |
166 exit_player(MSGTR_Exit_error); | |
167 } | |
168 if ( !S_ISDIR(stat_p.st_mode) ) { | |
169 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s %s\n", info.short_name, buf, MSGTR_VO_JPEG_ExistsButNoDirectory); | |
170 exit_player(MSGTR_Exit_error); | |
171 } | |
172 if ( !(stat_p.st_mode & S_IWUSR) ) { | |
173 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s\n", info.short_name, buf, MSGTR_VO_JPEG_DirExistsButNotWritable); | |
174 exit_player(MSGTR_Exit_error); | |
175 } | |
176 | |
177 mp_msg(MSGT_VO, MSGL_INFO, "\n%s: %s - %s\n", info.short_name, buf, MSGTR_VO_JPEG_DirExistsAndIsWritable); | |
178 break; | |
179 | |
180 default: | |
181 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
182 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s.\n", info.short_name, buf, MSGTR_VO_JPEG_CantCreateDirectory); | |
183 exit_player(MSGTR_Exit_error); | |
184 break; | |
185 } | |
186 } /* switch */ | |
187 } /* if !framecounter && jpeg_subdirs */ | |
188 | |
189 | |
190 framenum++; | |
191 | |
192 /* snprintf the full pathname of the outputfile */ | |
193 snprintf (buf, BUFLENGTH, "%s/%s/%08d.jpg", jpeg_outdir, subdirname, framenum); | |
194 | |
195 framecounter++; | |
98 | 196 |
99 return jpeg_write( buf,src[0] ); | 197 return jpeg_write( buf,src[0] ); |
100 } | 198 } |
101 | 199 |
102 static void draw_osd(void) | 200 static void draw_osd(void) |
140 case VOCTRL_QUERY_FORMAT: | 238 case VOCTRL_QUERY_FORMAT: |
141 return query_format(*((uint32_t*)data)); | 239 return query_format(*((uint32_t*)data)); |
142 } | 240 } |
143 return VO_NOTIMPL; | 241 return VO_NOTIMPL; |
144 } | 242 } |
243 | |
244 #undef BUFLENGTH | |
245 |