[XviD-devel] Variable frame rate and rate control

Makira makira at sympatico.ca
Sat Mar 15 00:43:04 CET 2003


Here's my mods: (I use /*mak*/ to keep track of my changes...

added:

/*mak*/    int frame_duration;                    /* [in] set to 0 if
average frame rate, in 90000 units per sec*/

in XVID_ENC_FRAME in xvid.h

Changed

void
RateControlUpdate(RateControl * rate_control,
                  int16_t quant,
                  int frame_size,
                  int keyframe,
/*mak*/              int32_t frame_duration)

In ratecontrol.h and .c

finally:

[...]
    int32_t rtn_quant;
    
    rate_control->frames++;
    rate_control->total_size += frame_size;
/*mak*/    if (frame_duration) rate_control->current_time += frame_duration;
/*mak*/    else rate_control->current_time += 90000 /
rate_control->framerate;
/*mak*/ rate_control->target_framesize = (double) rate_control->target_rate
/ 8.0 / ((rate_control->frames * 90000) / rate_control->current_time);

    deviation =
        (int64_t) ((double) rate_control->total_size -
/*mak*/               ((double) rate_control->target_framesize
                   * (double) rate_control->frames));

    DPRINTF(DPRINTF_RC, "CBR: frame: %i, quant: %i, deviation: %i\n",
                    (int32_t)(rate_control->frames - 1),
                    rate_control->rtn_quant,
                    (int32_t) deviation);
[...]

In ratecontrol.c

The only other changes are in encoder.c, to pass the frame_duration from
xvid_enc_param to the function call.

While this doesn't changes the frame duration encoded in the bitstream (is
there such a thing ? I'm not mpeg video guru), this isn't a problem, at
least in my case. I send the frameDuration directly to the mp4 muxer, and
quicktime seems to follow that info anyway.

At least, I have nicely working rate control.

Thank you for your great work on xvid.




More information about the XviD-devel mailing list