[FFmpeg-devel] Spurious delay between DTS and PTS

C Chatterjee cchatterj at hotmail.com
Tue Sep 11 22:52:30 CEST 2012

I found an issue with the bf parameter initialization and associated problems.

bf (libx264 bframes) parameter is initialized to -1 in libavcodec/libx264.c as below:
static const AVCodecDefault x264_defaults[] = {
    { "b",                "0" },
    { "bf",               "-1" },

bf is then used to initialize AvCodecContext::max_b_frames in:
int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec){
    if (codec && codec->defaults) {
        int ret;
        const AVCodecDefault *d = codec->defaults;
        while (d->key) {
            ret = av_opt_set(s, d->key, d->value, 0);
            av_assert0(ret >= 0);
    return 0;

max_b_frames is later used in libavformat/utils.c as:
static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt){
    int delay = FFMAX(st->codec->has_b_frames, !!st->codec->max_b_frames);

If max_b_frames==-1 ie uninitialized, the above line will produce delay=1 which will create a latency delay between dts and pts which is unnecessary for say baseline H.264 sequences.

Chanchal Chatterjee

More information about the ffmpeg-devel mailing list