Package: videohash
The Python package for near duplicate video detectionIntroductionVideohash is aPython packagefordetecting near-duplicate videos (Perceptual Video Hashing).
It can take any input video and generate a 64-bit equivalent hash value. Videohash is way more faster than comparing the imagehash values of individualframesof the video and more reliable than hashingkeyframes.The video-hash-values for identical or near-duplicate videos are the same or similar, implying that if the video is resized (upscaled/downscaled),transcoded,watermarkadded/removed,stabilized,color changed,frame ratechanged, changedaspect ratio,cropped,black-barsadded or removed, the hash-value should remain unchanged or not vary substantially.How the hash values are calculatedEvery one second, a frame from the input video is extracted, the frames are shrunk to a 144x144 pixel square, a collage is constructed that contains all of the resized frames(square-shaped), the collage'swavelet hash's bit-list is the first bit-list that we use. The frames extracted are now stitched horizontally to each other, and finally divided into 64 equal sized images, the domiant color of these 64 images are detected and compared with a pre-defined pattern of dominant colors, if they match the bit is set else unset. So now we have two bitlist, finally we bitwise XOR these two bitlists. The XOR'ed output is  used to generate the final 64 bit hash-value for the video. The bits are joined to form the 64 bit hash-value of the  input value.When not to use VideohashVideohash cannot be used to verify whether one video is a part of another (video fingerprinting). If the video is reversed or rotated by a substantial angle (greater than 10 degrees), Videohash will not provide the same or similar hash result, but you can always reverse the video manually and generate the hash value for reversed video.How to compare the video hash values stored in a databaseReadHamming Distance / Similarity searches in a database - Stack Overflow(Archive link)InstallationTo use this software, you must haveFFmpeginstalled. Please readhow to install FFmpegif you don't already know how.Install videohashUpgrade pippython3-mpipinstall--upgradepipIf you do not want to upgrade pip and the installation fails try appending--prefer-binaryto the following installation command(s).Install from thePyPi(recommended):pipinstallvideohashUsingconda, fromconda-forge(recommended):Maintainer is@step21condainstall-cconda-forgevideohashInstall directly fromtheGitHub repository (NOT recommended):pipinstallgit+https://github.com/akamhy/videohash.gitFeaturesGenerate videohash of a video directly from its URL(usesyt-dlp) or its path.Can be used as the core of a scalable Near Duplicate Video Retrieval (NDVR) system.The end-user can access the image representation(the collage) of the video.A videohash instance can be compared to a 64-bit stored hash, its hex representation, bitlist, and other videohash instances.UsageIn the following usage example the first two and the fourth instance of VideoHash class are computing the hash for the same video(not same as in checksum) and the third one is a different video.videohash1 is the VideoHash object for the video athttps://user-images.githubusercontent.com/64683866/168872267-7c6682f8-7294-4d9a-8a68-8c6f44c06df6.mp4.videohash2 video (link :https://user-images.githubusercontent.com/64683866/168869109-1f77c839-6912-4e24-8738-42cb15f3ab47.mp4) is upscaled, FPS changed and a text overlay added version of the first video, url1 athttps://user-images.githubusercontent.com/64683866/168872267-7c6682f8-7294-4d9a-8a68-8c6f44c06df6.mp4.videohash3 video is a completely different video, athttps://user-images.githubusercontent.com/64683866/148960165-a210f2d2-6c41-4349-bd8d-a4cb673bc0af.mp4.videohash4 video is a local copy of url1,https://user-images.githubusercontent.com/64683866/168872267-7c6682f8-7294-4d9a-8a68-8c6f44c06df6.mp4.>>>fromvideohashimportVideoHash>>>url1="https://user-images.githubusercontent.com/64683866/168872267-7c6682f8-7294-4d9a-8a68-8c6f44c06df6.mp4">>>videohash1=VideoHash(url=url1)>>>>>>url2="https://user-images.githubusercontent.com/64683866/168869109-1f77c839-6912-4e24-8738-42cb15f3ab47.mp4">>>videohash2=VideoHash(url=url2)>>>videohash2-videohash12>>>videohash2.is_similar(videohash1)True>>>>>>url3="https://user-images.githubusercontent.com/64683866/148960165-a210f2d2-6c41-4349-bd8d-a4cb673bc0af.mp4">>>videohash3=VideoHash(url=url3)>>>videohash3.is_similar(videohash1)False>>>videohash3.is_diffrent(videohash2)True>>>videohash3-videohash134>>>videohash3-videohash234>>>path4="/home/akamhy/Downloads/168872267-7c6682f8-7294-4d9a-8a68-8c6f44c06df6.mp4">>>videohash4=VideoHash(path=path4)>>>videohash4==videohash1True>>>videohash4-videohash10>>>videohash4.is_similar(videohash2)True>>>videohash4.is_similar(videohash4)True>>>videohash4.is_similar(videohash3)False>>>Extended Usage:https://github.com/akamhy/videohash/wiki/Extended-UsageAPI Reference:https://github.com/akamhy/videohash/wiki/API-ReferenceCreditsJohannesBuchnerandbunchesofdonaldforimagehash.Dmitry Petrovforimplementingdiscrete wavelet transform(DWT) based image hashing in Python.FFmpeg developers.Sam Dobsonforimage_slicer, videohash incorporates some code from image_slicer.Eddievinfor README design.iconolocodefor the videohash logo.LicenseCopyright (c) 2021-2022 Akash Mahanty. Seelicensefor details.The VideoHash logo was created byiconolocode. Seelicensefor details.Videos are from NASA and are in the public domain.NASA copyright policy states that "NASA material is not protected by copyright unless noted".