00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "contributors.h"
00015 #include "global.h"
00016 #include "img_io.h"
00017 #include "report.h"
00018
00019 static const VIDEO_SIZE VideoRes[] = {
00020 { "qcif" , 176, 144},
00021 { "qqvga" , 160, 128},
00022 { "qvga" , 320, 240},
00023 { "sif" , 352, 240},
00024 { "cif" , 352, 288},
00025 { "vga" , 640, 480},
00026 { "sd1" , 720, 480},
00027 { "sd2" , 704, 576},
00028 { "sd3" , 720, 576},
00029 { "720p" , 1280, 720},
00030 { "1080p" , 1920, 1080},
00031 { NULL, 0, 0}
00032 };
00033
00034
00035
00036
00037
00038
00039
00040
00041 int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, double *fps)
00042 {
00043 char *p1, *p2, *tail;
00044 char *fn = input_file->fname;
00045 char c;
00046 int i = 0;
00047
00048 *x_size = *y_size = -1;
00049 p1 = p2 = fn;
00050 while (p1 != NULL && p2 != NULL)
00051 {
00052
00053 p1 = strstr( p1, "_");
00054 if (p1 == NULL)
00055 break;
00056
00057
00058 p2 = strstr( p1, "x");
00059
00060
00061 if (p2 == NULL)
00062 break;
00063
00064
00065 *p2 = 0;
00066 *x_size = strtol( p1 + 1, &tail, 10);
00067
00068
00069 if (*tail != '\0' || *(p1 + 1) == '\0')
00070 {
00071 *p2 = 'x';
00072 p1 = tail;
00073 continue;
00074 }
00075
00076
00077 *p2 = 'x';
00078
00079
00080 p1 = strpbrk( p2 + 1, "_.");
00081
00082 if (p1 == NULL)
00083 {
00084 p1 = p2 + 1;
00085 continue;
00086 }
00087
00088
00089 c = *p1;
00090 *p1 = 0;
00091 *y_size = strtol( p2 + 1, &tail, 10);
00092
00093
00094 if (*tail != '\0' || *(p2 + 1) == '\0')
00095 {
00096 *p1 = c;
00097 p1 = tail;
00098 continue;
00099 }
00100
00101
00102 *p1 = c;
00103
00104
00105 p2 = strstr( p1 + 1, "ip");
00106
00107
00108 if (p2 == NULL)
00109 break;
00110
00111
00112 c = *p2;
00113 *p2 = 0;
00114 *fps = strtod( p1 + 1, &tail);
00115
00116
00117 if (*tail != '\0' || *(p1 + 1) == '\0')
00118 {
00119 *p2 = c;
00120 p1 = tail;
00121 continue;
00122 }
00123
00124
00125 *p2 = c;
00126 break;
00127 }
00128
00129
00130 if (p1 == NULL || p2 == NULL)
00131 {
00132 for (i = 0; VideoRes[i].name != NULL; i++)
00133 {
00134 if (strcasecmp (fn, VideoRes[i].name))
00135 {
00136 *x_size = VideoRes[i].x_size;
00137 *y_size = VideoRes[i].y_size;
00138
00139 break;
00140 }
00141 }
00142 }
00143
00144 return (*x_size == -1 || *y_size == -1) ? 0 : 1;
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154 void ParseFrameNoFormatFromString (VideoDataFile *input_file)
00155 {
00156 char *p1, *p2, *tail;
00157 char *fn = input_file->fname;
00158 char *fhead = input_file->fhead;
00159 char *ftail = input_file->ftail;
00160 int *zero_pad = &input_file->zero_pad;
00161 int *num_digits = &input_file->num_digits;
00162
00163 *zero_pad = 0;
00164 *num_digits = -1;
00165 p1 = p2 = fn;
00166 while (p1 != NULL && p2 != NULL)
00167 {
00168
00169 p1 = strstr( p1, "%");
00170 if (p1 == NULL)
00171 break;
00172
00173 strncpy(fhead, fn, p1 - fn);
00174
00175
00176 p2 = strstr( p1, "d");
00177
00178
00179 if (p2 == NULL)
00180 break;
00181
00182
00183 *p2 = 0;
00184
00185 if (*(p1 + 1) == '0')
00186 *zero_pad = 1;
00187
00188 *num_digits = strtol( p1 + 1, &tail, 10);
00189
00190
00191 if (*tail != '\0' || *(p1 + 1) == '\0')
00192 {
00193 *p2 = 'd';
00194 p1 = tail;
00195 continue;
00196 }
00197
00198
00199 *p2 = 'd';
00200
00201 tail++;
00202 strncpy(ftail, tail, strlen(tail));
00203 break;
00204 }
00205
00206 if (input_file->vdtype == VIDEO_TIFF)
00207 {
00208 input_file->is_concatenated = 0;
00209 }
00210 else
00211 input_file->is_concatenated = (*num_digits == -1) ? 1 : 0;
00212 }
00213
00214
00215
00216
00217
00218
00219
00220 void OpenFrameFile( VideoDataFile *input_file, int FrameNumberInFile)
00221 {
00222 char infile [FILE_NAME_SIZE], in_number[16];
00223 int length = 0;
00224 in_number[length]='\0';
00225 length = strlen(input_file->fhead);
00226 strncpy(infile, input_file->fhead, length);
00227 infile[length]='\0';
00228 if (input_file->zero_pad)
00229 snprintf(in_number, 16, "%0*d", input_file->num_digits, FrameNumberInFile);
00230 else
00231 snprintf(in_number, 16, "%*d", input_file->num_digits, FrameNumberInFile);
00232
00233 strncat(infile, in_number, sizeof(in_number));
00234 length += sizeof(in_number);
00235 infile[length]='\0';
00236 strncat(infile, input_file->ftail, strlen(input_file->ftail));
00237 length += strlen(input_file->ftail);
00238 infile[length]='\0';
00239
00240 if ((input_file->f_num = open(infile, OPENFLAGS_READ)) == -1)
00241 {
00242 printf ("OpenFrameFile: cannot open file %s\n", infile);
00243 report_stats_on_error();
00244 }
00245 }
00246
00247
00248
00249
00250
00251
00252
00253 void OpenFiles( VideoDataFile *input_file)
00254 {
00255 if (input_file->is_concatenated == 1)
00256 {
00257 if (strlen(input_file->fname) == 0)
00258 {
00259 snprintf(errortext, ET_SIZE, "No input sequence name was provided. Please check settings.");
00260 error (errortext, 500);
00261 }
00262
00263 if ((input_file->f_num = open(input_file->fname, OPENFLAGS_READ)) == -1)
00264 {
00265 snprintf(errortext, ET_SIZE, "Input file %s does not exist",input_file->fname);
00266 error (errortext, 500);
00267 }
00268 }
00269 }
00270
00271
00272
00273
00274
00275
00276
00277 void CloseFiles(VideoDataFile *input_file)
00278 {
00279 if (input_file->f_num != -1)
00280 close(input_file->f_num);
00281 input_file->f_num = -1;
00282 }
00283
00284
00285
00286
00287
00288
00289
00290 VideoFileType ParseVideoType (VideoDataFile *input_file)
00291 {
00292 char *format;
00293
00294 format = input_file->fname + strlen(input_file->fname) - 3;
00295
00296 if (strcasecmp (format, "yuv") == 0)
00297 {
00298 input_file->vdtype = VIDEO_YUV;
00299 input_file->format.yuv_format = YUV420;
00300 input_file->avi = NULL;
00301 }
00302 else if (strcasecmp (format, "rgb") == 0)
00303 {
00304 input_file->vdtype = VIDEO_RGB;
00305 input_file->format.yuv_format = YUV444;
00306 input_file->avi = NULL;
00307 }
00308 else if (strcasecmp (format, "tif") == 0)
00309 {
00310 input_file->vdtype = VIDEO_TIFF;
00311 input_file->avi = NULL;
00312 }
00313 else if (strcasecmp (format, "avi") == 0)
00314 {
00315 input_file->vdtype = VIDEO_AVI;
00316 }
00317 else
00318 {
00319
00320
00321 input_file->vdtype = VIDEO_YUV;
00322 input_file->format.yuv_format = YUV420;
00323 input_file->avi = NULL;
00324 }
00325
00326 return input_file->vdtype;
00327 }