See Import RootsMagic 7 into Family Historian 7 (18386) for the background to this problem.
Attached is a prototype Check for Possible Duplicated Media plugin Version 1.3.3 Date 08 Apr 2021.
In all FH versions, it avoids Lua SQL used in earlier versions by using a simple text file instead. It's probably just as efficient.
( On close inspection, the original plugin never actually used the SQL database anyway due to a small typo

It will only merge Media records if identical in all respects, apart from the filename path, which can differ as long as the files themselves are identical.
It does not delete any unlinked duplicate files. Use Check for Unlinked Media to do that for internal Project files.
Perhaps test it on a copy Project initially.
Its effects can be reversed using Edit > Undo Plugin Updates before closing FH or by reverting to a Snapshot.
BTW: I've not yet actually tested it on FH V5/6 as it is primarily needed for FH V7 now.