# Find FFmpeg # # This module defines # FFMPEG_FOUND # FFMPEG_INCLUDE_DIRS # FFMPEG_LIBRARIES # # Copyright (c) 2016 I-maginer # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU Lesser General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any later # version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 59 Temple # Place - Suite 330, Boston, MA 02111-1307, USA, or go to # http://www.gnu.org/copyleft/lesser.txt # INCLUDE (CheckIncludeFiles) # On a new cmake run, we do not need to be verbose IF(FFMPEG_INCLUDE_DIRS AND FFMPEG_LIBRARIES) SET(FFMPEG_FIND_QUIETLY TRUE) ENDIF(FFMPEG_INCLUDE_DIRS AND FFMPEG_LIBRARIES) include(FindPkgMacros) findpkg_begin(FFMPEG) create_search_paths(FFMPEG) # If FFMPEG_ROOT was defined in the environment, use it. if (NOT FFMPEG_ROOT) set(FFMPEG_ROOT ${FFMPEG_PREFIX_PATH} CACHE PATH "FFMPEG SDK path" FORCE) endif(NOT FFMPEG_ROOT) # concat all the search paths IF (FFMPEG_ROOT) SET(FFMPEG_INCLUDE_SEARCH_DIRS ${FFMPEG_ROOT}/include ) SET(FFMPEG_LIBRARY_SEARCH_RELEASE_DIRS ${FFMPEG_LIBRARY_SEARCH_DIRS} ${FFMPEG_ROOT}/lib ) SET(FFMPEG_LIBRARY_SEARCH_DEBUG_DIRS ${FFMPEG_LIBRARY_SEARCH_DIRS} ${FFMPEG_ROOT}/lib ) ENDIF(FFMPEG_ROOT) # log message IF (NOT FFMPEG_FIND_QUIETLY) MESSAGE(STATUS "Checking for FFmpeg library") ENDIF(NOT FFMPEG_FIND_QUIETLY) # Search for header files FIND_PATH(FFMPEG_INCLUDE_DIR libavformat/avformat.h PATHS ${FFMPEG_INCLUDE_SEARCH_DIRS}) # FFmpeg needs inttypes.h, add it the compiler lacks it CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H) IF (NOT HAVE_INTTYPES_H AND WIN32) SET(FFMPEG_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR} $ENV{SCOL_DEPENDENCIES_PATH}/ffmpeg/sources/requirements/msinttypes) ENDIF(NOT HAVE_INTTYPES_H AND WIN32) SET(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIR} CACHE STRING "Directory containing FFmpeg header files") message("Search dir ${FFMPEG_LIBRARY_SEARCH_RELEASE_DIRS}") # Search for libraries files (release mode) FIND_LIBRARY(FFMPEG_LIBRARY_LIBAVFORMAT_RELEASE libavformat avformat PATHS ${FFMPEG_LIBRARY_SEARCH_RELEASE_DIRS} NO_DEFAULT_PATH) # Search for libraries files (debug mode) FIND_LIBRARY(FFMPEG_LIBRARY_LIBAVFORMAT_DEBUG avformatd libavformat_d avformat_d libavformat avformat PATHS ${FFMPEG_LIBRARY_SEARCH_DEBUG_DIRS} NO_DEFAULT_PATH) SET(FFMPEG_LIBAVFORMAT_LIBRARY debug ${FFMPEG_LIBRARY_LIBAVFORMAT_DEBUG} optimized ${FFMPEG_LIBRARY_LIBAVFORMAT_RELEASE}) # Search for libraries files (release mode) FIND_LIBRARY(FFMPEG_LIBRARY_LIBAVFILTER_RELEASE libavfilter avfilter PATHS ${FFMPEG_LIBRARY_SEARCH_RELEASE_DIRS} NO_DEFAULT_PATH) # Search for libraries files (debug mode) FIND_LIBRARY(FFMPEG_LIBRARY_LIBAVFILTER_DEBUG avfilterd libavfilter_d avfilter_d libavfilter avfilter PATHS ${FFMPEG_LIBRARY_SEARCH_DEBUG_DIRS} NO_DEFAULT_PATH) SET(FFMPEG_LIBAVFILTER_LIBRARY debug ${FFMPEG_LIBRARY_LIBAVFILTER_DEBUG} optimized ${FFMPEG_LIBRARY_LIBAVFILTER_RELEASE}) # Search for libraries files (release mode) FIND_LIBRARY(FFMPEG_LIBRARY_LIBAVUTIL_RELEASE libavutil avutil PATHS ${FFMPEG_LIBRARY_SEARCH_RELEASE_DIRS} NO_DEFAULT_PATH) # Search for libraries files (debug mode) FIND_LIBRARY(FFMPEG_LIBRARY_LIBAVUTIL_DEBUG avutild libavutil_d avutil_d libavutil avutil PATHS ${FFMPEG_LIBRARY_SEARCH_DEBUG_DIRS} NO_DEFAULT_PATH) SET(FFMPEG_LIBAVUTIL_LIBRARY debug ${FFMPEG_LIBRARY_LIBAVUTIL_DEBUG} optimized ${FFMPEG_LIBRARY_LIBAVUTIL_RELEASE}) # Search for libraries files (release mode) FIND_LIBRARY(FFMPEG_LIBRARY_LIBAVCODEC_RELEASE libavcodec avcodec PATHS ${FFMPEG_LIBRARY_SEARCH_RELEASE_DIRS} NO_DEFAULT_PATH) # Search for libraries files (debug mode) FIND_LIBRARY(FFMPEG_LIBRARY_LIBAVCODEC_DEBUG avcodecd libavcodec_d avcodec_d libavcodec avcodec PATHS ${FFMPEG_LIBRARY_SEARCH_DEBUG_DIRS} NO_DEFAULT_PATH) SET(FFMPEG_LIBAVCODEC_LIBRARY debug ${FFMPEG_LIBRARY_LIBAVCODEC_DEBUG} optimized ${FFMPEG_LIBRARY_LIBAVCODEC_RELEASE}) # Search for libraries files (release mode) FIND_LIBRARY(FFMPEG_LIBRARY_LIBSWSCALE_RELEASE libswscale swscale PATHS ${FFMPEG_LIBRARY_SEARCH_RELEASE_DIRS} NO_DEFAULT_PATH) # Search for libraries files (debug mode) FIND_LIBRARY(FFMPEG_LIBRARY_LIBSWSCALE_DEBUG swscaled libswscale_d swscale_d libswscale swscale PATHS ${FFMPEG_LIBRARY_SEARCH_DEBUG_DIRS} NO_DEFAULT_PATH) SET(FFMPEG_LIBSWSCALE_LIBRARY debug ${FFMPEG_LIBRARY_LIBSWSCALE_DEBUG} optimized ${FFMPEG_LIBRARY_LIBSWSCALE_RELEASE}) # Search for libraries files (release mode) FIND_LIBRARY(FFMPEG_LIBRARY_LIBSWRESAMPLE_RELEASE libswresample swresample PATHS ${FFMPEG_LIBRARY_SEARCH_RELEASE_DIRS} NO_DEFAULT_PATH) # Search for libraries files (debug mode) FIND_LIBRARY(FFMPEG_LIBRARY_LIBSWRESAMPLE_DEBUG swresampled libswresample_d swresample_d libswresample swresample PATHS ${FFMPEG_LIBRARY_SEARCH_DEBUG_DIRS} NO_DEFAULT_PATH) SET(FFMPEG_LIBSWRESAMPLE_LIBRARY debug ${FFMPEG_LIBRARY_LIBSWRESAMPLE_DEBUG} optimized ${FFMPEG_LIBRARY_LIBSWRESAMPLE_RELEASE}) # Search for libraries files (release mode) #FIND_LIBRARY(FFMPEG_LIBRARY_LIBAVRESAMPLE_RELEASE libavresample avresample PATHS ${FFMPEG_LIBRARY_SEARCH_RELEASE_DIRS} NO_DEFAULT_PATH) # Search for libraries files (debug mode) #FIND_LIBRARY(FFMPEG_LIBRARY_LIBAVRESAMPLE_DEBUG avresampled libavresample_d avresample_d libavresample avresample PATHS ${FFMPEG_LIBRARY_SEARCH_DEBUG_DIRS} NO_DEFAULT_PATH) #SET(FFMPEG_LIBAVRESAMPLE_LIBRARY debug ${FFMPEG_LIBRARY_LIBAVRESAMPLE_DEBUG} optimized ${FFMPEG_LIBRARY_LIBAVRESAMPLE_RELEASE}) SET(FFMPEG_LIBRARIES ${FFMPEG_LIBAVFILTER_LIBRARY} ${FFMPEG_LIBSWSCALE_LIBRARY} ${FFMPEG_LIBSWRESAMPLE_LIBRARY} ${FFMPEG_LIBAVFORMAT_LIBRARY} ${FFMPEG_LIBAVCODEC_LIBRARY} ${FFMPEG_LIBAVUTIL_LIBRARY} CACHE STRING "FFmpeg libraries files" FORCE) IF(FFMPEG_INCLUDE_DIR AND FFMPEG_LIBRARIES) SET(FFMPEG_FOUND TRUE) ENDIF(FFMPEG_INCLUDE_DIR AND FFMPEG_LIBRARIES) IF (WIN32 AND NOT ANDROID) SET(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} "Secur32.lib") ENDIF(WIN32 AND NOT ANDROID) # For static linkink, add FFmpeg dependencies # TODO: disable bzip and iconv in FFmpeg build ? IF(APPLE) IF (NOT APPLE_IOS) FIND_LIBRARY(COREMEDIA_LIBRARY CoreMedia) FIND_LIBRARY(COREVIDEO_LIBRARY CoreVideo) FIND_LIBRARY(VIDEODECODE_LIBRARY VideoDecodeAcceleration) FIND_LIBRARY(VIDEOTOOLBOX_LIBRARY VideoToolbox) FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY AudioToolBox) SET(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${COREMEDIA_LIBRARY} ${COREVIDEO_LIBRARY} ${VIDEODECODE_LIBRARY} ${VIDEOTOOLBOX_LIBRARY} ${AUDIOTOOLBOX_LIBRARY} CACHE STRING "FFmpeg libraries files" FORCE) ENDIF() find_package(BZip2) find_package(Iconv) IF(NOT (BZIP2_FOUND AND ICONV_FOUND)) MESSAGE(STATUS "FindFFmpeg: bzip2 and/or iconv couldn't be found") SET(FFMPEG_FOUND FALSE) ELSE() # Use direct link flags instead of ${ICONV} and ${BZIP2}, so if we switch SDK at build time, # the linker will pick up the lib in the current SDK instead of the one specified at configure time SET(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${BZIP2_LIBRARIES} ${ICONV_LIBRARIES} CACHE STRING "FFmpeg libraries files" FORCE) ENDIF() ELSEIF(UNIX AND NOT ANDROID AND NOT RPI) find_package(BZip2) find_package(Iconv) IF(NOT (BZIP2_FOUND AND ICONV_FOUND)) MESSAGE(STATUS "FindFFmpeg: bzip2 and/or iconv couldn't be found") SET(FFMPEG_FOUND FALSE) ELSE() # Use direct link flags instead of ${ICONV} and ${BZIP2}, so if we switch SDK at build time, # the linker will pick up the lib in the current SDK instead of the one specified at configure time SET(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${BZIP2_LIBRARIES} ${ICONV_LIBRARIES} CACHE STRING "FFmpeg libraries files" FORCE) ENDIF() ELSEIF(RPI) # Find required packages find_package(PkgConfig REQUIRED) pkg_check_modules(LZMA REQUIRED liblzma) SET(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${LZMA_LIBRARIES} CACHE STRING "FFmpeg libraries files" FORCE) ENDIF() # Hide those variables in GUI SET(FFMPEG_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR} CACHE INTERNAL "") SET(FFMPEG_LIBRARY_RELEASE ${FFMPEG_LIBRARY_RELEASE} CACHE INTERNAL "") SET(FFMPEG_LIBRARY_DEBUG ${FFMPEG_LIBRARY_DEBUG} CACHE INTERNAL "") SET(FFMPEG_LIBRARY ${FFMPEG_LIBRARY} CACHE INTERNAL "") # log find result IF(FFMPEG_FOUND) IF(NOT FFMPEG_FIND_QUIETLY) MESSAGE(STATUS " libraries: ${FFMPEG_LIBRARIES}") MESSAGE(STATUS " includes: ${FFMPEG_INCLUDE_DIRS}") ENDIF() ELSE(FFMPEG_FOUND) IF(NOT FFMPEG_LIBRARIES) MESSAGE(STATUS, "FFmpeg library or one of it dependencies could not be found.") ENDIF() IF(NOT FFMPEG_INCLUDE_DIRS) MESSAGE(STATUS "FFmpeg include files could not be found.") ENDIF() ENDIF(FFMPEG_FOUND)