mirror of
				https://git.ffmpeg.org/ffmpeg.git
				synced 2025-11-04 01:30:56 +00:00 
			
		
		
		
	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 Originally committed as revision 9288 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
		
							parent
							
								
									0a4f20c6c5
								
							
						
					
					
						commit
						26ef3220cf
					
				
					 4 changed files with 145 additions and 105 deletions
				
			
		| 
						 | 
					@ -2882,6 +2882,30 @@ attribute_deprecated int img_pad(AVPicture *dst, const AVPicture *src, int heigh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
 | 
					extern unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Parses \p str and put in \p width_ptr and \p height_ptr the detected values.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return 0 in case of a successfull parsing, a negative value otherwise
 | 
				
			||||||
 | 
					 * @param[in] str the string to parse: it has to be a string in the format
 | 
				
			||||||
 | 
					 * <width>x<height> or a valid video frame size abbreviation.
 | 
				
			||||||
 | 
					 * @param[in,out] width_ptr pointer to the variable which will contain the detected
 | 
				
			||||||
 | 
					 * frame width value
 | 
				
			||||||
 | 
					 * @param[in,out] height_ptr pointer to the variable which will contain the detected
 | 
				
			||||||
 | 
					 * frame height value
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Parses \p str and put in \p frame_rate the detected values.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return 0 in case of a successfull parsing, a negative value otherwise
 | 
				
			||||||
 | 
					 * @param[in] str the string to parse: it has to be a string in the format
 | 
				
			||||||
 | 
					 * <frame_rate_nom>/<frame_rate_den>, a float number or a valid video rate abbreviation
 | 
				
			||||||
 | 
					 * @param[in,out] frame_rate pointer to the AVRational which will contain the detected
 | 
				
			||||||
 | 
					 * frame rate
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int av_parse_video_frame_rate(AVRational *frame_rate, const char *str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* error handling */
 | 
					/* error handling */
 | 
				
			||||||
#if EINVAL > 0
 | 
					#if EINVAL > 0
 | 
				
			||||||
#define AVERROR(e) (-(e)) /**< Returns a negative error code from a POSIX error code, to return from library functions. */
 | 
					#define AVERROR(e) (-(e)) /**< Returns a negative error code from a POSIX error code, to return from library functions. */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1347,3 +1347,113 @@ int av_tempfile(char *prefix, char **filename) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return fd; /* success */
 | 
					    return fd; /* success */
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					    const char *abv;
 | 
				
			||||||
 | 
					    int width, height;
 | 
				
			||||||
 | 
					    int frame_rate, frame_rate_base;
 | 
				
			||||||
 | 
					} AbvEntry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static AbvEntry frame_abvs[] = {
 | 
				
			||||||
 | 
					    { "ntsc",      720, 480, 30000, 1001 },
 | 
				
			||||||
 | 
					    { "pal",       720, 576,    25,    1 },
 | 
				
			||||||
 | 
					    { "qntsc",     352, 240, 30000, 1001 }, /* VCD compliant ntsc */
 | 
				
			||||||
 | 
					    { "qpal",      352, 288,    25,    1 }, /* VCD compliant pal */
 | 
				
			||||||
 | 
					    { "sntsc",     640, 480, 30000, 1001 }, /* square pixel NTSC */
 | 
				
			||||||
 | 
					    { "spal",      768, 576,    25,    1 }, /* square pixel PAL */
 | 
				
			||||||
 | 
					    { "film",      352, 240,    24,    1 },
 | 
				
			||||||
 | 
					    { "ntsc-film", 352, 240, 24000, 1001 },
 | 
				
			||||||
 | 
					    { "sqcif",     128,  96,     0,    0 },
 | 
				
			||||||
 | 
					    { "qcif",      176, 144,     0,    0 },
 | 
				
			||||||
 | 
					    { "cif",       352, 288,     0,    0 },
 | 
				
			||||||
 | 
					    { "4cif",      704, 576,     0,    0 },
 | 
				
			||||||
 | 
					    { "qqvga",     160, 120,     0,    0 },
 | 
				
			||||||
 | 
					    { "qvga",      320, 240,     0,    0 },
 | 
				
			||||||
 | 
					    { "vga",       640, 480,     0,    0 },
 | 
				
			||||||
 | 
					    { "svga",      800, 600,     0,    0 },
 | 
				
			||||||
 | 
					    { "xga",      1024, 768,     0,    0 },
 | 
				
			||||||
 | 
					    { "uxga",     1600,1200,     0,    0 },
 | 
				
			||||||
 | 
					    { "qxga",     2048,1536,     0,    0 },
 | 
				
			||||||
 | 
					    { "sxga",     1280,1024,     0,    0 },
 | 
				
			||||||
 | 
					    { "qsxga",    2560,2048,     0,    0 },
 | 
				
			||||||
 | 
					    { "hsxga",    5120,4096,     0,    0 },
 | 
				
			||||||
 | 
					    { "wvga",      852, 480,     0,    0 },
 | 
				
			||||||
 | 
					    { "wxga",     1366, 768,     0,    0 },
 | 
				
			||||||
 | 
					    { "wsxga",    1600,1024,     0,    0 },
 | 
				
			||||||
 | 
					    { "wuxga",    1920,1200,     0,    0 },
 | 
				
			||||||
 | 
					    { "woxga",    2560,1600,     0,    0 },
 | 
				
			||||||
 | 
					    { "wqsxga",   3200,2048,     0,    0 },
 | 
				
			||||||
 | 
					    { "wquxga",   3840,2400,     0,    0 },
 | 
				
			||||||
 | 
					    { "whsxga",   6400,4096,     0,    0 },
 | 
				
			||||||
 | 
					    { "whuxga",   7680,4800,     0,    0 },
 | 
				
			||||||
 | 
					    { "cga",       320, 200,     0,    0 },
 | 
				
			||||||
 | 
					    { "ega",       640, 350,     0,    0 },
 | 
				
			||||||
 | 
					    { "hd480",     852, 480,     0,    0 },
 | 
				
			||||||
 | 
					    { "hd720",    1280, 720,     0,    0 },
 | 
				
			||||||
 | 
					    { "hd1080",   1920,1080,     0,    0 },
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int i;
 | 
				
			||||||
 | 
					    int n = sizeof(frame_abvs) / sizeof(AbvEntry);
 | 
				
			||||||
 | 
					    const char *p;
 | 
				
			||||||
 | 
					    int frame_width = 0, frame_height = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for(i=0;i<n;i++) {
 | 
				
			||||||
 | 
					        if (!strcmp(frame_abvs[i].abv, str)) {
 | 
				
			||||||
 | 
					            frame_width = frame_abvs[i].width;
 | 
				
			||||||
 | 
					            frame_height = frame_abvs[i].height;
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (i == n) {
 | 
				
			||||||
 | 
					        p = str;
 | 
				
			||||||
 | 
					        frame_width = strtol(p, (char **)&p, 10);
 | 
				
			||||||
 | 
					        if (*p)
 | 
				
			||||||
 | 
					            p++;
 | 
				
			||||||
 | 
					        frame_height = strtol(p, (char **)&p, 10);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (frame_width <= 0 || frame_height <= 0)
 | 
				
			||||||
 | 
					        return -1;
 | 
				
			||||||
 | 
					    *width_ptr = frame_width;
 | 
				
			||||||
 | 
					    *height_ptr = frame_height;
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int i;
 | 
				
			||||||
 | 
					    char* cp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* First, we check our abbreviation table */
 | 
				
			||||||
 | 
					    for (i = 0; i < sizeof(frame_abvs)/sizeof(*frame_abvs); ++i)
 | 
				
			||||||
 | 
					         if (!strcmp(frame_abvs[i].abv, arg)) {
 | 
				
			||||||
 | 
					             frame_rate->num = frame_abvs[i].frame_rate;
 | 
				
			||||||
 | 
					             frame_rate->den = frame_abvs[i].frame_rate_base;
 | 
				
			||||||
 | 
					             return 0;
 | 
				
			||||||
 | 
					         }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Then, we try to parse it as fraction */
 | 
				
			||||||
 | 
					    cp = strchr(arg, '/');
 | 
				
			||||||
 | 
					    if (!cp)
 | 
				
			||||||
 | 
					        cp = strchr(arg, ':');
 | 
				
			||||||
 | 
					    if (cp) {
 | 
				
			||||||
 | 
					        char* cpp;
 | 
				
			||||||
 | 
					        frame_rate->num = strtol(arg, &cpp, 10);
 | 
				
			||||||
 | 
					        if (cpp != arg || cpp == cp)
 | 
				
			||||||
 | 
					            frame_rate->den = strtol(cp+1, &cpp, 10);
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					           frame_rate->num = 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else {
 | 
				
			||||||
 | 
					        /* Finally we give up and parse it as double */
 | 
				
			||||||
 | 
					        AVRational time_base = av_d2q(strtod(arg, 0), DEFAULT_FRAME_RATE_BASE);
 | 
				
			||||||
 | 
					        frame_rate->den = time_base.den;
 | 
				
			||||||
 | 
					        frame_rate->num = time_base.num;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (!frame_rate->num || !frame_rate->den)
 | 
				
			||||||
 | 
					        return -1;
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -763,13 +763,15 @@ void dump_format(AVFormatContext *ic,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * parses width and height out of string str.
 | 
					 * parses width and height out of string str.
 | 
				
			||||||
 | 
					 * @deprecated Use av_parse_video_frame_size instead.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
 | 
					attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Converts frame rate from string to a fraction.
 | 
					 * Converts frame rate from string to a fraction.
 | 
				
			||||||
 | 
					 * @deprecated Use av_parse_video_frame_rate instead.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
 | 
					attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Converts date string to number of seconds since Jan 1st, 1970.
 | 
					 * Converts date string to number of seconds since Jan 1st, 1970.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2482,114 +2482,18 @@ void dump_format(AVFormatContext *ic,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					 | 
				
			||||||
    const char *abv;
 | 
					 | 
				
			||||||
    int width, height;
 | 
					 | 
				
			||||||
    int frame_rate, frame_rate_base;
 | 
					 | 
				
			||||||
} AbvEntry;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static AbvEntry frame_abvs[] = {
 | 
					 | 
				
			||||||
    { "ntsc",      720, 480, 30000, 1001 },
 | 
					 | 
				
			||||||
    { "pal",       720, 576,    25,    1 },
 | 
					 | 
				
			||||||
    { "qntsc",     352, 240, 30000, 1001 }, /* VCD compliant ntsc */
 | 
					 | 
				
			||||||
    { "qpal",      352, 288,    25,    1 }, /* VCD compliant pal */
 | 
					 | 
				
			||||||
    { "sntsc",     640, 480, 30000, 1001 }, /* square pixel ntsc */
 | 
					 | 
				
			||||||
    { "spal",      768, 576,    25,    1 }, /* square pixel pal */
 | 
					 | 
				
			||||||
    { "film",      352, 240,    24,    1 },
 | 
					 | 
				
			||||||
    { "ntsc-film", 352, 240, 24000, 1001 },
 | 
					 | 
				
			||||||
    { "sqcif",     128,  96,     0,    0 },
 | 
					 | 
				
			||||||
    { "qcif",      176, 144,     0,    0 },
 | 
					 | 
				
			||||||
    { "cif",       352, 288,     0,    0 },
 | 
					 | 
				
			||||||
    { "4cif",      704, 576,     0,    0 },
 | 
					 | 
				
			||||||
    { "qqvga",     160, 120,     0,    0 },
 | 
					 | 
				
			||||||
    { "qvga",      320, 240,     0,    0 },
 | 
					 | 
				
			||||||
    { "vga",       640, 480,     0,    0 },
 | 
					 | 
				
			||||||
    { "svga",      800, 600,     0,    0 },
 | 
					 | 
				
			||||||
    { "xga",      1024, 768,     0,    0 },
 | 
					 | 
				
			||||||
    { "uxga",     1600,1200,     0,    0 },
 | 
					 | 
				
			||||||
    { "qxga",     2048,1536,     0,    0 },
 | 
					 | 
				
			||||||
    { "sxga",     1280,1024,     0,    0 },
 | 
					 | 
				
			||||||
    { "qsxga",    2560,2048,     0,    0 },
 | 
					 | 
				
			||||||
    { "hsxga",    5120,4096,     0,    0 },
 | 
					 | 
				
			||||||
    { "wvga",      852, 480,     0,    0 },
 | 
					 | 
				
			||||||
    { "wxga",     1366, 768,     0,    0 },
 | 
					 | 
				
			||||||
    { "wsxga",    1600,1024,     0,    0 },
 | 
					 | 
				
			||||||
    { "wuxga",    1920,1200,     0,    0 },
 | 
					 | 
				
			||||||
    { "woxga",    2560,1600,     0,    0 },
 | 
					 | 
				
			||||||
    { "wqsxga",   3200,2048,     0,    0 },
 | 
					 | 
				
			||||||
    { "wquxga",   3840,2400,     0,    0 },
 | 
					 | 
				
			||||||
    { "whsxga",   6400,4096,     0,    0 },
 | 
					 | 
				
			||||||
    { "whuxga",   7680,4800,     0,    0 },
 | 
					 | 
				
			||||||
    { "cga",       320, 200,     0,    0 },
 | 
					 | 
				
			||||||
    { "ega",       640, 350,     0,    0 },
 | 
					 | 
				
			||||||
    { "hd480",     852, 480,     0,    0 },
 | 
					 | 
				
			||||||
    { "hd720",    1280, 720,     0,    0 },
 | 
					 | 
				
			||||||
    { "hd1080",   1920,1080,     0,    0 },
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int parse_image_size(int *width_ptr, int *height_ptr, const char *str)
 | 
					int parse_image_size(int *width_ptr, int *height_ptr, const char *str)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int i;
 | 
					    return av_parse_video_frame_size(width_ptr, height_ptr, str);
 | 
				
			||||||
    int n = sizeof(frame_abvs) / sizeof(AbvEntry);
 | 
					 | 
				
			||||||
    const char *p;
 | 
					 | 
				
			||||||
    int frame_width = 0, frame_height = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for(i=0;i<n;i++) {
 | 
					 | 
				
			||||||
        if (!strcmp(frame_abvs[i].abv, str)) {
 | 
					 | 
				
			||||||
            frame_width = frame_abvs[i].width;
 | 
					 | 
				
			||||||
            frame_height = frame_abvs[i].height;
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (i == n) {
 | 
					 | 
				
			||||||
        p = str;
 | 
					 | 
				
			||||||
        frame_width = strtol(p, (char **)&p, 10);
 | 
					 | 
				
			||||||
        if (*p)
 | 
					 | 
				
			||||||
            p++;
 | 
					 | 
				
			||||||
        frame_height = strtol(p, (char **)&p, 10);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (frame_width <= 0 || frame_height <= 0)
 | 
					 | 
				
			||||||
        return -1;
 | 
					 | 
				
			||||||
    *width_ptr = frame_width;
 | 
					 | 
				
			||||||
    *height_ptr = frame_height;
 | 
					 | 
				
			||||||
    return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg)
 | 
					int parse_frame_rate(int *frame_rate_num, int *frame_rate_den, const char *arg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int i;
 | 
					    AVRational frame_rate;
 | 
				
			||||||
    char* cp;
 | 
					    int ret = av_parse_video_frame_rate(&frame_rate, arg);
 | 
				
			||||||
 | 
					    *frame_rate_num= frame_rate.num;
 | 
				
			||||||
    /* First, we check our abbreviation table */
 | 
					    *frame_rate_den= frame_rate.den;
 | 
				
			||||||
    for (i = 0; i < sizeof(frame_abvs)/sizeof(*frame_abvs); ++i)
 | 
					    return ret;
 | 
				
			||||||
         if (!strcmp(frame_abvs[i].abv, arg)) {
 | 
					 | 
				
			||||||
             *frame_rate = frame_abvs[i].frame_rate;
 | 
					 | 
				
			||||||
             *frame_rate_base = frame_abvs[i].frame_rate_base;
 | 
					 | 
				
			||||||
             return 0;
 | 
					 | 
				
			||||||
         }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* Then, we try to parse it as fraction */
 | 
					 | 
				
			||||||
    cp = strchr(arg, '/');
 | 
					 | 
				
			||||||
    if (!cp)
 | 
					 | 
				
			||||||
        cp = strchr(arg, ':');
 | 
					 | 
				
			||||||
    if (cp) {
 | 
					 | 
				
			||||||
        char* cpp;
 | 
					 | 
				
			||||||
        *frame_rate = strtol(arg, &cpp, 10);
 | 
					 | 
				
			||||||
        if (cpp != arg || cpp == cp)
 | 
					 | 
				
			||||||
            *frame_rate_base = strtol(cp+1, &cpp, 10);
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
           *frame_rate = 0;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    else {
 | 
					 | 
				
			||||||
        /* Finally we give up and parse it as double */
 | 
					 | 
				
			||||||
        AVRational time_base = av_d2q(strtod(arg, 0), DEFAULT_FRAME_RATE_BASE);
 | 
					 | 
				
			||||||
        *frame_rate_base = time_base.den;
 | 
					 | 
				
			||||||
        *frame_rate = time_base.num;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (!*frame_rate || !*frame_rate_base)
 | 
					 | 
				
			||||||
        return -1;
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
        return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int64_t parse_date(const char *datestr, int duration)
 | 
					int64_t parse_date(const char *datestr, int duration)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue