#perceptual #hash #duplicate #phash #video-file

vid_dup_finder_lib

a library to find near-duplicate video files

3 releases

new 0.1.2 Dec 8, 2024
0.1.1 Aug 6, 2022
0.1.0 Oct 30, 2021

#105 in Video

Download history 244/week @ 2024-08-21 319/week @ 2024-08-28 239/week @ 2024-09-04 446/week @ 2024-09-11 312/week @ 2024-09-18 1168/week @ 2024-09-25 1369/week @ 2024-10-02 1404/week @ 2024-10-09 537/week @ 2024-10-16 512/week @ 2024-10-23 473/week @ 2024-10-30 420/week @ 2024-11-06 566/week @ 2024-11-13 462/week @ 2024-11-20 473/week @ 2024-11-27 316/week @ 2024-12-04

2,056 downloads per month
Used in 6 crates (3 directly)

MIT/Apache

2.5MB
912 lines

Video Duplicate Finder

vid_dup_finder finds near-duplicate video files on disk. It detects videos whose frames look similar, and where the videos are roughly the same length (within ~5%).

vid_dup_finder will work with most common video file formats (any format supported by FFMPEG.)

How it works

Video Duplicate finder extracts several frames from the first minute of each video. It creates a "perceptual hash" from these frames using 'Spatial' and 'Temporal' information from those frames:

  • The spatial component describes the parts of each frame that are bright and dark. It is generated using the pHash algorithm described in here
  • The temporal component describes the parts of each frame that are brighter/darker than the previous frame. (It is calculated directly from the bits of the spatial hash)

The resulting hashes can then be compared according to their hamming distance. Shorter distances represent similar videos.

Requirements

Ffmpeg must be installed on your system and be accessible on the command line. You can do this by:

  • Debian-based systems: # apt install ffmpeg
  • Yum-based systems: # yum install ffmpeg
  • Windows:
    1. Download the correct installer from https://ffmpeg.org/download.html
    2. Run the installer and install ffmpeg to any directory
    3. Add the directory into the PATH environment variable

Limitations

vid_dup_finder will find duplicates if minor changes have been made to the video, such as resizing, small colour corrections, small crops or faint watermarks. It will not find duplicates if there are larger changes (flipping or rotation, embedding in a corner of a different video etc)

To save processing time when working on large datasets, vid_dup_finder uses only frames from the first 30 seconds of any video. vid_dup_finder may return false positives when used on content of the same length and and a common first-30- seconds (for example a series of cartoons with a fixed into sequence)

False Positives

Because this library only checks the first 30 seconds of each video, if two videos are the same length and share the first 30 seconds of video content, they will be reported as a false match. This may occur for TV shows which contain opening credits.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~8MB
~152K SLoC