"git@developer.sourcefind.cn:OpenDAS/fairscale.git" did not exist on "5be4817dc15e27c336b37e2c8d297cc4ff8dc6cc"
Commit 963905e4 authored by moto's avatar moto Committed by Facebook GitHub Bot
Browse files

Improve ffmpeg library discovery (#2204)

Summary:
This commit fixes the issue with ffmpeg discovery at build time.
The original implementation had issues like.

1. Wrong usage of FindFFMPEG, which caused mixture of ffmpeg libraries from system directory and user directory.
2. The optional `FFMPEG_ROOT` variable was not set within cmake.

The issue 1 is problematic when a user does not have a permission to
modify the environment. For example, an old version of ffmpeg, which is
installed in a directory managed by the system (such as `/usr/local/lib`),
then there is no way to specify a path in which user installs a supported version
of ffmpeg.

This commit changes the behavior by first searching the library
in `FFMPEG_ROOT` environment variables, then
resorting to the original behavior of searching the custom paths with
system default path.

Also this commirt removes support for `libavresample`, which is deprecated in
ffmpeg 4 and removed in ffmpeg 5.

Pull Request resolved: https://github.com/pytorch/audio/pull/2204

Reviewed By: carolineechen

Differential Revision: D34225769

Pulled By: mthrok

fbshipit-source-id: 95b0bfaaef31e2e69e6df29f789010f48a48210b
parent 8e3c6144
...@@ -53,7 +53,6 @@ The following components are supported: ...@@ -53,7 +53,6 @@ The following components are supported:
* `avdevice` * `avdevice`
* `avfilter` * `avfilter`
* `avformat` * `avformat`
* `avresample`
* `avutil` * `avutil`
* `swresample` * `swresample`
* `swscale` * `swscale`
...@@ -75,7 +74,15 @@ function (_ffmpeg_find component headername) ...@@ -75,7 +74,15 @@ function (_ffmpeg_find component headername)
NAMES NAMES
"lib${component}/${headername}" "lib${component}/${headername}"
PATHS PATHS
"${FFMPEG_ROOT}/include" "$ENV{FFMPEG_ROOT}/include"
PATH_SUFFIXES
ffmpeg
DOC "FFMPEG's ${component} include directory"
NO_DEFAULT_PATH)
find_path("FFMPEG_${component}_INCLUDE_DIR"
NAMES
"lib${component}/${headername}"
PATHS
"$ENV{CONDA_PREFIX}/include" "$ENV{CONDA_PREFIX}/include"
~/Library/Frameworks ~/Library/Frameworks
/Library/Frameworks /Library/Frameworks
...@@ -101,7 +108,13 @@ function (_ffmpeg_find component headername) ...@@ -101,7 +108,13 @@ function (_ffmpeg_find component headername)
NAMES NAMES
"${component}" "${component}"
PATHS PATHS
"${FFMPEG_ROOT}/lib" "$ENV{FFMPEG_ROOT}/lib"
DOC "FFMPEG's ${component} library"
NO_DEFAULT_PATH)
find_library("FFMPEG_${component}_LIBRARY"
NAMES
"${component}"
PATHS
"$ENV{CONDA_PREFIX}/lib" "$ENV{CONDA_PREFIX}/lib"
~/Library/Frameworks ~/Library/Frameworks
/Library/Frameworks /Library/Frameworks
...@@ -114,7 +127,7 @@ function (_ffmpeg_find component headername) ...@@ -114,7 +127,7 @@ function (_ffmpeg_find component headername)
/opt/csw/lib /opt/csw/lib
/opt/lib /opt/lib
/usr/freeware/lib64 /usr/freeware/lib64
"${FFMPEG_ROOT}/bin" "$ENV{FFMPEG_ROOT}/bin"
DOC "FFMPEG's ${component} library") DOC "FFMPEG's ${component} library")
mark_as_advanced("FFMPEG_${component}_LIBRARY") mark_as_advanced("FFMPEG_${component}_LIBRARY")
...@@ -176,8 +189,6 @@ function (_ffmpeg_find component headername) ...@@ -176,8 +189,6 @@ function (_ffmpeg_find component headername)
endfunction () endfunction ()
_ffmpeg_find(avutil avutil.h) _ffmpeg_find(avutil avutil.h)
_ffmpeg_find(avresample avresample.h
avutil)
_ffmpeg_find(swresample swresample.h _ffmpeg_find(swresample swresample.h
avutil) avutil)
_ffmpeg_find(swscale swscale.h _ffmpeg_find(swscale swscale.h
......
...@@ -13,17 +13,6 @@ if (BUILD_SOX) ...@@ -13,17 +13,6 @@ if (BUILD_SOX)
list(APPEND TORCHAUDIO_THIRD_PARTIES libsox) list(APPEND TORCHAUDIO_THIRD_PARTIES libsox)
endif() endif()
################################################################################
# ffmpeg
################################################################################
if (BUILD_FFMPEG)
set(FFMPEG_FIND_COMPONENTS avdevice avfilter avformat avcodec avutil)
include(FindFFMPEG)
add_library(ffmpeg INTERFACE)
target_include_directories(ffmpeg INTERFACE ${FFMPEG_INCLUDE_DIRS})
target_link_libraries(ffmpeg INTERFACE ${FFMPEG_LIBRARIES})
endif()
################################################################################ ################################################################################
# kaldi # kaldi
################################################################################ ################################################################################
......
...@@ -178,12 +178,13 @@ if(BUILD_FFMPEG) ...@@ -178,12 +178,13 @@ if(BUILD_FFMPEG)
ffmpeg/stream_processor.cpp ffmpeg/stream_processor.cpp
ffmpeg/streamer.cpp ffmpeg/streamer.cpp
) )
define_library( find_package(FFMPEG 4.1 REQUIRED COMPONENTS avdevice avfilter avformat avcodec avutil)
libtorchaudio_ffmpeg define_library(
"${LIBTORCHAUDIO_FFMPEG_SOURCES}" libtorchaudio_ffmpeg
"${LIBTORCHAUDIO_INCLUDE_DIRS}" "${LIBTORCHAUDIO_FFMPEG_SOURCES}"
"torch;ffmpeg" "${LIBTORCHAUDIO_INCLUDE_DIRS};${FFMPEG_INCLUDE_DIRS}"
"${LIBTORCHAUDIO_COMPILE_DEFINITIONS}" "torch;${FFMPEG_LIBRARIES}"
"${LIBTORCHAUDIO_COMPILE_DEFINITIONS}"
) )
endif() endif()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment