Skip to content

Commit 5c4cdcc

Browse files
committed
Use pre-built binaries for ffmpeg extension
1 parent d9f51ce commit 5c4cdcc

File tree

5 files changed

+84
-272
lines changed

5 files changed

+84
-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: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
else()
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+
endif()
27+
elseif (UNIX)
28+
if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
29+
FetchContent_Declare(
30+
f4
31+
URL ${base_url}/2023-07-06/linux_aarch64/4.1.8.tar.gz
32+
URL_HASH SHA256=aae0b713040e30ceebe0d0bc82353d3d9054055c7af8a4f4abc1766015ab7681
33+
)
34+
else ()
35+
FetchContent_Declare(
36+
f4
37+
URL ${base_url}/2023-07-06/linux_x86_64/4.1.8.tar.gz
38+
URL_HASH SHA256=52e53b8857739bdd54f9d8541e22569b57f6c6f16504ee83963c2ed3e7061a23
39+
)
40+
endif()
41+
elseif(MSVC)
42+
FetchContent_Declare(
43+
f4
44+
URL ${base_url}/2023-07-06/windows/4.1.8.tar.gz
45+
URL_HASH SHA256=ddf2185b2938149179063172b8d0da4f3ba5f545c29568e913e7f2aa623011fe
46+
)
47+
endif()
48+
49+
FetchContent_MakeAvailable(f4)
50+
target_include_directories(ffmpeg4 INTERFACE ${f4_SOURCE_DIR}/include)
51+
52+
if(APPLE)
53+
target_link_libraries(
54+
ffmpeg4
55+
INTERFACE
56+
${f4_SOURCE_DIR}/lib/libavutil.56.dylib
57+
${f4_SOURCE_DIR}/lib/libavcodec.58.dylib
58+
${f4_SOURCE_DIR}/lib/libavformat.58.dylib
59+
${f4_SOURCE_DIR}/lib/libavdevice.58.dylib
60+
${f4_SOURCE_DIR}/lib/libavfilter.7.dylib
61+
)
62+
elseif (UNIX)
63+
target_link_libraries(
64+
ffmpeg4
65+
INTERFACE
66+
${f4_SOURCE_DIR}/lib/libavutil.so.56
67+
${f4_SOURCE_DIR}/lib/libavcodec.so.58
68+
${f4_SOURCE_DIR}/lib/libavformat.so.58
69+
${f4_SOURCE_DIR}/lib/libavdevice.so.58
70+
${f4_SOURCE_DIR}/lib/libavfilter.so.7
71+
)
72+
elseif(MSVC)
73+
target_link_libraries(
74+
ffmpeg4
75+
INTERFACE
76+
${f4_SOURCE_DIR}/bin/avutil.lib
77+
${f4_SOURCE_DIR}/bin/avcodec.lib
78+
${f4_SOURCE_DIR}/bin/avformat.lib
79+
${f4_SOURCE_DIR}/bin/avdevice.lib
80+
${f4_SOURCE_DIR}/bin/avfilter.lib
81+
)
82+
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)