Skip to content

Commit

Permalink
fix(ffmpeg): package OSX ffmpeg4.2.2 into toolkit (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
DefTruth committed Feb 24, 2022
1 parent 9a6627d commit ea5afbc
Show file tree
Hide file tree
Showing 59 changed files with 96 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ message("#######################################################################

# setup include dir and lib dir
include_directories(${LITE_AI_ROOT_DIR})
link_directories(${LITE_AI_ROOT_DIR}/lib)
link_directories(${LITE_AI_ROOT_DIR}/lib/${PLATFORM_NAME})

# include custom cmake files.
include(cmake/setup_opencv_libs.cmake)
Expand Down
46 changes: 39 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,48 @@ The output is:
cp -r you-path-to-downloaded-or-built-TNN/include/tnn lite.ai.toolkit/tnn
```

and put the libs into **lite.ai.toolkit/lib** directory. Please reference the build-docs[<sup>1</sup>](#lite.ai.toolkit-1) for **third_party**.
* **lite.ai.toolkit/lib**
and put the libs into **lite.ai.toolkit/lib/(linux|windows)** directory. Please reference the build-docs[<sup>1</sup>](#lite.ai.toolkit-1) for **third_party**.
* **lite.ai.toolkit/lib/(linux|windows)**
```shell
cp you-path-to-downloaded-or-built-opencv/lib/*opencv* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-onnxruntime/lib/*onnxruntime* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-MNN/lib/*MNN* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-ncnn/lib/*ncnn* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-TNN/lib/*TNN* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-opencv/lib/(linux|windows)/*opencv* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-onnxruntime/lib/(linux|windows)/*onnxruntime* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-MNN/lib/(linux|windows)/*MNN* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-ncnn/lib/(linux|windows)/*ncnn* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-TNN/lib/(linux|windows)/*TNN* lite.ai.toolkit/lib
```

Note, your also need to install ffmpeg(<=4.2.2) in Linux to support the opencv videoio module. See [issue#203](https://github.com/DefTruth/lite.ai.toolkit/issues/6). In MacOS, ffmpeg4.2.2 was been package into lite.ai.toolkit, thus, no installation need in OSX. In Windows, ffmpeg was been package into opencv dll prebuilt by the team of opencv. Please make sure -DWITH_FFMPEG=ON and check the configuration info when building opencv.
* first, build ffmpeg(<=4.2.2) from source.
```shell
git clone --depth=1 https://git.ffmpeg.org/ffmpeg.git -b n4.2.2
cd ffmpeg
./configure --enable-shared --disable-x86asm --prefix=/usr/local/opt/ffmpeg --disable-static
make -j8
make install
```
* then, build opencv with -DWITH_FFMPEG=ON, just like
```shell
#!/bin/bash
mkdir build
cd build
cmake .. \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=your-path-to-custom-dir \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_opencv_python3=OFF \
-D BUILD_opencv_python2=OFF \
-D BUILD_SHARED_LIBS=ON \
-D BUILD_opencv_apps=OFF \
-D WITH_FFMPEG=ON
make -j8
make install
cd ..
```
after built opencv, you can follow the steps to build lite.ai.toolkit.

* Windows: You can reference to [issue#6](https://github.com/DefTruth/lite.ai.toolkit/issues/6)
* Linux: The Docs and Docker image for Linux will be coming soon ~ [issue#2](https://github.com/DefTruth/lite.ai.toolkit/issues/2)
Expand Down
47 changes: 39 additions & 8 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,47 @@ static void test_default()
cp -r you-path-to-downloaded-or-built-TNN/include/tnn lite.ai.toolkit/tnn
```

然后把各个依赖库拷贝到**lite.ai.toolkit/lib** 文件夹。 请参考依赖库的编译文档[<sup>1</sup>](#lite.ai.toolkit-1)。
* **lite.ai.toolkit/lib**
然后把各个依赖库拷贝到**lite.ai.toolkit/lib/(linux|windows)** 文件夹。 请参考依赖库的编译文档[<sup>1</sup>](#lite.ai.toolkit-1)。
* **lite.ai.toolkit/lib/(linux|windows)**
```shell
cp you-path-to-downloaded-or-built-opencv/lib/*opencv* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-onnxruntime/lib/*onnxruntime* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-MNN/lib/*MNN* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-ncnn/lib/*ncnn* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-TNN/lib/*TNN* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-opencv/lib/(linux|windows)/*opencv* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-onnxruntime/lib/(linux|windows)/*onnxruntime* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-MNN/lib/(linux|windows)/*MNN* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-ncnn/lib/(linux|windows)/*ncnn* lite.ai.toolkit/lib
cp you-path-to-downloaded-or-built-TNN/lib/(linux|windows)/*TNN* lite.ai.toolkit/lib
```

注意,你还需要安装ffmpeg(<=4.2.2),因为opencv的videoio模块依赖ffmpeg进行mp4的编解码。参考[issue#203](https://github.com/DefTruth/lite.ai.toolkit/issues/6) . 在MacOS下,ffmpeg4.2.2已经作为一个自定义依赖库被我打包进lite.ai.toolkit,不需要再从HomeBrew安装为系统库,因此lite.ai.toolkit是单体的,你可以把它移植到app里面,不用心另一台运行app的机器没有ffmpeg,MacOS版本的lite.ai.toolkit已经包含ffmpeg. 在Windows下,opencv官方团队已经提供了用于opencv的ffmpeg预编译库。在Linux下编译opencv时,请确保-DWITH_FFMPEG=ON,并检查是否链接到ffmpeg.
* 先编译ffmpeg,注意必须是低版本的,高于4.4的,opencv会不兼容。
```shell
git clone --depth=1 https://git.ffmpeg.org/ffmpeg.git -b n4.2.2
cd ffmpeg
./configure --enable-shared --disable-x86asm --prefix=/usr/local/opt/ffmpeg --disable-static
make -j8
make install
```
* 然后,编译带ffmpeg支持的OpenCV,指定-DWITH_FFMPEG=ON
```shell
#!/bin/bash
mkdir build
cd build
cmake .. \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=your-path-to-custom-dir \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_opencv_python3=OFF \
-D BUILD_opencv_python2=OFF \
-D BUILD_SHARED_LIBS=ON \
-D BUILD_opencv_apps=OFF \
-D WITH_FFMPEG=ON
make -j8
make install
cd ..
```
编译完opencv后,你就可以按照上述的步骤,继续编译lite.ai.toolkit.

* Windows: 你可以参考[issue#6](https://github.com/DefTruth/lite.ai.toolkit/issues/6) ,讨论了常见的编译问题。
* Linux: 参考MacOS下的编译,替换Linux版本的依赖库即可。Linux下的发行版本将会在近期添加 ~ [issue#2](https://github.com/DefTruth/lite.ai.toolkit/issues/2)
Expand Down
14 changes: 9 additions & 5 deletions cmake/lite.ai.toolkit-cmd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -131,31 +131,35 @@ function(add_lite_ai_toolkit_engines_libs_command)
# copy opencv libs
if (INCLUDE_OPENCV)
message("Installing OpenCV libs -> INCLUDE_OPENCV: ${INCLUDE_OPENCV} ...")
file(GLOB ALL_OpenCV_LIBS ${LITE_AI_ROOT_DIR}/lib/*opencv*)
file(GLOB ALL_OpenCV_LIBS ${LITE_AI_ROOT_DIR}/lib/${PLATFORM_NAME}/*opencv*)
file(GLOB FFMPEG_AV_LIBS ${LITE_AI_ROOT_DIR}/lib/${PLATFORM_NAME}/*av*)
file(GLOB FFMPEG_SW_LIBS ${LITE_AI_ROOT_DIR}/lib/${PLATFORM_NAME}/*sw*)
file(INSTALL ${ALL_OpenCV_LIBS} DESTINATION ${LIBRARY_OUTPUT_PATH})
file(INSTALL ${FFMPEG_AV_LIBS} DESTINATION ${LIBRARY_OUTPUT_PATH})
file(INSTALL ${FFMPEG_SW_LIBS} DESTINATION ${LIBRARY_OUTPUT_PATH})
endif()
# copy onnxruntime libs
if (ENABLE_ONNXRUNTIME)
message("Installing ONNXRuntime libs -> ENABLE_ONNXRUNTIME: ${ENABLE_ONNXRUNTIME} ...")
file(GLOB ALL_ONNXRUNTIME_LIBS ${LITE_AI_ROOT_DIR}/lib/*onnxruntime*)
file(GLOB ALL_ONNXRUNTIME_LIBS ${LITE_AI_ROOT_DIR}/lib/${PLATFORM_NAME}/*onnxruntime*)
file(INSTALL ${ALL_ONNXRUNTIME_LIBS} DESTINATION ${LIBRARY_OUTPUT_PATH})
endif()
# copy MNN libs
if (ENABLE_MNN)
message("Installing MNN libs -> ENABLE_MNN: ${ENABLE_MNN} ...")
file(GLOB ALL_MNN_LIBS ${LITE_AI_ROOT_DIR}/lib/*MNN*)
file(GLOB ALL_MNN_LIBS ${LITE_AI_ROOT_DIR}/lib/${PLATFORM_NAME}/*MNN*)
file(INSTALL ${ALL_MNN_LIBS} DESTINATION ${LIBRARY_OUTPUT_PATH})
endif()
# copy NCNN libs
if (ENABLE_NCNN)
message("Installing NCNN libs -> ENABLE_NCNN: ${ENABLE_NCNN} ...")
file(GLOB ALL_NCNN_LIBS ${LITE_AI_ROOT_DIR}/lib/*ncnn*)
file(GLOB ALL_NCNN_LIBS ${LITE_AI_ROOT_DIR}/lib/${PLATFORM_NAME}/*ncnn*)
file(INSTALL ${ALL_NCNN_LIBS} DESTINATION ${LIBRARY_OUTPUT_PATH})
endif()
# copy TNN libs
if (ENABLE_TNN)
message("Installing TNN libs -> ENABLE_TNN: ${ENABLE_TNN} ...")
file(GLOB ALL_TNN_LIBS ${LITE_AI_ROOT_DIR}/lib/*TNN*)
file(GLOB ALL_TNN_LIBS ${LITE_AI_ROOT_DIR}/lib/${PLATFORM_NAME}/*TNN*)
file(INSTALL ${ALL_TNN_LIBS} DESTINATION ${LIBRARY_OUTPUT_PATH})
endif()
endfunction()
Expand Down
7 changes: 6 additions & 1 deletion cmake/lite.ai.toolkit.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
add_lite_ai_toolkit_shared_library(${VERSION_STRING} ${SOVERSION_STRING})
add_lite_ai_toolkit_engines_headers_command()
add_lite_ai_toolkit_engines_libs_command()

# TODO: Windows需要之后兼容
if(${PLATFORM_NAME} MATCHES macos OR ${PLATFORM_NAME} MATCHES linux)
add_lite_ai_toolkit_engines_libs_command()
endif()

if(${PLATFORM_NAME} MATCHES macos OR ${PLATFORM_NAME} MATCHES linux)
add_lite_ai_toolkit_test_custom_command()
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/setup_opencv_libs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(OpenCV_LIBS
opencv_imgproc
opencv_imgcodecs
opencv_video
opencv_videoio
opencv_videoio # need ffmpeg for mp4 io
) # need only
message("###########################################################################################")

2 changes: 1 addition & 1 deletion lib/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
windows
linux
android
android
Binary file removed lib/libopencv_video.4.5.dylib
Binary file not shown.
Binary file removed lib/libopencv_video.dylib
Binary file not shown.
Empty file added lib/macos/.gitignore
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added lib/macos/libavcodec.58.dylib
Binary file not shown.
Binary file added lib/macos/libavcodec.dylib
Binary file not shown.
Binary file added lib/macos/libavdevice.58.dylib
Binary file not shown.
Binary file added lib/macos/libavdevice.dylib
Binary file not shown.
Binary file added lib/macos/libavfilter.7.dylib
Binary file not shown.
Binary file added lib/macos/libavfilter.dylib
Binary file not shown.
Binary file added lib/macos/libavformat.58.dylib
Binary file not shown.
Binary file added lib/macos/libavformat.dylib
Binary file not shown.
Binary file added lib/macos/libavutil.56.dylib
Binary file not shown.
Binary file added lib/macos/libavutil.dylib
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added lib/macos/libopencv_calib3d.4.5.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_calib3d.dylib
Binary file not shown.
Binary file renamed lib/libopencv_core.4.5.dylib → lib/macos/libopencv_core.4.5.dylib
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file added lib/macos/libopencv_features2d.4.5.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_features2d.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_flann.4.5.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_flann.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_gapi.4.5.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_gapi.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_highgui.4.5.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_highgui.dylib
Binary file not shown.
Binary file renamed lib/libopencv_imgcodecs.4.5.dylib → lib/macos/libopencv_imgcodecs.4.5.dylib
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file renamed lib/libopencv_imgproc.4.5.dylib → lib/macos/libopencv_imgproc.4.5.dylib
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file added lib/macos/libopencv_ml.4.5.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_ml.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_objdetect.4.5.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_objdetect.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_photo.4.5.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_photo.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_stitching.4.5.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_stitching.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_video.4.5.dylib
Binary file not shown.
Binary file added lib/macos/libopencv_video.dylib
Binary file not shown.
Binary file renamed lib/libopencv_videoio.4.5.dylib → lib/macos/libopencv_videoio.4.5.dylib
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file added lib/macos/libswresample.3.dylib
Binary file not shown.
Binary file added lib/macos/libswresample.dylib
Binary file not shown.
Binary file added lib/macos/libswscale.5.dylib
Binary file not shown.
Binary file added lib/macos/libswscale.dylib
Binary file not shown.

0 comments on commit ea5afbc

Please sign in to comment.