|
58 | 58 | #include <jpeglib.h>
|
59 | 59 | #include <libv4l2.h>
|
60 | 60 | #include <signal.h>
|
| 61 | +#include <stdint.h> |
| 62 | +#include <inttypes.h> |
61 | 63 |
|
62 | 64 | #include "config.h"
|
63 | 65 | #include "yuv.h"
|
@@ -105,6 +107,8 @@ static char* jpegFilename = NULL;
|
105 | 107 | static char* jpegFilenamePart = NULL;
|
106 | 108 | static char* deviceName = "/dev/video0";
|
107 | 109 |
|
| 110 | +static const char* const continuousFilenameFmt = "%s_%010"PRIu32"_%"PRId64".jpg"; |
| 111 | + |
108 | 112 | /**
|
109 | 113 | SIGINT interput handler
|
110 | 114 | */
|
@@ -220,10 +224,10 @@ static void imageProcess(const void* p, struct timeval timestamp)
|
220 | 224 | YUV420toYUV444(width, height, src, dst);
|
221 | 225 |
|
222 | 226 | if(continuous==1) {
|
223 |
| - static int img_ind = 0; |
224 |
| - long timestamp_long; |
| 227 | + static uint32_t img_ind = 0; |
| 228 | + int64_t timestamp_long; |
225 | 229 | timestamp_long = timestamp.tv_sec*1e6 + timestamp.tv_usec;
|
226 |
| - sprintf(jpegFilename,"%s_%010d_%010ld.jpg",jpegFilenamePart,img_ind++,timestamp_long); |
| 230 | + sprintf(jpegFilename,continuousFilenameFmt,jpegFilenamePart,img_ind++,timestamp_long); |
227 | 231 |
|
228 | 232 | }
|
229 | 233 | // write jpeg
|
@@ -963,9 +967,9 @@ int main(int argc, char **argv)
|
963 | 967 | }
|
964 | 968 |
|
965 | 969 | if(continuous == 1) {
|
966 |
| - int max_name_len = strlen(jpegFilename)+10+10+3; |
| 970 | + int max_name_len = snprintf(NULL,0,continuousFilenameFmt,jpegFilename,UINT32_MAX,INT64_MAX); |
967 | 971 | jpegFilenamePart = jpegFilename;
|
968 |
| - jpegFilename = calloc(max_name_len,sizeof(char)); |
| 972 | + jpegFilename = calloc(max_name_len+1,sizeof(char)); |
969 | 973 | strcpy(jpegFilename,jpegFilenamePart);
|
970 | 974 | }
|
971 | 975 |
|
|
0 commit comments