changing codec parameters in midstream

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

changing codec parameters in midstream

I've been trying to dynamically increase qcomp and qmax parameters of x264
encoder in 'ffmpeg' to reduce streaming bitrate, e.g. I 've  been  trying
to  do  it after streaming started:

void ff_set_qcomp(float qcomp, int qmax, int qmin)

    int i;
    AVOutputStream* out;
//find output video stream
    for(i=0;i<nb_ostreams;i++) {
        out = ost_table[i];
        if (out->st->codec->codec_type == CODEC_TYPE_VIDEO)
//create new codec cotext
    AVCodecContext *ctx = avcodec_alloc_context();
    ctx->codec_id = out->st->codec->codec_id;
    ctx->qcompress = qcomp;
    ctx->qmax = qmax;
//copy other codec context parameters
    ctx->height = out->st->codec->height;
    ctx->width = out->st->codec->width;
AVCodec* xcodec = avcodec_find_encoder(ctx->codec_id);
//close existing codec
//open codec context with new parameters  - returns success status
    if (avcodec_open(ctx, xcodec) < 0) {
                fprintf(stderr, "Error while re- opening codec for output
stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or
                ost->file_index, ost->index);
//switch context
    ost_table[i]->st->codec = ctx;

Right after codec context is switched, "read_packet" call returns me End Of
File. Can someone tell me what I am missing, or recommend correct approach?
Thank you in adance,
libav-user mailing list
[hidden email]