Logo Search packages:      
Sourcecode: blender version File versions  Download package

int parse_frame_rate ( int *  frame_rate,
int *  frame_rate_base,
const char *  arg 
)

Converts frame rate from string to a fraction.

First we try to get an exact integer or fractional frame rate. If this fails we convert the frame rate to a double and return an approximate fraction using the DEFAULT_FRAME_RATE_BASE.

Definition at line 2718 of file utils.c.

References av_d2q(), AVRational::den, and AVRational::num.

{
    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 = 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;
}


Generated by  Doxygen 1.6.0   Back to index