void avfilter_formats_unref(AVFilterFormats **ref)
{
    int idx;
    if (!*ref)
        return;
    idx = find_ref_index(ref);
    if(idx >= 0)
        memmove((*ref)->refs + idx, (*ref)->refs + idx+1,
            sizeof(AVFilterFormats**) * ((*ref)->refcount-idx-1));
    if(!--(*ref)->refcount) {
        av_free((*ref)->formats);
        av_free((*ref)->refs);
        av_free(*ref);
    }
    *ref = NULL;
}
['void avfilter_destroy(AVFilterContext *filter)\n{\n    int i;\n    if(filter->filter->uninit)\n        filter->filter->uninit(filter);\n    for(i = 0; i < filter->input_count; i ++) {\n        if(filter->inputs[i]) {\n            if (filter->inputs[i]->src)\n                filter->inputs[i]->src->outputs[filter->inputs[i]->srcpad] = NULL;\n            avfilter_formats_unref(&filter->inputs[i]->in_formats);\n            avfilter_formats_unref(&filter->inputs[i]->out_formats);\n        }\n        av_freep(&filter->inputs[i]);\n    }\n    for(i = 0; i < filter->output_count; i ++) {\n        if(filter->outputs[i]) {\n            if (filter->outputs[i]->dst)\n                filter->outputs[i]->dst->inputs[filter->outputs[i]->dstpad] = NULL;\n            avfilter_formats_unref(&filter->outputs[i]->in_formats);\n            avfilter_formats_unref(&filter->outputs[i]->out_formats);\n        }\n        av_freep(&filter->outputs[i]);\n    }\n    av_freep(&filter->name);\n    av_freep(&filter->input_pads);\n    av_freep(&filter->output_pads);\n    av_freep(&filter->inputs);\n    av_freep(&filter->outputs);\n    av_freep(&filter->priv);\n    av_free(filter);\n}', 'void avfilter_formats_unref(AVFilterFormats **ref)\n{\n    int idx;\n    if (!*ref)\n        return;\n    idx = find_ref_index(ref);\n    if(idx >= 0)\n        memmove((*ref)->refs + idx, (*ref)->refs + idx+1,\n            sizeof(AVFilterFormats**) * ((*ref)->refcount-idx-1));\n    if(!--(*ref)->refcount) {\n        av_free((*ref)->formats);\n        av_free((*ref)->refs);\n        av_free(*ref);\n    }\n    *ref = NULL;\n}', 'static int find_ref_index(AVFilterFormats **ref)\n{\n    int i;\n    for(i = 0; i < (*ref)->refcount; i ++)\n        if((*ref)->refs[i] == ref)\n            return i;\n    return -1;\n}']