如何在 Mac OS X Lion 上构建哈希(使用最新的 ffmpeg-devel)

2023-11-29

在 OSX 上构建 pHash 0.9.4 可能会很棘手。 对于那些遇到问题的人,我下面有点冗长的回答可能会有所帮助。



确保您的 macports 已完全更新并正常工作。这意味着最近的 Xcode,并在 Xcode 首选项 -> 下载 -> 组件中安装命令行工具!

$ sudo port selfupdate

# if you've had previous build issues:
$ sudo port clean --all

# get pHash
wget http://www.phash.org/releases/pHash-0.9.4.tar.gz
tar zxvf pHash-0.9.4.tar.gz
cd pHash-0.9.4

# remove old versions of ffmpeg, e.g.
$ sudo port installed ffmpeg
$ sudo port uninstall --follow-dependents ffmpeg @0.7.11_1+mmx
$ sudo port uninstall --follow-dependents ffmpeg @0.7.8_0

# install latest ffmpeg-devel version (@20120329 for me) - enable the non-free stuff as well
$ sudo port install ffmpeg-devel +nonfree

# double check that you have some new header files
$ ll -tr /opt/local/include/

total 8816
-rw-r--r--    1 root  admin      191 Dec 23  2004 lua.hpp
-rw-r--r--    1 root  admin     1026 Dec 27  2007 lualib.h
-rw-r--r--    1 root  admin     5777 Dec 27  2007 lauxlib.h
...

drwxr-xr-x    6 root  admin      204 Jul 12 17:27 libmodplug
drwxr-xr-x    3 root  admin      102 Jul 12 17:32 libswscale
drwxr-xr-x    3 root  admin      102 Jul 12 17:32 libswresample
drwxr-xr-x    3 root  admin      102 Jul 12 17:32 libpostproc
drwxr-xr-x   41 root  admin     1394 Jul 12 17:32 libavutil
drwxr-xr-x    5 root  admin      170 Jul 12 17:32 libavformat
drwxr-xr-x    8 root  admin      272 Jul 12 17:32 libavfilter
drwxr-xr-x    3 root  admin      102 Jul 12 17:32 libavdevice
drwxr-xr-x   10 root  admin      340 Jul 12 17:32 libavcodec

# get CImg and copy CImg.h into your pHash dir
$ cd ..
$ wget http://downloads.sourceforge.net/project/cimg/CImg-1.5.0.zip
$ unzip CImg-1.5.0.zip
$ cp CImg-1.5.0/CImg.h pHash-0.9.4/
$ cd pHash-0.9.4

# copy the JNI headers from your Java SDK into your pHash dir - for 1.7.0 they're here:
$ cp /Library/Java//JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h ./
$ cp /Library/Java//JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/darwin/jni_md.h ./

# install libsndfile, libsamplerate and mpg123 if not installed already
$ sudo port install libsndfile
$ sudo port install libsamplerate
$ sudo port install mpg123

# now run configure, with Java enabled as you likely want those cool bindings, and expect the missing libavcodec error:
$ ./configure --enable-java 


或者这会更有意义:

$ ./configure --enable-java CPPFLAGS="-I/opt/local/include" LDFLAGS="-L/opt/local/lib" 


但配置完全忽略了新的 include/lib 路径:( 似乎它们是硬编码在配置中的。

...
checking CImg.h usability... no
checking CImg.h presence... no
checking for CImg.h... no
checking whether CImg.h is in the current or src directory.... yes

*** Configuring video Hash ***

checking whether FFmpeg is present... checking for avcodec_alloc_frame in -lavcodec... no
configure: error: 

*** libavcodec not found.



因此,由于 configure 期望所有库和包含文件都位于 /usr/local/ (而不是 /opt/local)中,并且我无法让它在其他地方查找,所以剩下要做的唯一一件事就是暴力破解它! :D

# edit ./configure as follows
$ nano configure
CTRL-W -> search for ' -L/' (note the space)

# edit the lines as follows
LDFLAGS="$LDFLAGS -L/usr/local/lib -L/opt/local/lib"
CPPFLAGS="$CPPFLAGS -I/usr/local/include -I/opt/local/include"  

# Or do the newbie version (I actually did this the first time!)
$ sudo mv /usr/local/lib /usr/local/lib-foo
$ sudo mv /usr/local/include/ /usr/local/include-foo
$ sudo ln -s /opt/local/lib /usr/local/lib
$ sudo ln -s /opt/local/include /usr/local/include

$ ll /usr/local/

total 16
drwxr-xr-x  32 root  wheel  1088 Jun 29 18:04 bin
drwxr-xr-x   3 root  wheel   102 Mar  6 14:40 etc
lrwxr-xr-x   1 root  wheel    18 Jul 12 19:27 include -> /opt/local/include
drwxr-xr-x  11 root  wheel   374 Jul 12 19:22 include-foo
lrwxr-xr-x   1 root  wheel    14 Jul 12 19:27 lib -> /opt/local/lib
drwxr-xr-x  25 root  wheel   850 Jul 12 19:23 lib-foo
drwxr-xr-x   8 root  wheel   272 Oct 11  2010 sbin
drwxr-xr-x   4 root  wheel   136 Jun 12 11:52 share

# at this point ./configure should work ok


是时候运行 make - 你会得到一堆错误:

$ make

# on to the code bits:
# we need to adjust src/cimgffmpeg.cpp to support the latest version of ffmpeg
# a few things have moved from being deprecated to having been completely changed:

$ make 2>&1 | grep error

cimgffmpeg.cpp:57: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:70: error: 'CODEC_TYPE_VIDEO' was not declared in this scope
cimgffmpeg.cpp:134: error: 'avcodec_decode_video' was not declared in this scope
cimgffmpeg.cpp:202: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:216: error: 'CODEC_TYPE_VIDEO' was not declared in this scope
cimgffmpeg.cpp:283: error: 'avcodec_decode_video' was not declared in this scope
cimgffmpeg.cpp:339: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:357: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:368: error: 'CODEC_TYPE_VIDEO' was not declared in this scope
cimgffmpeg.cpp:399: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:410: error: 'CODEC_TYPE_VIDEO' was not declared in this scope

# change as follows; left: original downloaded source, right: modified source 

$ diff ~/Downloads/pHash-0.9.4-fresh/src/cimgffmpeg.cpp ~/dev/pHash-0.9.4/src/cimgffmpeg.cpp

57c57
<       if(av_open_input_file(&st_info->pFormatCtx, st_info->filename, NULL, 0, NULL)!=0)
---
>       if(avformat_open_input(&st_info->pFormatCtx, st_info->filename, NULL, NULL)!=0)

70c70
<       if(st_info->pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) 
---
>       if(st_info->pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) 

134c134
<         avcodec_decode_video(st_info->pCodecCtx, pFrame, &frameFinished,packet.data, packet.size);
---
>         avcodec_decode_video2(st_info->pCodecCtx, pFrame, &frameFinished, &packet);

202c202
<       if(av_open_input_file(&(st_info->pFormatCtx),st_info->filename,NULL,0,NULL)!=0){
---
>       if(avformat_open_input(&(st_info->pFormatCtx),st_info->filename,NULL,NULL)!=0){

216c216
<           if(st_info->pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) 
---
>           if(st_info->pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) 

282,283c282
<           avcodec_decode_video(st_info->pCodecCtx, pFrame, &frameFinished,
<                                packet.data,packet.size);
---
>           avcodec_decode_video2(st_info->pCodecCtx, pFrame, &frameFinished, &packet);

339c338
<   if (av_open_input_file(&pFormatCtx, file, NULL, 0, NULL))
---
>   if (avformat_open_input(&pFormatCtx, file, NULL, NULL))

357c356
<   if (av_open_input_file(&pFormatCtx, file, NULL, 0, NULL))
---
>   if (avformat_open_input(&pFormatCtx, file, NULL, NULL))

368c367
<        if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) 
---
>        if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) 

399c398
<   if (av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL))
---
>   if (avformat_open_input(&pFormatCtx, filename, NULL, NULL))

410c409
<            if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) 
---
>            if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) 


我确信那非常有趣,不用担心我们就快到了。

# make should now complete with only useless warnings
$ make
$ sudo make -n install

# if all went well you've not got pHash with Java bindings
# let's build the Java files and test it

$ cd ll bindings/java/org/phash/
$ javac *.java

# go back to the Java bindins root and run
$ cd ../..

# oh yeah.. if you actually DID rename the include/lib dirs previously then: 
$ sudo rm /usr/local/lib
$ sudo rm /usr/local/include
$ sudo mv /usr/local/include-foo/ /usr/local/include
$ sudo mv /usr/local/lib-foo/ /usr/local/lib

# drum roll..
$ java -Djava.library.path=/usr/local/lib org/phash/pHash -mh ~/Downloads/s01.jpg ~/Downloads/s02.jpg 
File 1: /Users/xxx/Downloads/s01.jpg
File 2: /Users/xxx/Downloads/s02.jpg
0.3159722222222222

# now go try out your image recognition app ideas ;)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Mac OS X Lion 上构建哈希(使用最新的 ffmpeg-devel) 的相关文章

  • 如何使用 ffmpeg 提取时间精确的视频片段?

    这并不是一个特别新的问题领域 但我已经尝试过那里建议的内容 但运气不佳 那么 我的故事 我有一大段 15 秒的直接来自camera mov 视频 我想从中提取特定的块 我可以通过开始时间和停止时间 以秒为单位 来识别该块 我首先尝试执行我称
  • 如何将 tkinter 窗口放在其他窗口之上?

    我正在使用 Python 2Tkinter and PyObjC 然后我用py2app 该程序工作正常 但每当我打开该程序时 该窗口都会以隐藏状态开始 因此直到我单击扩展坞上的图标将其调出时 它才会出现 有什么方法可以控制这个 使窗口位于应
  • 如何从 Ant 构建文件设置 Eclipse 构建路径和类路径?

    关于 Ant 和 Eclipse 有很多讨论 但之前的答案似乎对我没有帮助 事情是这样的 我正在尝试构建一个可以从命令行使用 Ant 成功编译的 Java 程序 更令人困惑的是 我尝试编译的程序是 Ant 本身 我真正想做的是将这个项目引入
  • VLC 和 ffmpeg 如何协同工作?

    我从源代码编译了VLC 它运行良好 当我执行 Vlc 时 vlc 运行 我还从源代码编译了 ffmpeg 它也运行良好 当我执行 ffmpeg i f toto flv mp3 vn acodec copy new toto mp3 时 会
  • 无法访问类“std::basic_ios<_Elem,_Traits>”中声明的私有成员

    此特定方法有问题 不知道如何解决 我收到的错误是上面的 错误 C2248 std basic ios basic ios 不能 访问类中声明的私有成员 std basic ios C Program Files Microsoft Visu
  • Android 构建签名 APK 时出错:找不到用于签名配置“externalOverride”的 keystore.jks

    当我尝试构建签名 APK 时出现此错误 我最近升级到 API 23 但之后成功生成了 APK s 我很困惑 寻求帮助并建议如何解决这个问题 这是错误 FAILURE Build failed with an exception What w
  • 动态框架中未定义的架构符号

    我正在开发一个 iOS 框架 该框架包含多个第三方框架并使用 UnitySendMessage C 方法与 Unity 进行通信 我想创建一个动态框架 支持 iOS8 但我偶然发现以下编译错误 Undefined symbols for a
  • 如何在Android项目中使用libffmpeg.so?

    我正在尝试在 Android 中创建一个屏幕录制应用程序 为此 我使用 FFmpeg 我已经创建了 libffmpeg so 文件 现在我想在 Android 项目中使用相同的方法来调用它的本机函数 我怎样才能做到这一点 本教程提供了有关此
  • Python 用静态图像将 mp3 转换为 mp4

    我有x文件包含一个列表mp3我想转换的文件mp3文件至mp4文件带有static png photo 似乎这里唯一的方法是使用ffmpeg但我不知道如何实现它 我编写了脚本来接受输入mp3文件夹和一个 png photo 然后它将创建新文件
  • 使用 ffmpeg 或 OpenCV 处理原始图像

    看完之后维基百科页面 http en wikipedia org wiki Raw image format原始图像格式 是任何图像的数字负片 为了查看或打印 相机图像传感器的输出具有 进行处理 即转换为照片渲染 场景 然后以标准光栅图形格
  • 如何向 SvelteKit/Vite 应用添加版本号?

    我正在尝试在我的 SvelteKit 应用程序中创建一个系统 它会在某个页面上向您显示有关当前应用程序版本的信息 最好是 Git 提交哈希和描述 我尝试使用Vite的定义功能 https vitejs dev config define在构
  • Qt WinRT 应用程序无法访问文件权限被拒绝

    我需要使用 Qt 和 FFMPEG 开发 WinRT 应用程序 我根据指令构建了 WinRT 的 ffmpeghere https github com Microsoft FFmpegInterop我可以将库与我的项目链接起来 现在我需要
  • 使用 gradle 部署 GAE 时出现奇怪的构建失败

    直到今天一切都运转良好 据我所知 没有改变任何东西 现在我明白了 C mypath gt gradle appengineDeploy gt Configure project WARNING You are a using release
  • 如何在使用cmake完成make后打印消息?

    我正在尝试使用 CMake 完成构建过程后打印消息 我只是想在之后通知用户make命令已完成 没有任何错误 我该怎么做 我试过add custom target 但我无法选择何时跑步 另外 我尝试过add custom command 它再
  • Python 子进程(ffmpeg)仅在我按 Ctrl-C 程序时启动?

    我正在尝试使用 Cygwin 和 Python 2 7 并行运行一些 ffmpeg 命令 这大概是我所拥有的 import subprocess processes set commands ffmpeg i input mp4 outpu
  • Maven:从构建中排除测试

    我在项目的 src test java 文件夹中有一些类用作测试 当我使用标准 Maven 编译插件运行 Maven 时 这些项目被编译成 class 文件 并包含在打包编译代码的 jar 中 在运行 Maven 和构建我的版本之前 我已经
  • 为什么在标头内的类声明中声明变量时会出现错误?

    我正在尝试创建一个包含简单整数的类 当然 它使用头文件之类的 这是代码 class h class consolBuf private int buffersize1 10 Data member initializer is not al
  • 有没有什么好的工具可以查看和浏览ant构建文件?

    我发现很难读取 ant 构建文件 特别是如果构建文件包含大量导入文件 例如属性文件和其他 xml 构建文件 因此 我想知道是否有一些好的工具可以提供帮助 例如在 IDE 中查看和浏览源代码 提前致谢 Try 盛大 这里 http www g
  • ffmpeg concat:“不安全的文件名”

    尝试将一堆 mts 文件转换为一个大 mp4 文件 stephan rechenmonster mnt backupsystem archive2 Videos 20151222 PRIVATE AVCHD BDMV bin ffmpeg
  • XCode 4.2.1 在 Lion 10.7.2 上启动时崩溃

    这周我买了大约 10 年来的第一台 Mac 是的 这是一台二手 Mac Pro 2x2GHz 双核 Xeon 2GB RAM 它全新安装了 Mac OS X Lion 10 7 2 我只安装了 OmniOutlner Pro Textmat

随机推荐