Skip to content

Commit 505780b

Browse files
committed
Use pre-built binaries for ffmpeg extension
1 parent d9f51ce commit 505780b

File tree

5 files changed

+93
-272
lines changed

5 files changed

+93
-272
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ if (BUILD_SOX)
171171
add_subdirectory(torchaudio/csrc/sox)
172172
endif()
173173
if (USE_FFMPEG)
174+
add_subdirectory(third_party/ffmpeg)
174175
add_subdirectory(torchaudio/csrc/ffmpeg)
175176
endif()
176177
if (BUILD_CUDA_CTC_DECODER)

cmake/FindFFMPEG.cmake

Lines changed: 0 additions & 264 deletions
This file was deleted.

third_party/ffmpeg/CMakeLists.txt

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
################################################################################
2+
# This file defines the following FFmpeg libraries using pre-built binaries.
3+
4+
add_library(ffmpeg4 INTERFACE)
5+
add_library(ffmpeg ALIAS ffmpeg4)
6+
7+
################################################################################
8+
9+
include(FetchContent)
10+
11+
set(base_url https://pytorch.s3.amazonaws.com/torchaudio/ffmpeg)
12+
13+
if (APPLE)
14+
if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
15+
FetchContent_Declare(
16+
f4
17+
URL ${base_url}/2023-07-06/macos_arm64/4.1.8.tar.gz
18+
URL_HASH SHA256=a44b8152b7f204ce5050fc7f6fd2bbbafe7ae4e45f03e135f3b45dd9a08f404e
19+
)
20+
elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
21+
FetchContent_Declare(
22+
f4
23+
URL ${base_url}/2023-07-06/macos_x86_64/4.1.8.tar.gz
24+
URL_HASH SHA256=392d5af0b24535bfc69d6244e7595e5f07117b93d94505d0a4b34c82ae479f48
25+
)
26+
else ()
27+
message(
28+
FATAL_ERROR
29+
"CPU architecture ${CMAKE_SYSTEM_PROCESSOR} is not currently supported. If you do not need FFmpeg integration, then setting USE_FFMPEG=0 will bypass the issue.")
30+
endif()
31+
elseif (UNIX)
32+
if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
33+
FetchContent_Declare(
34+
f4
35+
URL ${base_url}/2023-07-06/linux_aarch64/4.1.8.tar.gz
36+
URL_HASH SHA256=aae0b713040e30ceebe0d0bc82353d3d9054055c7af8a4f4abc1766015ab7681
37+
)
38+
elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
39+
FetchContent_Declare(
40+
f4
41+
URL ${base_url}/2023-07-06/linux_x86_64/4.1.8.tar.gz
42+
URL_HASH SHA256=52e53b8857739bdd54f9d8541e22569b57f6c6f16504ee83963c2ed3e7061a23
43+
)
44+
else ()
45+
# Possible case ppc64le (though it's not officially supported.)
46+
message(
47+
FATAL_ERROR
48+
"CPU architecture ${CMAKE_SYSTEM_PROCESSOR} is not currently supported. If you do not need FFmpeg integration, then setting USE_FFMPEG=0 will bypass the issue.")
49+
endif()
50+
elseif(MSVC)
51+
FetchContent_Declare(
52+
f4
53+
URL ${base_url}/2023-07-06/windows/4.1.8.tar.gz
54+
URL_HASH SHA256=c45cd36e0575490f97ace07365bb67c5e1cbe9f3e6a4272d035c19348df96790
55+
)
56+
endif()
57+
58+
FetchContent_MakeAvailable(f4)
59+
target_include_directories(ffmpeg4 INTERFACE ${f4_SOURCE_DIR}/include)
60+
61+
if(APPLE)
62+
target_link_libraries(
63+
ffmpeg4
64+
INTERFACE
65+
${f4_SOURCE_DIR}/lib/libavutil.56.dylib
66+
${f4_SOURCE_DIR}/lib/libavcodec.58.dylib
67+
${f4_SOURCE_DIR}/lib/libavformat.58.dylib
68+
${f4_SOURCE_DIR}/lib/libavdevice.58.dylib
69+
${f4_SOURCE_DIR}/lib/libavfilter.7.dylib
70+
)
71+
elseif (UNIX)
72+
target_link_libraries(
73+
ffmpeg4
74+
INTERFACE
75+
${f4_SOURCE_DIR}/lib/libavutil.so.56
76+
${f4_SOURCE_DIR}/lib/libavcodec.so.58
77+
${f4_SOURCE_DIR}/lib/libavformat.so.58
78+
${f4_SOURCE_DIR}/lib/libavdevice.so.58
79+
${f4_SOURCE_DIR}/lib/libavfilter.so.7
80+
)
81+
elseif(MSVC)
82+
target_link_libraries(
83+
ffmpeg4
84+
INTERFACE
85+
${f4_SOURCE_DIR}/bin/avutil.lib
86+
${f4_SOURCE_DIR}/bin/avcodec.lib
87+
${f4_SOURCE_DIR}/bin/avformat.lib
88+
${f4_SOURCE_DIR}/bin/avdevice.lib
89+
${f4_SOURCE_DIR}/bin/avfilter.lib
90+
)
91+
endif()

tools/setup_helpers/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _get_build(var, default=False):
3636
_BUILD_SOX = False if platform.system() == "Windows" else _get_build("BUILD_SOX", True)
3737
_BUILD_RIR = _get_build("BUILD_RIR", True)
3838
_BUILD_RNNT = _get_build("BUILD_RNNT", True)
39-
_USE_FFMPEG = _get_build("USE_FFMPEG", False)
39+
_USE_FFMPEG = _get_build("USE_FFMPEG", True)
4040
_USE_ROCM = _get_build("USE_ROCM", torch.backends.cuda.is_built() and torch.version.hip is not None)
4141
_USE_CUDA = _get_build("USE_CUDA", torch.backends.cuda.is_built() and torch.version.hip is None)
4242
_BUILD_ALIGN = _get_build("BUILD_ALIGN", True)

torchaudio/csrc/ffmpeg/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
message(STATUS "FFMPEG_ROOT=$ENV{FFMPEG_ROOT}")
2-
find_package(FFMPEG 4.1 REQUIRED COMPONENTS avdevice avfilter avformat avcodec avutil)
3-
add_library(ffmpeg INTERFACE)
4-
target_include_directories(ffmpeg INTERFACE "${FFMPEG_INCLUDE_DIRS}")
5-
target_link_libraries(ffmpeg INTERFACE "${FFMPEG_LIBRARIES}")
6-
7-
81
set(
92
sources
103
ffmpeg.cpp

0 commit comments

Comments
 (0)