[FFmpeg-devel] Encoding video stream into CIF and 25 fps video format

Anthony Chapellier anthony
Fri Oct 5 16:04:33 CEST 2007


Michel Bardiaux a ?crit :
> Anthony Chapellier a ?crit :
>   
>> Hi,
>>
>> I'm a beginner with video codecs and ffmpeg so I'd appreciate some help.^^
>>
>> I'm doing some devel on a program which encode a video stream provided 
>> by a webcam using h263 codec from libavcodec library. Until today, the 
>> program has been working perfectly fine and encoded the video into QCIF 
>> and 10fps video format.
>>
>> However, I wish to change those settings and encode the video into CIF 
>> and 25 fps video format. And this is my big problem !!! Firstly I'm 
>> unable to get 25 fps, the video stream don't go over 15 fps... 
>> Secondary, when I try to encode the video into CIF I got a lot of error 
>> messages :
>>
>> - rc buffer underflow
>> - concealing xxx DC, xxx AC, xxx MV errors
>>
>> And something weird is that the video quality is really good during a 
>> few seconds and after that it's full of grey pixels.So do you know how I 
>> could solve this problem ? is there some setting I didn't well like 
>> buffer size, bit rate or something else... ?
>>
>>     
>
> We cant do anything without the exact command used and its output messages.
>
>
>   
Unfortunately, I'm not using ffmpeg sofware but only libavcodec and 
libavformat in another application so I can't provide any command line. 
I can just provide how the settings are done and the error messages :

#define FF_MIN_BUFFER_SIZE 16384
#define MAX_ENC_BUFFER_SIZE (FF_MIN_BUFFER_SIZE * 32)

void *h263_encoder_init(void *ctx) {
    phvstream_t *s = (phvstream_t *)ctx;
    ph_h263_encoder_ctx_t * h263t;

    h263t = (ph_h263_encoder_ctx_t *) 
calloc(sizeof(ph_h263_encoder_ctx_t), 1);
    _h263_meta_init(&h263t->meta, s);
     h263t->max_frame_len = MAX_ENC_BUFFER_SIZE;
    h263t->data_enc = (uint8_t *) av_malloc (h263t->max_frame_len);

    phcodec_avcodec_encoder_init(&h263t->encoder_ctx, &h263t->meta, s);

    //h263t->encoder_ctx.context->flags |= CODEC_FLAG_QP_RD;
    //h263t->encoder_ctx.context->flags |= CODEC_FLAG_H263P_SLICE_STRUCT;
    h263t->encoder_ctx.context->flags |= CODEC_FLAG_QSCALE;

    //h263t->encoder_ctx.context->flags |= CODEC_FLAG_INPUT_PRESERVED;
    //h263t->encoder_ctx.context->flags |= CODEC_FLAG_EMU_EDGE;
    //h263t->encoder_ctx.context->flags |= CODEC_FLAG_PASS1;

    h263t->encoder_ctx.context->mb_decision = FF_MB_DECISION_RD;

    h263t->encoder_ctx.context->gop_size = 30;
    h263t->encoder_ctx.context->thread_count = 1;
#define DEFAULT_RATE    (16 * 8 * 1024)
    h263t->encoder_ctx.context->rc_min_rate = DEFAULT_RATE;
    h263t->encoder_ctx.context->rc_max_rate = DEFAULT_RATE;
    h263t->encoder_ctx.context->rc_buffer_size = DEFAULT_RATE * 64;
    h263t->encoder_ctx.context->bit_rate = DEFAULT_RATE;

    if (avcodec_open(h263t->encoder_ctx.context,
            h263t->encoder_ctx.encoder) < 0) {
        return 0;
    }

    return h263t;
}

This function replace some settings defined by the one above

void ph_video_bwcontrol_apply_user_params(phvstream_t *stream) {
    ph_h263_encoder_ctx_t *enc_ctx;
    ph_avcodec_encoder_ctx_t * av_enc_t;
    int q_compress, b_quant_offset, b_quant_factor, i_quant_factor, 
i_quant_offset;
    int quality, fps, gop_size, b_rate, img_quality;
    ph_mstream_params_t *msp = &stream->ms.mses->streams[PH_MSTREAM_VIDEO1];
[....]
        case PHAPI_VIDEO_LINE_1024KBPS:
            printf("video_bwcontrol: 1024kbps\n");
            b_rate = KB_PER_SEC(120);
            quality = 110;
            fps = 25;
            gop_size = 13;
            img_quality = 3;

[.....]

    gop_size = fps;

    enc_ctx = (ph_h263_encoder_ctx_t *) stream->ms.encoder_ctx;
    av_enc_t = &enc_ctx->encoder_ctx;

    av_enc_t->resized_pic->quality = img_quality;

#if 0
    av_enc_t->context->qcompress = (float)(quality / 100.0);
    av_enc_t->context->qblur = (float)(quality / 100.0);
#endif

    av_enc_t->context->b_quant_offset = (float)(2.0 - quality / 100.0);
    av_enc_t->context->b_quant_factor = (float)(2.0 - quality / 100.0);

    av_enc_t->context->i_quant_factor =  (float)(-1.0 + quality / 100.0);
    av_enc_t->context->i_quant_offset = (float)(0.0);


    av_enc_t->context->rc_min_rate = b_rate;
    av_enc_t->context->rc_max_rate = b_rate;
    av_enc_t->context->rc_buffer_size = b_rate * 64;
    av_enc_t->context->bit_rate = (b_rate * 3) >> 2;
    av_enc_t->context->bit_rate = b_rate;
    av_enc_t->context->bit_rate_tolerance = b_rate << 3;
    av_enc_t->context->max_qdiff = 3;
    av_enc_t->context->rc_qsquish = 0;
    av_enc_t->context->rc_eq = "tex^qComp";

    av_enc_t->context->gop_size = gop_size;

    av_enc_t->context->time_base.den = fps;
    av_enc_t->context->time_base.num = 1;

    stream->fps = fps;
    stream->fps_interleave_time = (1000/fps);

    if (stream->wt) {
        webcam_set_fps(stream->wt, fps);
    }
}

-- 
M. Anthony Chapellier
---------
MBDSYS SARL
1, centre commercial de la Tour
93120 LA COURNEUVE
FRANCE

Tel : +33 (0) 148 35 20 46
      +33 (0) 143 11 09 14
Fax : +33 (0) 148 37 79 28

http://www.mbdsys.com





More information about the ffmpeg-devel mailing list