Build status for all platforms (Android, iOS, Linux, Mac OS X, Windows):
Commercial support and paid services for custom presets:
The JavaCPP Presets modules contain Java configuration and interface classes for widely used C/C++ libraries. The configuration files in the org.bytedeco.<moduleName>.presets
packages are used by the Parser
to create from C/C++ header files the Java interface files targeting the org.bytedeco.<moduleName>
packages, which is turn are used by the Generator
and the native C++ compiler to produce the required JNI libraries. Moreover, helper classes make their functionality easier to use on the Java platform, including Android.
For orientation purposes, the documentation of this repository can be thought of as being split into 2 levels:
javacpp-presets
module itself, andThis parent README.md file contains general information applicable to all modules to solve issues concerning downloads, common requirements, installation procedures, and build instructions. The respective README.md files in each subdirectory contain extra information, links, and notes concerning API documentation, specific requirements, dependencies for pom.xml
files, and sample usage code, for the presets and packages of each module. Please be aware that not all of the presets have the same level of maturity, and the style and layout may also differ from one to another since they are based on the APIs of third-party libraries.
Please refer to the wiki page for more information about how to create new presets. Since additional documentation is currently lacking, please also feel free to ask questions on the mailing list or the discussion forum.
JAR files containing binaries for all child modules and builds for all supported platforms (Android, iOS, Linux, Mac OS X, and Windows) can be obtained from the Maven Central Repository. Archives containing these JAR files are also available as releases.
To install manually the JAR files, follow the instructions in the Manual Installation section below.
We can also have everything downloaded and installed automatically with:
pom.xml
file)<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>${moduleName}-platform</artifactId>
<version>${moduleVersion}-1.5.6</version>
</dependency>
build.gradle
file)dependencies {
implementation group: 'org.bytedeco', name: moduleName + '-platform', version: moduleVersion + '-1.5.6'
}
project.clj
file):dependencies [
[~(symbol (str "org.bytedeco/" moduleName "-platform")) ~(str moduleVersion "-1.5.6")]
]
build.sbt
file)libraryDependencies += "org.bytedeco" % moduleName + "-platform" % moduleVersion + "-1.5.6"
where the moduleName
and moduleVersion
variables correspond to the desired module. This downloads binaries for all platforms, but to get binaries for only one platform we can set the javacpp.platform
system property (via the -D
command line option) to something like android-arm
, linux-x86_64
, macosx-x86_64
, windows-x86_64
, etc. We can also specify more than one platform, see the examples at Reducing the Number of Dependencies. Another option available to Gradle users is Gradle JavaCPP, and similarly for Scala users there is SBT-JavaCPP.
To use the JavaCPP Presets, you will need to download and install the following software:
Further, in the case of Android, the JavaCPP Presets also rely on:
Simply put all the desired JAR files (opencv*.jar
, ffmpeg*.jar
, etc.), in addition to javacpp.jar
, somewhere in your class path. The JAR files available as pre-built artifacts are meant to be used with JavaCPP. The binaries for Linux were built for CentOS 6 and 7, so they should work on most distributions currently in use. The ones for Android were compiled for ARMv7 processors featuring an FPU, so they will not work on ancient devices such as the HTC Magic or some others with an ARMv6 CPU. Here are some more specific instructions for common cases:
NetBeans (Java SE 7 or newer):
Eclipse (Java SE 7 or newer):
IntelliJ IDEA (Android 5.0 or newer):
app/libs
subdirectory.+
, and select "2 File dependency".libs
subdirectory.After that, we can access almost transparently the corresponding C/C++ APIs through the interface classes found in the org.bytedeco.<moduleName>
packages. Indeed, the Parser
translates the code comments from the C/C++ header files into the Java interface files, (almost) ready to be consumed by Javadoc. However, since their translation still leaves to be desired, one may wish to refer to the original documentation pages. For instance, the ones for OpenCV and FFmpeg can be found online at:
If the binary files available above are not enough for your needs, you might need to rebuild them from the source code. To this end, project files on the Java side were created as Maven modules. By default, the Maven build also installs the native libraries on the native C/C++ side with the cppbuild.sh
scripts, but they can also be installed by other means.
Additionally, one can find on the wiki page additional information about the recommended build environments for the major platforms.
The JavaCPP Presets depend on Maven, a powerful build system for Java, so before attempting a build, be sure to install and read up on:
Each child module in turn relies by default on the included cppbuild.sh
scripts, explained below, to install its corresponding native libraries in the cppbuild
subdirectory. To use native libraries already installed somewhere else on the system, other installation directories than cppbuild
can also be specified either in the pom.xml
files or in the .java
configuration files. The following versions are supported:
Once everything installed and configured, simply execute
$ mvn install --projects .,opencv,ffmpeg,etc. -Djavacpp.platform.root=/path/to/android-ndk/
inside the directory containing the parent pom.xml
file, by specifying only the desired child modules in the command, but without the leading period "." in the comma-separated list of projects, the parent pom.xml
file itself might not get installed. (The -Djavacpp.platform.root=...
option is required only for Android builds.) Also specify -Djavacpp.cppbuild.skip
as option to skip the execution of the cppbuild.sh
scripts. In addition to -Djavacpp.platform=...
, some of the presets can also be built against CUDA with -Djavacpp.platform.extension=-gpu
or CPython with -Djavacpp.platform.extension=-python
. Please refer to the comments inside the pom.xml
file for further details. From the "platform" subdirectory, we can also install the "platform" artifacts with a similar command:
$ cd platform
$ mvn install --projects ../opencv/platform,../ffmpeg/platform,etc. -Djavacpp.platform.host
cppbuild.sh
scriptsRunning the scripts allows us to install easily the native libraries on multiple platforms, but additional software is required:
With the above in working order, the scripts get launched automatically as part of the Maven build lifecycle, but we can also manually execute
$ ANDROID_NDK=/path/to/android-ndk/ bash cppbuild.sh [-platform <name>] [-extension <name>] <install | clean> [projects]
where possible platform names are: android-arm
, android-x86
, linux-x86
, linux-x86_64
, linux-armhf
, linux-ppc64le
, linux-mips64el
, macosx-x86_64
, windows-x86
, windows-x86_64
, etc. The -gpu
extension as supported by some builds also require CUDA to be installed. (The ANDROID_NDK
variable is required only for Android builds.) Please note that the scripts download source archives from appropriate sites as necessary.
To compile binaries for an Android device with no FPU, first make sure this is what you want. Without FPU, the performance of either OpenCV or FFmpeg is bound to be unacceptable. If you still wish to continue down that road, then replace "armeabi-v7a" by "armeabi" and "-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16" with "-march=armv5te -mtune=xscale -msoft-float", inside various files.
Although JavaCPP can pick up native libraries installed on the system, the scripts exist to facilitate the build process across multiple platforms. They also allow JavaCPP to copy the native libraries and load them at runtime from the JAR files created above by Maven, a useful feature for standalone applications or Java applets. Moreover, tricks such as the following work with JNLP:
<resources os="Linux" arch="x86 i386 i486 i586 i686">
<jar href="lib/opencv-linux-x86.jar"/>
<jar href="lib/ffmpeg-linux-x86.jar"/>
</resources>
<resources os="Linux" arch="x86_64 amd64">
<jar href="lib/opencv-linux-x86_64.jar"/>
<jar href="lib/ffmpeg-linux-x86_64.jar"/>
</resources>
Thanks to Jose Gómez for testing this out!
Contributions of any kind are highly welcome! At the moment, the Parser
has limited capabilities, so I plan to improve it gradually to the point where it can successfully parse large C++ header files that are even more convoluted than the ones from OpenCV, Caffe, or TensorFlow, but the build system could also be improved. Consequently, I am looking for help especially with the five following tasks, in no particular order:
Parser
(by using the presets for LLVM and Clang?)linux-armhf
for Raspberry Pi, etc.To contribute, please fork and create pull requests, or post your suggestions as a new "issue". Thank you very much in advance for your contribution!
Project lead: Samuel Audet samuel.audet at
gmail.com
Developer site: https://github.com/bytedeco/javacpp-presets
Discussion group: http://groups.google.com/group/javacpp-project
在利用FFmpegFrameGrabber处理视频流,将视频一帧一帧取出来的过程中 遇到一个报错:Could not initialize class org.bytedeco.javacpp.avutil 网上查找资料发现是少引入了包 但是增加之后又会有其他的报错,如:Exception in thread "main" java.lang.NoClassDefFoundError: org/b
1. Java 与 FFMPEG FFMPEG 是一个广泛用于媒体处理的库,在Java的世界里,处理视频的能力相当弱,于是有很大需求需要Java 调用 FFMPEG。 Java 调用C 的方式有很多,可以用最原始的JNI方式,也可以JNA方式,还可以是命令行。 采用命令行的方式比较简单,不过有很大局限性,尤其是涉及到 视频的处理和分析的时候,比如要取出某个packet,然后进行处理
JavaCPP提供了在Java中高效访问本地C++的方法。采用JNI技术实现,支持所有Java实现包括Android系统,Avian 和 RoboVM。 JavaCPP提供了一系列的Annotation将Java代码映射到C++代码,并使用一个可执行的jar包将C++代码转化为可以从JVM内调用的动态链接库文件。 Maven: <dependency> <groupId>org.bytede
我只是想测试JAVACPP并尝试了我的eclipse中网页中的第一个示例: http://code.google.com/p/javacpp/(Legacyclass和Legacy库) 我一打字: javac-cp libs\javacpp.jar:. src\LegacyLibrary.java 在命令行中,我得到以下错误消息: src\LegacyLibrary.java: 1:错误:包com
以便在我的应用程序中使用它。我正在测试一个原生C++Android Studio模板项目。 我已经在GitHub上上传了完整的项目供参考:https://GitHub.com/jacobkrieg10/javacppnewexample 还有,下面是我认为需要注意的项目中的相关文件: nativelibrary.java: cmakelists.txt: 注意,Native-lib.cpp只是模板
好的。我正在引导一个简单的应用程序。我使用的是flow.js。我使用的预置是babel-preset-2015、babel-preset-react和Babel-Preset-Stage-0。我必须在我的。Babelrc和WebPack.config中放置相同的预置,以便所有这些预置都能工作。例如,如果我从WebPack.config中移动它们,我会得到一个错误'React is not defi