Ver código fonte

搭建 ffmpeg+opencv 环境

DevYK 3 anos atrás
pai
commit
b5631e379f

+ 52 - 5
CMakeLists.txt

@@ -6,11 +6,11 @@ project(bytesflow-opencv-media)
 SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/output/bin)
 SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/output/lib)
 
-add_subdirectory(opencv)
+add_subdirectory(src)
 add_subdirectory(jni)
 
 
-############################################# 加入jni支持,linux############################################
+############################################# 加入jni支持############################################
 message(FIND JAVA_HOME---> $ENV{JAVA_HOME})
 set(JAVA_HOME $ENV{JAVA_HOME})
 message(JAVA_HOME ${JAVA_HOME})
@@ -20,6 +20,8 @@ if (NOT DEFINED ENV{JAVA_HOME})
     set(JNI_PATH ${JAVA_HOME}/include)
 endif ()
 
+############################################# 加入 ffmpeg src 支持############################################
+
 IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
     set(JNI_MD_PATH ${JAVA_HOME}/include/linux)
     set(JNI_PATH ${JAVA_HOME}/include)
@@ -29,6 +31,14 @@ IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
     set(OPENCV_INCLUDE ${OPENCV_HOME}/include/opencv4/)
     set(OPENCV_LIBS ${OPENCV_HOME}/lib64)
 
+    set(FFMPEG_PREFIX /usr)
+    set(FFMPEG_INCLUDE_DIRS ${FFMPEG_PREFIX}/include/ffmpeg/)
+    set(FFMPEG_LIBRARIES ${FFMPEG_PREFIX}/lib64/)
+    MESSAGE(FFMPEG_PREFIX ${FFMPEG_PREFIX})
+    MESSAGE(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS})
+    MESSAGE(FFMPEG_LIBS ${FFMPEG_LIBRARIES})
+
+
 ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
     set(JNI_PATH ${JAVA_HOME}/include)
     set(JNI_MD_PATH ${JAVA_HOME}/include/darwin)
@@ -37,6 +47,15 @@ ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
     set(OPENCV_INCLUDE ${OPENCV_HOME}/include/opencv4)
     set(OPENCV_LIBS ${OPENCV_HOME}/lib)
 
+
+    set(FFMPEG_PREFIX /usr/local/Cellar/ffmpeg@4/4.4.1)
+    set(FFMPEG_INCLUDE_DIRS ${FFMPEG_PREFIX}/include/ffmpeg/)
+    set(FFMPEG_LIBS ${FFMPEG_PREFIX}/lib64/)
+    MESSAGE(FFMPEG_PREFIX ${FFMPEG_PREFIX})
+    MESSAGE(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS})
+    MESSAGE(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES})
+
+
 ELSE ()
     MESSAGE(STATUS "other platform: ${CMAKE_SYSTEM_NAME}")
 ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux")
@@ -44,15 +63,29 @@ ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux")
 message(OPENCV_INCLUDE>${OPENCV_INCLUDE})
 message(OPENCV_LIBS>${OPENCV_LIBS})
 message(JAVA_HOME>${JAVA_HOME})
-link_directories(${OPENCV_LIBS})
+
 include_directories(${OPENCV_INCLUDE})
 include_directories(${JNI_MD_PATH})
+include_directories(${FFMPEG_INCLUDE_DIRS})
 
+link_directories(${OPENCV_LIBS})
+link_directories(${FFMPEG_LIBS})
 
 add_library(piaoquan_java_opencv SHARED
-        ${OPENCV_SRC}
+        ${Project_SRC}
         ${JAVA_JNI_SRC})
 
+add_library(video_similarity_detection SHARED
+        ${Project_SRC})
+
+set(FFmpeg_LIBS
+        -lavcodec
+        -lavdevice
+        -lavfilter
+        -lavformat
+        -lavutil
+        -lswscale
+        -lswresample)
 set(OpenCV_LIBS
         -lopencv_imgproc
         -lopencv_imgcodecs
@@ -118,13 +151,23 @@ if (CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))
     set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -O0")
     message("Debug mode:${CMAKE_C_FLAGS_DEBUG}")
     add_executable(ImageBlurDetection_debug main.cpp
-            ${OPENCV_SRC}
+            ${Project_SRC}
             count_down_latch.h
             ${JAVA_JNI_SRC}
             )
     target_link_libraries(ImageBlurDetection_debug -lpthread
             ${OpenCV_LIBS}
             )
+
+    add_executable(video_similarity_detection_debug main.cpp
+            ${Project_SRC}
+            count_down_latch.h
+            ${JAVA_JNI_SRC}
+            )
+    target_link_libraries(video_similarity_detection_debug -lpthread
+            ${OpenCV_LIBS}
+            ${FFmpeg_LIBS}
+            )
 elseif (CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
     set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -O3")
     message("Release mode:${CMAKE_C_FLAGS_RELEASE}")
@@ -136,6 +179,10 @@ endif ()
 target_link_libraries(piaoquan_java_opencv
         ${OpenCV_LIBS}
         )
+target_link_libraries(video_similarity_detection
+        ${OpenCV_LIBS}
+        ${FFmpeg_LIBS}
+        )
 
 
 

+ 8 - 8
README.md

@@ -41,29 +41,29 @@ export JAVA_HOME=xxx
 **命令安装 必须 4.5.5 版本(不推荐)**
 
 ```shell
-sudo yum install opencv opencv-devel
+sudo yum install src src-devel
 
 #检查版本
-pkg-config --modversion opencv
+pkg-config --modversion src
 ```
 
 **源码安装 4.5.5(推荐)**
 
 ```shell
-#opencv 环境 4.5.5
+#src 环境 4.5.5
 #安装依赖包
 sudo yum install freeglut-devel mesa-libGL mesa-libGL-devel  boost boost-thread boost-devel libv4l-devel libjpeg-turbo-devel libtiff-devel  libdc1394-devel tbb-devel eigen3-devel gstreamer-plugins-base-devel python-devel numpy python34-numpy gtk2-devel libpng-devel jasper-devel openexr-devel libwebp-devel python3 python3-devel python3-pip  python3-devel python3-numpy
 #下载 OpenCV 源码 
 
-wget -O opencv-4.5.5.zip         https://github.com/opencv/opencv/archive/refs/tags/4.5.5.zip
+wget -O src-4.5.5.zip         https://github.com/opencv/opencv/archive/refs/tags/4.5.5.zip
 wget -O opencv_contrib-4.5.5.zip https://github.com/opencv/opencv_contrib/archive/refs/tags/4.5.5.zip
-unzip opencv-4.5.5.zip
+unzip src-4.5.5.zip
 unzip opencv_contrib-4.5.5.zip
 
-cd opencv-4.5.5
+cd src-4.5.5
 mkdir build && cd build
 
-OPENCV_CONTRIB_DIR=/root/opencv/opencv_contrib-4.5.5/modules
+OPENCV_CONTRIB_DIR=/root/src/opencv_contrib-4.5.5/modules
 
 cmake -D CMAKE_BUILD_TYPE=RELEASE \
     -D CMAKE_INSTALL_PREFIX=/usr/local \
@@ -82,7 +82,7 @@ make -j8 && make install
 #### MAC:
 **命令安装**
 ```shell
-brew install opencv
+brew install src
 ```
 如果安装慢可以换一个源:
 ```shell

+ 1 - 1
jni/ImageBlurDetection.h

@@ -6,7 +6,7 @@
 #ifndef LOPENCVSAMPLE_IMAGEBLURDETECTION_H
 #define LOPENCVSAMPLE_IMAGEBLURDETECTION_H
 
-#define JAVA_JNI_CLASS_PATH "com/bytesflow/opencv/media/jni/PQCVMediaProcessor"
+#define JAVA_JNI_CLASS_PATH "com/bytesflow/src/media/jni/PQCVMediaProcessor"
 #define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
 
 #endif //LOPENCVSAMPLE_IMAGEBLURDETECTION_H

+ 0 - 6
opencv/CMakeLists.txt

@@ -1,6 +0,0 @@
-set(OPENCV_SRC ${OPENCV_SRC}
-        opencv/image_blur_detection.cpp
-        opencv/image_blur_detection.h
-        PARENT_SCOPE
-        )
-

+ 6 - 0
src/CMakeLists.txt

@@ -0,0 +1,6 @@
+set(Project_SRC ${Project_SRC}
+        src/image_blur_detection.cpp
+        src/image_blur_detection.h
+        PARENT_SCOPE
+        )
+

+ 0 - 0
opencv/image_blur_detection.cpp → src/image_blur_detection.cpp


+ 0 - 0
opencv/image_blur_detection.h → src/image_blur_detection.h