comparison utils.c @ 5126:7982b376b58a libavcodec

Move the video size and rate abbreviations system from libavformat to libavcodec patch by Stefano Sabatini: [stefano dot sabatini minus lala poste dot it] original thread: [FFmpeg-devel] [PATCH] Redesign the video size and rateabbreviations system date: 06/02/2007 05:30 PM
author benoit
date Tue, 12 Jun 2007 08:06:54 +0000
parents 270e6cce0be3
children 4dbe6578f811
comparison
equal deleted inserted replaced
5125:13ffe6b5bd0e 5126:7982b376b58a
1345 av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename); 1345 av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
1346 return -1; 1346 return -1;
1347 } 1347 }
1348 return fd; /* success */ 1348 return fd; /* success */
1349 } 1349 }
1350
1351 typedef struct {
1352 const char *abv;
1353 int width, height;
1354 int frame_rate, frame_rate_base;
1355 } AbvEntry;
1356
1357 static AbvEntry frame_abvs[] = {
1358 { "ntsc", 720, 480, 30000, 1001 },
1359 { "pal", 720, 576, 25, 1 },
1360 { "qntsc", 352, 240, 30000, 1001 }, /* VCD compliant ntsc */
1361 { "qpal", 352, 288, 25, 1 }, /* VCD compliant pal */
1362 { "sntsc", 640, 480, 30000, 1001 }, /* square pixel NTSC */
1363 { "spal", 768, 576, 25, 1 }, /* square pixel PAL */
1364 { "film", 352, 240, 24, 1 },
1365 { "ntsc-film", 352, 240, 24000, 1001 },
1366 { "sqcif", 128, 96, 0, 0 },
1367 { "qcif", 176, 144, 0, 0 },
1368 { "cif", 352, 288, 0, 0 },
1369 { "4cif", 704, 576, 0, 0 },
1370 { "qqvga", 160, 120, 0, 0 },
1371 { "qvga", 320, 240, 0, 0 },
1372 { "vga", 640, 480, 0, 0 },
1373 { "svga", 800, 600, 0, 0 },
1374 { "xga", 1024, 768, 0, 0 },
1375 { "uxga", 1600,1200, 0, 0 },
1376 { "qxga", 2048,1536, 0, 0 },
1377 { "sxga", 1280,1024, 0, 0 },
1378 { "qsxga", 2560,2048, 0, 0 },
1379 { "hsxga", 5120,4096, 0, 0 },
1380 { "wvga", 852, 480, 0, 0 },
1381 { "wxga", 1366, 768, 0, 0 },
1382 { "wsxga", 1600,1024, 0, 0 },
1383 { "wuxga", 1920,1200, 0, 0 },
1384 { "woxga", 2560,1600, 0, 0 },
1385 { "wqsxga", 3200,2048, 0, 0 },
1386 { "wquxga", 3840,2400, 0, 0 },
1387 { "whsxga", 6400,4096, 0, 0 },
1388 { "whuxga", 7680,4800, 0, 0 },
1389 { "cga", 320, 200, 0, 0 },
1390 { "ega", 640, 350, 0, 0 },
1391 { "hd480", 852, 480, 0, 0 },
1392 { "hd720", 1280, 720, 0, 0 },
1393 { "hd1080", 1920,1080, 0, 0 },
1394 };
1395
1396 int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str)
1397 {
1398 int i;
1399 int n = sizeof(frame_abvs) / sizeof(AbvEntry);
1400 const char *p;
1401 int frame_width = 0, frame_height = 0;
1402
1403 for(i=0;i<n;i++) {
1404 if (!strcmp(frame_abvs[i].abv, str)) {
1405 frame_width = frame_abvs[i].width;
1406 frame_height = frame_abvs[i].height;
1407 break;
1408 }
1409 }
1410 if (i == n) {
1411 p = str;
1412 frame_width = strtol(p, (char **)&p, 10);
1413 if (*p)
1414 p++;
1415 frame_height = strtol(p, (char **)&p, 10);
1416 }
1417 if (frame_width <= 0 || frame_height <= 0)
1418 return -1;
1419 *width_ptr = frame_width;
1420 *height_ptr = frame_height;
1421 return 0;
1422 }
1423
1424 int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg)
1425 {
1426 int i;
1427 char* cp;
1428
1429 /* First, we check our abbreviation table */
1430 for (i = 0; i < sizeof(frame_abvs)/sizeof(*frame_abvs); ++i)
1431 if (!strcmp(frame_abvs[i].abv, arg)) {
1432 frame_rate->num = frame_abvs[i].frame_rate;
1433 frame_rate->den = frame_abvs[i].frame_rate_base;
1434 return 0;
1435 }
1436
1437 /* Then, we try to parse it as fraction */
1438 cp = strchr(arg, '/');
1439 if (!cp)
1440 cp = strchr(arg, ':');
1441 if (cp) {
1442 char* cpp;
1443 frame_rate->num = strtol(arg, &cpp, 10);
1444 if (cpp != arg || cpp == cp)
1445 frame_rate->den = strtol(cp+1, &cpp, 10);
1446 else
1447 frame_rate->num = 0;
1448 }
1449 else {
1450 /* Finally we give up and parse it as double */
1451 AVRational time_base = av_d2q(strtod(arg, 0), DEFAULT_FRAME_RATE_BASE);
1452 frame_rate->den = time_base.den;
1453 frame_rate->num = time_base.num;
1454 }
1455 if (!frame_rate->num || !frame_rate->den)
1456 return -1;
1457 else
1458 return 0;
1459 }