If bug is random then you can compare two encodes with:
Code:
Subtract(clip1,clip2)
WriteFileIf (last, "log.log", "LumaDifference(clip1, clip2)>0", "current_frame")
In your case this at least should show first discrepancy in the files.
EDIT:
Just random idea: Interleave good_clip with encode_clip then check where there is no duplicate frame.