void avfilter_unref_buffer(AVFilterBufferRef *ref)
{
    if (!ref)
        return;
    if (!(--ref->buf->refcount))
        ref->buf->free(ref->buf);
    if (ref->extended_data != ref->data)
        av_freep(&ref->extended_data);
    av_free(ref->video);
    av_free(ref->audio);
    av_free(ref);
}
['static int poll_filters(void)\n{\n    AVFilterBufferRef *picref;\n    AVFrame *filtered_frame = NULL;\n    int i, frame_size;\n    for (i = 0; i < nb_output_streams; i++) {\n        OutputStream *ost = output_streams[i];\n        OutputFile    *of = output_files[ost->file_index];\n        int ret = 0;\n        if (!ost->filter)\n            continue;\n        if (!ost->filtered_frame && !(ost->filtered_frame = avcodec_alloc_frame())) {\n            return AVERROR(ENOMEM);\n        } else\n            avcodec_get_frame_defaults(ost->filtered_frame);\n        filtered_frame = ost->filtered_frame;\n        while (ret >= 0 && !ost->is_past_recording_time) {\n            if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&\n                !(ost->enc->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE))\n                ret = av_buffersink_read_samples(ost->filter->filter, &picref,\n                                                 ost->st->codec->frame_size);\n            else\n                ret = av_buffersink_read(ost->filter->filter, &picref);\n            if (ret < 0)\n                break;\n            avfilter_copy_buf_props(filtered_frame, picref);\n            if (picref->pts != AV_NOPTS_VALUE) {\n                filtered_frame->pts = av_rescale_q(picref->pts,\n                                                   ost->filter->filter->inputs[0]->time_base,\n                                                   ost->st->codec->time_base) -\n                                      av_rescale_q(of->start_time,\n                                                   AV_TIME_BASE_Q,\n                                                   ost->st->codec->time_base);\n                if (of->start_time && filtered_frame->pts < 0) {\n                    avfilter_unref_buffer(picref);\n                    continue;\n                }\n            }\n            switch (ost->filter->filter->inputs[0]->type) {\n            case AVMEDIA_TYPE_VIDEO:\n                if (!ost->frame_aspect_ratio)\n                    ost->st->codec->sample_aspect_ratio = picref->video->pixel_aspect;\n                do_video_out(of->ctx, ost, filtered_frame, &frame_size,\n                             same_quant ? ost->last_quality :\n                                          ost->st->codec->global_quality);\n                if (vstats_filename && frame_size)\n                    do_video_stats(of->ctx, ost, frame_size);\n                break;\n            case AVMEDIA_TYPE_AUDIO:\n                do_audio_out(of->ctx, ost, filtered_frame);\n                break;\n            default:\n                av_assert0(0);\n            }\n            avfilter_unref_buffer(picref);\n        }\n    }\n    return 0;\n}', 'int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)\n{\n    return av_rescale_q_rnd(a, bq, cq, AV_ROUND_NEAR_INF);\n}', 'int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq,\n                         enum AVRounding rnd)\n{\n    int64_t b= bq.num * (int64_t)cq.den;\n    int64_t c= cq.num * (int64_t)bq.den;\n    return av_rescale_rnd(a, b, c, rnd);\n}', 'int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){\n    int64_t r=0;\n    assert(c > 0);\n    assert(b >=0);\n    assert((unsigned)rnd<=5 && rnd!=4);\n    if(a<0 && a != INT64_MIN) return -av_rescale_rnd(-a, b, c, rnd ^ ((rnd>>1)&1));\n    if(rnd==AV_ROUND_NEAR_INF) r= c/2;\n    else if(rnd&1)             r= c-1;\n    if(b<=INT_MAX && c<=INT_MAX){\n        if(a<=INT_MAX)\n            return (a * b + r)/c;\n        else\n            return a/c*b + (a%c*b + r)/c;\n    }else{\n#if 1\n        uint64_t a0= a&0xFFFFFFFF;\n        uint64_t a1= a>>32;\n        uint64_t b0= b&0xFFFFFFFF;\n        uint64_t b1= b>>32;\n        uint64_t t1= a0*b1 + a1*b0;\n        uint64_t t1a= t1<<32;\n        int i;\n        a0 = a0*b0 + t1a;\n        a1 = a1*b1 + (t1>>32) + (a0<t1a);\n        a0 += r;\n        a1 += a0<r;\n        for(i=63; i>=0; i--){\n            a1+= a1 + ((a0>>i)&1);\n            t1+=t1;\n            if( c <= a1){\n                a1 -= c;\n                t1++;\n            }\n        }\n        return t1;\n    }\n#else\n        AVInteger ai;\n        ai= av_mul_i(av_int2i(a), av_int2i(b));\n        ai= av_add_i(ai, av_int2i(r));\n        return av_i2int(av_div_i(ai, av_int2i(c)));\n    }\n#endif\n}', 'void avfilter_unref_buffer(AVFilterBufferRef *ref)\n{\n    if (!ref)\n        return;\n    if (!(--ref->buf->refcount))\n        ref->buf->free(ref->buf);\n    if (ref->extended_data != ref->data)\n        av_freep(&ref->extended_data);\n    av_free(ref->video);\n    av_free(ref->audio);\n    av_free(ref);\n}']