See the thread "libavfilter - avfilter_merge_formats heap corruption". I have not actually tested the patch since I cannot build ffmpeg on windows, actually on closer inspection I don't think it is correct.