forked from opencv/opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Framework for dynamic videoio backends, FFmpeg and GStreamer plugins
- Loading branch information
Showing
64 changed files
with
2,278 additions
and
1,476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#============================================= | ||
# build with OpenCV | ||
|
||
function(ocv_create_builtin_videoio_plugin name target videoio_src_file) | ||
|
||
if(NOT TARGET ${target}) | ||
message(FATAL_ERROR "${target} does not exist!") | ||
endif() | ||
if(NOT OpenCV_SOURCE_DIR) | ||
message(FATAL_ERROR "OpenCV_SOURCE_DIR must be set to build the plugin!") | ||
endif() | ||
|
||
add_library(${name} MODULE | ||
"${CMAKE_CURRENT_LIST_DIR}/src/${videoio_src_file}" | ||
"${CMAKE_CURRENT_LIST_DIR}/src/plugin_api.cpp") | ||
target_include_directories(${name} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") | ||
target_compile_definitions(${name} PRIVATE BUILD_PLUGIN) | ||
target_link_libraries(${name} PRIVATE ${target}) | ||
|
||
foreach(mod opencv_videoio opencv_core opencv_imgproc opencv_imgcodecs) | ||
target_link_libraries(${name} PRIVATE ${mod}) | ||
target_include_directories(${name} PRIVATE "${OPENCV_MODULE_${mod}_LOCATION}/include") | ||
endforeach() | ||
|
||
set_target_properties(${name} PROPERTIES | ||
CXX_STANDARD 11 | ||
CXX_VISIBILITY_PRESET hidden | ||
) | ||
install(TARGETS ${name} LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT plugins OPTIONAL) | ||
|
||
endfunction() | ||
|
||
#============================================= | ||
# standalone build | ||
|
||
function(ocv_create_videoio_plugin default_name target target_desc videoio_src_file) | ||
|
||
set(OPENCV_PLUGIN_NAME ${default_name} CACHE STRING "") | ||
set(OPENCV_PLUGIN_DESTINATION "" CACHE PATH "") | ||
project(${OPENCV_PLUGIN_NAME} LANGUAGES CXX) | ||
|
||
set(BUILD_SHARED_LIBS ON CACHE BOOL "") | ||
if(NOT BUILD_SHARED_LIBS) | ||
message(FATAL_ERROR "Static plugin build does not make sense") | ||
endif() | ||
|
||
if(NOT OpenCV_SOURCE_DIR) | ||
message(FATAL_ERROR "OpenCV_SOURCE_DIR must be set to build the plugin!") | ||
endif() | ||
|
||
include("${OpenCV_SOURCE_DIR}/modules/videoio/cmake/init.cmake") | ||
|
||
if(NOT TARGET ${target}) | ||
message(FATAL_ERROR "${target_desc} was not found!") | ||
endif() | ||
|
||
set(modules_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../..") | ||
set(videoio_ROOT "${modules_ROOT}/videoio") | ||
set(core_ROOT "${modules_ROOT}/core") | ||
set(imgproc_ROOT "${modules_ROOT}/imgproc") | ||
set(imgcodecs_ROOT "${modules_ROOT}/imgcodecs") | ||
|
||
add_library(${OPENCV_PLUGIN_NAME} MODULE "${videoio_ROOT}/src/${videoio_src_file}" "${videoio_ROOT}/src/plugin_api.cpp") | ||
target_include_directories(${OPENCV_PLUGIN_NAME} PRIVATE | ||
"${CMAKE_CURRENT_BINARY_DIR}" | ||
"${videoio_ROOT}/src" | ||
"${videoio_ROOT}/include" | ||
"${core_ROOT}/include" | ||
"${imgproc_ROOT}/include" | ||
"${imgcodecs_ROOT}/include" | ||
) | ||
target_compile_definitions(${OPENCV_PLUGIN_NAME} PRIVATE BUILD_PLUGIN) | ||
|
||
# Fixes for build | ||
target_compile_definitions(${OPENCV_PLUGIN_NAME} PRIVATE __OPENCV_BUILD) | ||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cvconfig.h" "#pragma once") | ||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cv_cpu_config.h" "#pragma once") | ||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/opencv2/opencv_modules.hpp" "#pragma once") | ||
|
||
target_link_libraries(${OPENCV_PLUGIN_NAME} PRIVATE ${target}) | ||
set_target_properties(${OPENCV_PLUGIN_NAME} PROPERTIES | ||
CXX_STANDARD 11 | ||
CXX_VISIBILITY_PRESET hidden | ||
) | ||
|
||
# Hack for Windows | ||
if(WIN32) | ||
find_package(OpenCV REQUIRED core imgproc videoio) | ||
target_link_libraries(${OPENCV_PLUGIN_NAME} ${OpenCV_LIBS}) | ||
endif() | ||
|
||
if(OPENCV_PLUGIN_DESTINATION) | ||
set_target_properties(${OPENCV_PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${OPENCV_PLUGIN_DESTINATION}") | ||
message(STATUS "Output destination: ${OPENCV_PLUGIN_DESTINATION}") | ||
endif() | ||
|
||
message(STATUS "Library name: ${OPENCV_PLUGIN_NAME}") | ||
|
||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [ -z $1 ] ; then | ||
echo "<script> <destination directory>" | ||
exit 1 | ||
fi | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
OCV="$( cd "${DIR}/../../.." >/dev/null 2>&1 && pwd )" | ||
mkdir -p "${1}" # Docker creates non-existed mounts with 'root' owner, lets ensure that dir exists under the current user to avoid "Permission denied" problem | ||
DST="$( cd "$1" >/dev/null 2>&1 && pwd )" | ||
CFG=$2 | ||
|
||
do_build() | ||
{ | ||
TAG=$1 | ||
D=$2 | ||
F=$3 | ||
shift 3 | ||
docker build \ | ||
--build-arg http_proxy \ | ||
--build-arg https_proxy \ | ||
$@ \ | ||
-t $TAG \ | ||
-f "${D}/${F}" \ | ||
"${D}" | ||
} | ||
|
||
do_run() | ||
{ | ||
TAG=$1 | ||
shift 1 | ||
docker run \ | ||
-it \ | ||
--rm \ | ||
-v "${OCV}":/opencv:ro \ | ||
-v "${DST}":/dst \ | ||
-e CFG=$CFG \ | ||
--user $(id -u):$(id -g) \ | ||
$TAG \ | ||
$@ | ||
} | ||
|
||
build_gstreamer() | ||
{ | ||
TAG=opencv_gstreamer_builder | ||
do_build $TAG "${DIR}/plugin_gstreamer" Dockerfile | ||
do_run $TAG /opencv/modules/videoio/misc/plugin_gstreamer/build.sh /dst $CFG | ||
} | ||
|
||
build_ffmpeg_ubuntu() | ||
{ | ||
VER=$1 | ||
TAG=opencv_ffmpeg_ubuntu_builder:${VER} | ||
do_build $TAG "${DIR}/plugin_ffmpeg" Dockerfile-ubuntu --build-arg VER=${VER} | ||
do_run $TAG /opencv/modules/videoio/misc/plugin_ffmpeg/build-ubuntu.sh /dst ${VER} ${CFG} | ||
} | ||
|
||
build_ffmpeg() | ||
{ | ||
VER=$1 | ||
TAG=opencv_ffmpeg_builder:${VER} | ||
ARCHIVE="${DIR}/plugin_ffmpeg/ffmpeg-${VER}.tar.xz" | ||
if [ ! -f "${ARCHIVE}" ] ; then | ||
wget https://www.ffmpeg.org/releases/ffmpeg-${VER}.tar.xz -O "${ARCHIVE}" | ||
fi | ||
do_build $TAG "${DIR}/plugin_ffmpeg" Dockerfile-ffmpeg --build-arg VER=${VER} | ||
do_run $TAG /opencv/modules/videoio/misc/plugin_ffmpeg/build-standalone.sh /dst ${VER} ${CFG} | ||
} | ||
|
||
echo "OpenCV: ${OCV}" | ||
echo "Destination: ${DST}" | ||
|
||
build_gstreamer | ||
build_ffmpeg_ubuntu 18.04 | ||
build_ffmpeg_ubuntu 16.04 | ||
build_ffmpeg 4.1 | ||
build_ffmpeg 3.4.5 | ||
build_ffmpeg 2.8.15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.tar.xz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
set(OpenCV_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../..") | ||
set(WITH_FFMPEG ON) | ||
set(OPENCV_FFMPEG_SKIP_BUILD_CHECK ON) | ||
include("${OpenCV_SOURCE_DIR}/modules/videoio/cmake/plugin.cmake") | ||
ocv_create_videoio_plugin("opencv_videoio_ffmpeg" "ocv.3rdparty.ffmpeg" "FFmpeg" "cap_ffmpeg.cpp") | ||
|
||
message(STATUS "FFMPEG_libavcodec_VERSION=${FFMPEG_libavcodec_VERSION}") | ||
message(STATUS "FFMPEG_libavformat_VERSION=${FFMPEG_libavformat_VERSION}") | ||
message(STATUS "FFMPEG_libavutil_VERSION=${FFMPEG_libavutil_VERSION}") | ||
message(STATUS "FFMPEG_libswscale_VERSION=${FFMPEG_libswscale_VERSION}") | ||
message(STATUS "FFMPEG_libavresample_VERSION=${FFMPEG_libavresample_VERSION}") |
Oops, something went wrong.