Python code to find and display all the exact duplicate photos (images) and videos in a folder and delete them (optional).
Begins search at the current folder. Repeats it for all sub-directories as well.
All the duplicate Photos and Videos are displayed at the end of the program. Input "Y" to delete the duplicates.
Type | Run command |
---|---|
Photos | python duplicate_exact_photos.py |
Videos | python duplicate_exact_videos.py |
Or Run "duplicate_media_exact.bat" on a Windows system to run both programs sequentially (photos followed by videos).
Argument | Usage | Default |
---|---|---|
folder | Folder to begin the search. Subfolders are included. | Current path |
keep_largest | Keep the file with the largest or smallest size among the duplicates. 1 for largest and 0 for smallest. | 1: Keep largest |
compare_size | Photos are resized to this value for comparison. Higher value compares more pixels but requires more RAM and runs slower. |
300 gives accurate and fast results. |
This program requires Python with numpy, tqdm and CV2 libraries to function.
Run the following command to install the dependent libraries in the Python environment if they are not present already:
pip install -r requirements.txt
Photos are compared using pixel-wise comparison using cosine distance after setting them to a fixed size.
Videos are compared using pixel-wise comparisons using cosine distance on the first frame (with a fixed size) and by matching their frame length.