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 void end_frame(AVFilterLink *inlink)\n{\n    AVFilterContext    *ctx = inlink->dst;\n    FPSContext           *s = ctx->priv;\n    AVFilterLink   *outlink = ctx->outputs[0];\n    AVFilterBufferRef  *buf = inlink->cur_buf;\n    int64_t delta;\n    int i;\n    s->frames_in++;\n    if (s->pts == AV_NOPTS_VALUE) {\n        if (buf->pts != AV_NOPTS_VALUE) {\n            write_to_fifo(s->fifo, buf);\n            s->first_pts = s->pts = buf->pts;\n        } else {\n            av_log(ctx, AV_LOG_WARNING, "Discarding initial frame(s) with no "\n                   "timestamp.\\n");\n            avfilter_unref_buffer(buf);\n            s->drop++;\n        }\n        return;\n    }\n    if (buf->pts == AV_NOPTS_VALUE) {\n        write_to_fifo(s->fifo, buf);\n        return;\n    }\n    delta = av_rescale_q(buf->pts - s->pts, inlink->time_base,\n                         outlink->time_base);\n    if (delta < 1) {\n        AVFilterBufferRef *tmp;\n        int drop = av_fifo_size(s->fifo)/sizeof(AVFilterBufferRef*);\n        av_log(ctx, AV_LOG_DEBUG, "Dropping %d frame(s).\\n", drop);\n        s->drop += drop;\n        av_fifo_generic_read(s->fifo, &tmp, sizeof(tmp), NULL);\n        flush_fifo(s->fifo);\n        write_to_fifo(s->fifo, tmp);\n        avfilter_unref_buffer(buf);\n        return;\n    }\n    for (i = 0; i < delta; i++) {\n        AVFilterBufferRef *buf_out;\n        av_fifo_generic_read(s->fifo, &buf_out, sizeof(buf_out), NULL);\n        if (!av_fifo_size(s->fifo) && i < delta - 1) {\n            av_log(ctx, AV_LOG_DEBUG, "Duplicating frame.\\n");\n            write_to_fifo(s->fifo, avfilter_ref_buffer(buf_out, AV_PERM_READ));\n            s->dup++;\n        }\n        buf_out->pts = av_rescale_q(s->first_pts, inlink->time_base,\n                                    outlink->time_base) + s->frames_out;\n        avfilter_start_frame(outlink, buf_out);\n        avfilter_draw_slice(outlink, 0, outlink->h, 1);\n        avfilter_end_frame(outlink);\n        s->frames_out++;\n    }\n    flush_fifo(s->fifo);\n    write_to_fifo(s->fifo, buf);\n    s->pts = s->first_pts + av_rescale_q(s->frames_out, outlink->time_base, inlink->time_base);\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}']