FindFFmpeg.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/include/x86_64-linux-gnu
  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/lib/x86_64-linux-gnu
  34. )
  35. find_library(
  36. FFMPEG_LIBAVFORMAT
  37. NAMES avformat
  38. PATHS ${_FFMPEG_AVFORMAT_LIBRARY_DIRS}
  39. /usr/lib64
  40. /usr/local/lib
  41. /usr/lib/x86_64-linux-gnu
  42. )
  43. find_library(
  44. FFMPEG_LIBSWRESAMPLE
  45. NAMES swresample
  46. PATHS ${_FFMPEG_SWRESAMPLE_LIBRARY_DIRS}
  47. /usr/lib64
  48. /usr/local/lib
  49. /usr/lib/x86_64-linux-gnu
  50. )
  51. find_library(
  52. FFMPEG_LIBAVUTIL
  53. NAMES avutil
  54. PATHS ${_FFMPEG_AVUTIL_LIBRARY_DIRS}
  55. /usr/lib64
  56. /usr/local/lib
  57. /usr/lib/x86_64-linux-gnu
  58. )
  59. find_library(
  60. FFMPEG_LIBSWSCALE
  61. NAMES swscale
  62. PATHS ${_FFMPEG_SWSCALE_LIBRARY_DIRS}
  63. /usr/lib64
  64. /usr/local/lib
  65. /usr/lib/x86_64-linux-gnu
  66. )
  67. find_library(
  68. FFMPEG_LIBAVFILTER
  69. NAMES avfilter
  70. PATHS ${_FFMPEG_AVFILTER_LIBRARY_DIRS}
  71. /usr/lib64
  72. /usr/local/lib
  73. /usr/lib/x86_64-linux-gnu
  74. )
  75. find_library(
  76. FFMPEG_LIBAVDEVICE
  77. NAMES avdevice
  78. PATHS ${_FFMPEG_AVDEVICE_LIBRARY_DIRS}
  79. /usr/lib64
  80. /usr/local/lib
  81. /usr/lib/x86_64-linux-gnu
  82. )
  83. if (WITH_FFMPEG_AVDEVICE AND NOT FFMPEG_LIBAVDEVICE)
  84. message(FATAL_ERROR "Not find FFmpeg LIBAVDEVICE ")
  85. endif ()
  86. if (FFMPEG_LIBAVCODEC AND FFMPEG_LIBAVFORMAT AND FFMPEG_LIBAVUTIL AND FFMPEG_LIBSWSCALE AND FFMPEG_LIBSWRESAMPLE AND (FFMPEG_LIBAVDEVICE OR NOT WITH_FFMPEG_AVDEVICE))
  87. set(FFMPEG_FOUND TRUE)
  88. endif ()
  89. if (FFMPEG_FOUND)
  90. set(FFMPEG_INCLUDE_DIR ${FFMPEG_AVCODEC_INCLUDE_DIR})
  91. set(FFMPEG_LIBRARIES
  92. ${FFMPEG_LIBAVCODEC}
  93. ${FFMPEG_LIBAVFORMAT}
  94. ${FFMPEG_LIBAVUTIL}
  95. ${FFMPEG_LIBSWSCALE}
  96. ${FFMPEG_LIBSWRESAMPLE})
  97. if (WITH_FFMPEG_AVDEVICE)
  98. list(APPEND FFMPEG_LIBRARIES ${FFMPEG_LIBAVDEVICE})
  99. endif (WITH_FFMPEG_AVDEVICE)
  100. else (FFMPEG_FOUND)
  101. message(FATAL_ERROR "Could not find FFmpeg libraries!")
  102. endif (FFMPEG_FOUND)
  103. endif (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)