Comments (1)
I ran into another issue with the above approach: for some WEBM and MKV videos, pHash returns 0 hashes.
Cause: the frame count calculated in the above snippet is only an estimate. However, in ph_getKeyFramesFromVideo()
, this estimate is treated as solid fact. When that frame count is an overestimation, then the last few values in the dist
array are never written to, because the corresponding frames don't exist. If one of those places happens to hold a very small or even negative number, the associated (non-existent!) frame is selected as one of the frames to hash. ReadFrames()
throws no error when it is told to decode a frame past the end of the video, it simply returns 0, to indicate it decoded no frames. Thus, if a non-existent frame is selected for hashing, no frame is read, and if that's the only frame selected for hashing, then ph_getKeyFramesFromVideo()
returns 0 frames, and ph_dct_videohash()
calculates 0 hashes, all without any errors being reported.
If the frame count is an overestimation, the last portion of the video is simply ignored, which is only slightly less bad.
Solution: allocate space in the dist
array for 20% more frames than the header estimates, and when the end of the file has been reached, reduce the actual frame count as appropriate.
--- a/src/pHash.cpp
+++ b/src/pHash.cpp
@@ -354,6 +354,7 @@ CImgList<uint8_t> *ph_getKeyFramesFromVideo(const char *filename) {
if (N <= 0) {
return NULL;
}
+ N *= 1.2f;
float frames_per_sec = 0.5 * fps(filename);
if (frames_per_sec < 0) {
@@ -413,6 +414,8 @@ CImgList<uint8_t> *ph_getKeyFramesFromVideo(const char *filename) {
} while ((nbread >= st_info.nb_retrieval) && (k < nbframes));
vfinfo_close(&st_info);
+ nbframes = k;
+
int S = 10;
int L = 50;
int alpha1 = 3;
An alternative approach to the first half of the patch would be to change the snippet in the OP to overestimate by 20%, instead of doing it here. This would avoid some overallocation when the frame count is not an estimate, such as for MP4 containers, but would tie GetNumberOfVideoFrames()
and ph_getKeyFramesFromVideo()
more closely together, which may not be what you want.
from phash.
Related Issues (20)
- pHash.org Version Outdated
- cmake does not check for libtiff HOT 1
- Running make fails when building examples/test_dctvideohash.cpp HOT 1
- Using pHash data from an older version of pHash w/the current version HOT 1
- build issue HOT 1
- Add support for HEIF/HEIC images via libheif
- Doc for ph_hamming_distance is wrong
- bindings / PHP build HOT 2
- Radial hash ignores gamma parameter? HOT 1
- No ConvNet (pHashML) Documentation HOT 6
- Rounding logic looks strange HOT 1
- 'FORCE' settings in CMakeLists.txt? HOT 1
- 希望ph_dct_imagehash接口能支持传图片的二进制流 HOT 1
- Wrong phash value for 195x64 images HOT 1
- 请教这几个函数问题,谢谢 HOT 1
- _ph_image_digest function cimg exception when alpha channel present
- Unable to create .pylib file with Mac Sonoma.
- Invalid argument(s): Failed to load dynamic library 'phash.so': dlopen failed: cannot locate symbol "TIFFSetWarningHandler" referenced by "/data/app/~~dsq_8wJXYPiEvZhp0h9C8w==/com.example.tcg-n4L1yUnzT6xjvaZKt_iDZA==/lib/arm64/phash.so"...
- Build instructions need updating HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phash.