FindFFmpeg.cmake 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # ==============================================
  2. # Try to find FFmpeg libraries:
  3. # - avcodec
  4. # - avformat
  5. # - avdevice
  6. # - avutil
  7. # - swscale
  8. # - avfilter
  9. #
  10. # FFMPEG_FOUND - system has FFmpeg
  11. # FFMPEG_INCLUDE_DIR - the FFmpeg inc directory
  12. # FFMPEG_LIBRARIES - Link these to use FFmpeg
  13. # ==============================================
  14. # Notice: this original script is from internet.
  15. if (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
  16. # in cache already
  17. set(FFMPEG_FOUND TRUE)
  18. else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
  19. find_path(
  20. FFMPEG_AVCODEC_INCLUDE_DIR
  21. NAMES libavcodec/avcodec.h
  22. PATHS ${_FFMPEG_AVCODEC_INCLUDE_DIRS}
  23. /usr/include/ffmpeg
  24. /usr/local/include
  25. /usr/local/ffmpeg/include
  26. )
  27. find_library(
  28. FFMPEG_LIBAVCODEC
  29. NAMES avcodec
  30. PATHS ${_FFMPEG_AVCODEC_LIBRARY_DIRS}
  31. /usr/lib64
  32. /usr/local/lib
  33. /usr/local/ffmpeg/lib
  34. /usr/lib/aarch64-linux-gnu/
  35. )
  36. find_library(
  37. FFMPEG_LIBAVFORMAT
  38. NAMES avformat
  39. PATHS ${_FFMPEG_AVFORMAT_LIBRARY_DIRS}
  40. /usr/lib64
  41. /usr/local/lib
  42. /usr/local/ffmpeg/lib
  43. /usr/lib/aarch64-linux-gnu
  44. )
  45. find_library(
  46. FFMPEG_LIBSWRESAMPLE
  47. NAMES swresample
  48. PATHS ${_FFMPEG_SWRESAMPLE_LIBRARY_DIRS}
  49. /usr/lib64
  50. /usr/local/lib
  51. /usr/local/ffmpeg/lib
  52. /usr/lib/aarch64-linux-gnu/
  53. )
  54. find_library(
  55. FFMPEG_LIBAVUTIL
  56. NAMES avutil
  57. PATHS ${_FFMPEG_AVUTIL_LIBRARY_DIRS}
  58. /usr/lib64
  59. /usr/local/lib
  60. /usr/local/ffmpeg/lib
  61. /usr/lib/aarch64-linux-gnu/
  62. )
  63. find_library(
  64. FFMPEG_LIBSWSCALE
  65. NAMES swscale
  66. PATHS ${_FFMPEG_SWSCALE_LIBRARY_DIRS}
  67. /usr/lib64
  68. /usr/local/lib
  69. /usr/local/ffmpeg/lib
  70. /usr/lib/aarch64-linux-gnu/
  71. )
  72. find_library(
  73. FFMPEG_LIBAVFILTER
  74. NAMES avfilter
  75. PATHS ${_FFMPEG_AVFILTER_LIBRARY_DIRS}
  76. /usr/lib64
  77. /usr/local/lib
  78. /usr/local/ffmpeg/lib
  79. /usr/lib/aarch64-linux-gnu/
  80. )
  81. find_library(
  82. FFMPEG_LIBAVDEVICE
  83. NAMES avdevice
  84. PATHS ${_FFMPEG_AVDEVICE_LIBRARY_DIRS}
  85. /usr/lib64
  86. /usr/local/lib
  87. /usr/local/ffmpeg/lib
  88. /usr/lib/aarch64-linux-gnu/
  89. )
  90. if (WITH_FFMPEG_AVDEVICE AND NOT FFMPEG_LIBAVDEVICE)
  91. message(FATAL_ERROR "Not find FFmpeg LIBAVDEVICE ")
  92. endif ()
  93. if (FFMPEG_LIBAVCODEC AND FFMPEG_LIBAVFORMAT AND FFMPEG_LIBAVUTIL AND FFMPEG_LIBSWSCALE AND FFMPEG_LIBSWRESAMPLE AND (FFMPEG_LIBAVDEVICE OR NOT WITH_FFMPEG_AVDEVICE))
  94. set(FFMPEG_FOUND TRUE)
  95. endif ()
  96. if (FFMPEG_FOUND)
  97. set(FFMPEG_INCLUDE_DIR ${FFMPEG_AVCODEC_INCLUDE_DIR})
  98. set(FFMPEG_LIBRARIES
  99. ${FFMPEG_LIBAVCODEC}
  100. ${FFMPEG_LIBAVFORMAT}
  101. ${FFMPEG_LIBAVUTIL}
  102. ${FFMPEG_LIBSWSCALE}
  103. ${FFMPEG_LIBSWRESAMPLE})
  104. if (WITH_FFMPEG_AVDEVICE)
  105. list(APPEND FFMPEG_LIBRARIES ${FFMPEG_LIBAVDEVICE})
  106. endif (WITH_FFMPEG_AVDEVICE)
  107. else (FFMPEG_FOUND)
  108. message(FATAL_ERROR "Could not find FFmpeg libraries!")
  109. endif (FFMPEG_FOUND)
  110. endif (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)