我已经使用最新的 ffmpeg 和 pHash 库(ffmpeg-2.2.1 和 pHash-0.9.6)以及 pHash ruby gem(https://github.com/toy/pHash)设置了我的系统。
我正在使用 ruby 并尝试比较两个视频文件,如下所示:
require 'phash/video'
video1 = Phash::Video.new('video1.mp4')
video2 = Phash::Video.new('video2.mp4')
video1 % video2
执行此脚本会导致分段错误:
..../gems/pHash-1.1.4/lib/phash/video.rb:20: [BUG] Segmentation fault
ruby 1.9.3p545 (2014-02-24 revision 45159) [x86_64-darwin13.1.0]
-- Control frame information -----------------------------------------------
c:0008 p:---- s:0029 b:0029 l:000028 d:000028 CFUNC :ph_dct_videohash
c:0007 p:0042 s:0024 b:0024 l:000023 d:000023 METHOD .../gems/pHash-1.1.4/lib/phash/video.rb:20
c:0006 p:0038 s:0017 b:0017 l:000016 d:000016 METHOD .../gems/pHash-1.1.4/lib/phash.rb:43
c:0005 p:0025 s:0014 b:0014 l:000013 d:000013 METHOD .../gems/pHash-1.1.4/lib/phash.rb:39
c:0004 p:0011 s:0011 b:0011 l:000010 d:000010 METHOD .../gems/pHash-1.1.4/lib/phash.rb:48
c:0003 p:0050 s:0006 b:0006 l:000128 d:0011b8 EVAL video_test_phash.rb:3
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:000128 d:000128 TOP
-- Ruby level backtrace information ----------------------------------------
video_test_phash.rb:3:in `<main>'
.../gems/pHash-1.1.4/lib/phash.rb:48:in `similarity'
.../gems/pHash-1.1.4/lib/phash.rb:39:in `phash'
.../gems/pHash-1.1.4/lib/phash.rb:43:in `compute_phash'
.../gems/pHash-1.1.4/lib/phash/video.rb:20:in `video_hash'
.../gems/pHash-1.1.4/lib/phash/video.rb:20:in `ph_dct_videohash'
...
Abort trap: 6
看来崩溃发生在 ph_dct_videohash 函数中,该函数是 pHash 库的一部分。该函数在文件 pHash.cpp 中。我在这里复制它,以防它对某人有意义:
ulong64* ph_dct_videohash(const char *filename, int &Length){
CImgList<uint8_t> *keyframes = ph_getKeyFramesFromVideo(filename);
if (keyframes == NULL)
return NULL;
Length = keyframes->size();
ulong64 *hash = (ulong64*)malloc(sizeof(ulong64)*Length);
CImg<float> *C = ph_dct_matrix(32);
CImg<float> Ctransp = C->get_transpose();
CImg<float> dctImage;
CImg<float> subsec;
CImg<uint8_t> currentframe;
for (unsigned int i=0;i < keyframes->size(); i++){
currentframe = keyframes->at(i);
currentframe.blur(1.0);
dctImage = (*C)*(currentframe)*Ctransp;
subsec = dctImage.crop(1,1,8,8).unroll('x');
float med = subsec.median();
hash[i] = 0x0000000000000000;
ulong64 one = 0x0000000000000001;
for (int j=0;j<64;j++){
if (subsec(j) > med)
hash[i] |= one;
one = one << 1;
}
}
keyframes->clear();
delete keyframes;
keyframes = NULL;
delete C;
C = NULL;
return hash;
}
很感谢任何形式的帮助!