diff --git a/platforms/android/build_sdk.py b/platforms/android/build_sdk.py index f4d39074c7..f27a392f7e 100755 --- a/platforms/android/build_sdk.py +++ b/platforms/android/build_sdk.py @@ -215,7 +215,7 @@ class Builder: for d in ["CMakeCache.txt", "CMakeFiles/", "bin/", "libs/", "lib/", "package/", "install/samples/"]: rm_one(d) - def build_library(self, abi, do_install): + def build_library(self, abi, do_install, no_media_ndk): cmd = [self.cmake_path, "-GNinja"] cmake_vars = dict( CMAKE_TOOLCHAIN_FILE=self.get_toolchain_file(), @@ -260,6 +260,9 @@ class Builder: if do_install: cmd.extend(["-DBUILD_TESTS=ON", "-DINSTALL_TESTS=ON"]) + if no_media_ndk: + cmake_vars['WITH_ANDROID_MEDIANDK'] = "OFF" + cmake_vars.update(abi.cmake_vars) cmd += [ "-D%s='%s'" % (k, v) for (k, v) in cmake_vars.items() if v is not None] cmd.append(self.opencvdir) @@ -370,6 +373,7 @@ if __name__ == "__main__": parser.add_argument('--opencl', action="store_true", help="Enable OpenCL support") parser.add_argument('--no_kotlin', action="store_true", help="Disable Kotlin extensions") parser.add_argument('--shared', action="store_true", help="Build shared libraries") + parser.add_argument('--no_media_ndk', action="store_true", help="Do not link Media NDK (required for video I/O support)") args = parser.parse_args() log.basicConfig(format='%(message)s', level=log.DEBUG) @@ -447,7 +451,7 @@ if __name__ == "__main__": os.chdir(builder.libdest) builder.clean_library_build_dir() - builder.build_library(abi, do_install) + builder.build_library(abi, do_install, args.no_media_ndk) builder.gather_results() diff --git a/samples/android/CMakeLists.txt b/samples/android/CMakeLists.txt index f4fe882447..fe6318f48e 100644 --- a/samples/android/CMakeLists.txt +++ b/samples/android/CMakeLists.txt @@ -13,6 +13,7 @@ add_subdirectory(image-manipulations) add_subdirectory(camera-calibration) add_subdirectory(color-blob-detection) add_subdirectory(mobilenet-objdetect) +add_subdirectory(video-recorder) add_subdirectory(tutorial-1-camerapreview) add_subdirectory(tutorial-2-mixedprocessing) add_subdirectory(tutorial-3-cameracontrol) diff --git a/samples/android/video-recorder/CMakeLists.txt b/samples/android/video-recorder/CMakeLists.txt new file mode 100644 index 0000000000..e833d8fd6f --- /dev/null +++ b/samples/android/video-recorder/CMakeLists.txt @@ -0,0 +1,12 @@ +set(sample example-video-recorder) + +if(BUILD_FAT_JAVA_LIB) + set(native_deps opencv_java) +else() + set(native_deps videoio) +endif() + +add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS "${OPENCV_ANDROID_LIB_DIR}" SDK_TARGET 11 "${ANDROID_SDK_TARGET}" NATIVE_DEPS ${native_deps}) +if(TARGET ${sample}) + add_dependencies(opencv_android_examples ${sample}) +endif() diff --git a/samples/android/video-recorder/build.gradle.in b/samples/android/video-recorder/build.gradle.in new file mode 100644 index 0000000000..b279623803 --- /dev/null +++ b/samples/android/video-recorder/build.gradle.in @@ -0,0 +1,36 @@ +apply plugin: 'com.android.application' + +android { + namespace 'org.opencv.samples.recorder' + compileSdkVersion @ANDROID_COMPILE_SDK_VERSION@ + defaultConfig { + applicationId "org.opencv.samples.recorder" + minSdkVersion @ANDROID_MIN_SDK_VERSION@ + targetSdkVersion @ANDROID_TARGET_SDK_VERSION@ + versionCode 301 + versionName "3.01" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + sourceSets { + main { + java.srcDirs = @ANDROID_SAMPLE_JAVA_PATH@ + aidl.srcDirs = @ANDROID_SAMPLE_JAVA_PATH@ + res.srcDirs = @ANDROID_SAMPLE_RES_PATH@ + manifest.srcFile '@ANDROID_SAMPLE_MANIFEST_PATH@' + } + } +} + +dependencies { + //implementation fileTree(dir: 'libs', include: ['*.jar']) + if (gradle.opencv_source == "sdk_path") { + implementation project(':opencv') + } else if (gradle.opencv_source == "maven_local" || gradle.opencv_source == "maven_cenral") { + implementation 'org.opencv:opencv:@OPENCV_VERSION_PLAIN@' + } +} diff --git a/samples/android/video-recorder/gradle/AndroidManifest.xml b/samples/android/video-recorder/gradle/AndroidManifest.xml new file mode 100644 index 0000000000..fc4129c0f2 --- /dev/null +++ b/samples/android/video-recorder/gradle/AndroidManifest.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/android/video-recorder/res/drawable/icon.png b/samples/android/video-recorder/res/drawable/icon.png new file mode 100644 index 0000000000..630454927b Binary files /dev/null and b/samples/android/video-recorder/res/drawable/icon.png differ diff --git a/samples/android/video-recorder/res/layout/recorder_surface_view.xml b/samples/android/video-recorder/res/layout/recorder_surface_view.xml new file mode 100644 index 0000000000..9df6114140 --- /dev/null +++ b/samples/android/video-recorder/res/layout/recorder_surface_view.xml @@ -0,0 +1,38 @@ + + +