icvInitFFMPEG() { #if defined WIN32 || defined _WIN32 const char* module_name = "opencv_ffmpeg" CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) CVAUX_STR(CV_SUBMINOR_VERSION) #if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__) "_64" #endif ".dll"; icvFFOpenCV = LoadLibrary( module_name ); if( icvFFOpenCV ) { icvCreateFileCapture_FFMPEG_p = (CvCreateFileCapture_Plugin)GetProcAddress(icvFFOpenCV, "cvCreateFileCapture_FFMPEG"); icvReleaseCapture_FFMPEG_p = (CvReleaseCapture_Plugin)GetProcAddress(icvFFOpenCV, "cvReleaseCapture_FFMPEG"); icvGrabFrame_FFMPEG_p = (CvGrabFrame_Plugin)GetProcAddress(icvFFOpenCV, "cvGrabFrame_FFMPEG"); icvRetrieveFrame_FFMPEG_p = (CvRetrieveFrame_Plugin)GetProcAddress(icvFFOpenCV, "cvRetrieveFrame_FFMPEG"); icvSetCaptureProperty_FFMPEG_p = (CvSetCaptureProperty_Plugin)GetProcAddress(icvFFOpenCV, "cvSetCaptureProperty_FFMPEG"); icvGetCaptureProperty_FFMPEG_p = (CvGetCaptureProperty_Plugin)GetProcAddress(icvFFOpenCV, "cvGetCaptureProperty_FFMPEG"); icvCreateVideoWriter_FFMPEG_p = (CvCreateVideoWriter_Plugin)GetProcAddress(icvFFOpenCV, "cvCreateVideoWriter_FFMPEG"); icvReleaseVideoWriter_FFMPEG_p = (CvReleaseVideoWriter_Plugin)GetProcAddress(icvFFOpenCV, "cvReleaseVideoWriter_FFMPEG"); icvWriteFrame_FFMPEG_p = (CvWriteFrame_Plugin)GetProcAddress(icvFFOpenCV, "cvWriteFrame_FFMPEG"); if( icvCreateFileCapture_FFMPEG_p == NULL || icvReleaseCapture_FFMPEG_p == NULL || icvGrabFrame_FFMPEG_p == NULL || icvRetrieveFrame_FFMPEG_p == NULL || icvSetCaptureProperty_FFMPEG_p == NULL || icvGetCaptureProperty_FFMPEG_p == NULL || icvCreateVideoWriter_FFMPEG_p == NULL || icvReleaseVideoWriter_FFMPEG_p == NULL || icvWriteFrame_FFMPEG_p == NULL ) { fprintf(stderr, "Failed to load FFMPEG plugin: module handle=%p\n", icvFFOpenCV); } } #elif defined HAVE_FFMPEG icvCreateFileCapture_FFMPEG_p = (CvCreateFileCapture_Plugin)cvCreateFileCapture_FFMPEG; icvReleaseCapture_FFMPEG_p = (CvReleaseCapture_Plugin)cvReleaseCapture_FFMPEG; icvGrabFrame_FFMPEG_p = (CvGrabFrame_Plugin)cvGrabFrame_FFMPEG; icvRetrieveFrame_FFMPEG_p = (CvRetrieveFrame_Plugin)cvRetrieveFrame_FFMPEG; icvSetCaptureProperty_FFMPEG_p = (CvSetCaptureProperty_Plugin)cvSetCaptureProperty_FFMPEG; icvGetCaptureProperty_FFMPEG_p = (CvGetCaptureProperty_Plugin)cvGetCaptureProperty_FFMPEG; icvCreateVideoWriter_FFMPEG_p = (CvCreateVideoWriter_Plugin)cvCreateVideoWriter_FFMPEG; icvReleaseVideoWriter_FFMPEG_p = (CvReleaseVideoWriter_Plugin)cvReleaseVideoWriter_FFMPEG; icvWriteFrame_FFMPEG_p = (CvWriteFrame_Plugin)cvWriteFrame_FFMPEG; #endif }
cv::String getCacheDirectory(const char* sub_directory_name, const char* configuration_name) { String cache_path; if (configuration_name) { cache_path = utils::getConfigurationParameterString(configuration_name, ""); } if (cache_path.empty()) { cv::String default_cache_path; #ifdef _WIN32 char tmp_path_buf[MAX_PATH+1] = {0}; DWORD res = GetTempPath(MAX_PATH, tmp_path_buf); if (res > 0 && res <= MAX_PATH) { default_cache_path = tmp_path_buf; } #elif defined __ANDROID__ // no defaults #elif defined __APPLE__ const char* tmpdir_env = getenv("TMPDIR"); if (tmpdir_env && utils::fs::isDirectory(tmpdir_env)) { default_cache_path = tmpdir_env; } else { default_cache_path = "/tmp/"; CV_LOG_WARNING(NULL, "Using world accessible cache directory. This may be not secure: " << default_cache_path); } #elif defined __linux__ || defined __HAIKU__ || defined __FreeBSD__ // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if (default_cache_path.empty()) { const char* xdg_cache_env = getenv("XDG_CACHE_HOME"); if (xdg_cache_env && xdg_cache_env[0] && utils::fs::isDirectory(xdg_cache_env)) { default_cache_path = xdg_cache_env; } } if (default_cache_path.empty()) { const char* home_env = getenv("HOME"); if (home_env && home_env[0] && utils::fs::isDirectory(home_env)) { cv::String home_path = home_env; cv::String home_cache_path = utils::fs::join(home_path, ".cache/"); if (utils::fs::isDirectory(home_cache_path)) { default_cache_path = home_cache_path; } } } if (default_cache_path.empty()) { const char* temp_path = "/var/tmp/"; if (utils::fs::isDirectory(temp_path)) { default_cache_path = temp_path; CV_LOG_WARNING(NULL, "Using world accessible cache directory. This may be not secure: " << default_cache_path); } } if (default_cache_path.empty()) { default_cache_path = "/tmp/"; CV_LOG_WARNING(NULL, "Using world accessible cache directory. This may be not secure: " << default_cache_path); } #else // no defaults #endif CV_LOG_VERBOSE(NULL, 0, "default_cache_path = " << default_cache_path); if (!default_cache_path.empty()) { if (utils::fs::isDirectory(default_cache_path)) { cv::String default_cache_path_base = utils::fs::join(default_cache_path, "opencv"); default_cache_path = utils::fs::join(default_cache_path_base, CVAUX_STR(CV_VERSION_MAJOR) "." CVAUX_STR(CV_VERSION_MINOR) CV_VERSION_STATUS); if (utils::getConfigurationParameterBool("OPENCV_CACHE_SHOW_CLEANUP_MESSAGE", true) && !utils::fs::isDirectory(default_cache_path)) { std::vector<cv::String> existedCacheDirs; try { utils::fs::glob_relative(default_cache_path_base, "*", existedCacheDirs, false, true); } catch (...) { // ignore } if (!existedCacheDirs.empty()) { CV_LOG_WARNING(NULL, "Creating new OpenCV cache directory: " << default_cache_path); CV_LOG_WARNING(NULL, "There are several neighbour directories, probably created by old OpenCV versions."); CV_LOG_WARNING(NULL, "Feel free to cleanup these unused directories:"); for (size_t i = 0; i < existedCacheDirs.size(); i++) { CV_LOG_WARNING(NULL, " - " << existedCacheDirs[i]); } CV_LOG_WARNING(NULL, "Note: This message is showed only once."); } } if (sub_directory_name && sub_directory_name[0] != '\0') default_cache_path = utils::fs::join(default_cache_path, cv::String(sub_directory_name) + native_separator); if (!utils::fs::createDirectories(default_cache_path)) { CV_LOG_DEBUG(NULL, "Can't create OpenCV cache sub-directory: " << default_cache_path); } else { cache_path = default_cache_path; } } else { CV_LOG_INFO(NULL, "Can't find default cache directory (does it exist?): " << default_cache_path); } } else { CV_LOG_DEBUG(NULL, "OpenCV has no support to discover default cache directory on the current platform"); } } else { if (cache_path == "disabled") return cache_path; if (!isDirectory(cache_path)) { CV_LOG_WARNING(NULL, "Specified non-existed directory, creating OpenCV sub-directory for caching purposes: " << cache_path); if (!createDirectories(cache_path)) { CV_LOG_ERROR(NULL, "Can't create OpenCV cache sub-directory: " << cache_path); cache_path.clear(); } } } CV_Assert(cache_path.empty() || utils::fs::isDirectory(cache_path)); if (!cache_path.empty()) { if (!isPathSeparator(cache_path[cache_path.size() - 1])) { cache_path += native_separator; } } return cache_path; }