torchcodec 1.0.0__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- torchcodec/__init__.py +50 -0
- torchcodec/_core/AVIOContextHolder.cpp +85 -0
- torchcodec/_core/AVIOContextHolder.h +44 -0
- torchcodec/_core/AudioCommon.cpp +101 -0
- torchcodec/_core/AudioCommon.h +48 -0
- torchcodec/_core/AudioConverter.cpp +130 -0
- torchcodec/_core/AudioConverter.h +59 -0
- torchcodec/_core/BetaCudaDeviceInterface.cpp +1635 -0
- torchcodec/_core/BetaCudaDeviceInterface.h +364 -0
- torchcodec/_core/CMakeLists.txt +661 -0
- torchcodec/_core/CUDACommon.cpp +129 -0
- torchcodec/_core/CUDACommon.h +115 -0
- torchcodec/_core/Cache.h +126 -0
- torchcodec/_core/CodecParameters.cpp +98 -0
- torchcodec/_core/CodecParameters.h +59 -0
- torchcodec/_core/ColorConverter.cpp +92 -0
- torchcodec/_core/ColorConverter.h +40 -0
- torchcodec/_core/CpuDeviceInterface.cpp +654 -0
- torchcodec/_core/CpuDeviceInterface.h +153 -0
- torchcodec/_core/CudaDeviceInterface.cpp +519 -0
- torchcodec/_core/CudaDeviceInterface.h +92 -0
- torchcodec/_core/DecodeAvif.cpp +284 -0
- torchcodec/_core/DecodeAvif.h +28 -0
- torchcodec/_core/DecodeGif.cpp +488 -0
- torchcodec/_core/DecodeGif.h +32 -0
- torchcodec/_core/DecodeHeic.cpp +306 -0
- torchcodec/_core/DecodeHeic.h +18 -0
- torchcodec/_core/DecodeJpeg.cpp +489 -0
- torchcodec/_core/DecodeJpeg.h +17 -0
- torchcodec/_core/DecodeJpegCuda.cpp +638 -0
- torchcodec/_core/DecodeJpegCuda.h +92 -0
- torchcodec/_core/DecodePng.cpp +569 -0
- torchcodec/_core/DecodePng.h +31 -0
- torchcodec/_core/DecodeWebp.cpp +238 -0
- torchcodec/_core/DecodeWebp.h +17 -0
- torchcodec/_core/Demuxer.cpp +415 -0
- torchcodec/_core/Demuxer.h +158 -0
- torchcodec/_core/DeviceInterface.cpp +152 -0
- torchcodec/_core/DeviceInterface.h +255 -0
- torchcodec/_core/EncodeJpeg.cpp +223 -0
- torchcodec/_core/EncodeJpeg.h +19 -0
- torchcodec/_core/EncodeJpegCuda.cpp +272 -0
- torchcodec/_core/EncodeJpegCuda.h +56 -0
- torchcodec/_core/EncodePng.cpp +207 -0
- torchcodec/_core/EncodePng.h +19 -0
- torchcodec/_core/Encoder.cpp +1023 -0
- torchcodec/_core/Encoder.h +144 -0
- torchcodec/_core/Exif.h +241 -0
- torchcodec/_core/FFMPEGCommon.cpp +1159 -0
- torchcodec/_core/FFMPEGCommon.h +506 -0
- torchcodec/_core/FileIO.cpp +78 -0
- torchcodec/_core/FileIO.h +34 -0
- torchcodec/_core/FileLikeIO.cpp +76 -0
- torchcodec/_core/FileLikeIO.h +68 -0
- torchcodec/_core/FilterGraph.cpp +211 -0
- torchcodec/_core/FilterGraph.h +59 -0
- torchcodec/_core/Frame.cpp +75 -0
- torchcodec/_core/Frame.h +76 -0
- torchcodec/_core/IOInterface.h +44 -0
- torchcodec/_core/ImageCommon.h +113 -0
- torchcodec/_core/Logging.cpp +42 -0
- torchcodec/_core/Logging.h +38 -0
- torchcodec/_core/Metadata.cpp +312 -0
- torchcodec/_core/Metadata.h +115 -0
- torchcodec/_core/NVCUVIDRuntimeLoader.cpp +324 -0
- torchcodec/_core/NVCUVIDRuntimeLoader.h +14 -0
- torchcodec/_core/NVDECCache.cpp +111 -0
- torchcodec/_core/NVDECCache.h +136 -0
- torchcodec/_core/NVDECCacheConfig.cpp +61 -0
- torchcodec/_core/NVDECCacheConfig.h +30 -0
- torchcodec/_core/PacketDecoder.cpp +358 -0
- torchcodec/_core/PacketDecoder.h +140 -0
- torchcodec/_core/SingleStreamDecoder.cpp +1856 -0
- torchcodec/_core/SingleStreamDecoder.h +424 -0
- torchcodec/_core/StableABICompat.h +213 -0
- torchcodec/_core/StreamOptions.h +93 -0
- torchcodec/_core/SwScale.cpp +124 -0
- torchcodec/_core/SwScale.h +67 -0
- torchcodec/_core/TensorIO.cpp +136 -0
- torchcodec/_core/TensorIO.h +53 -0
- torchcodec/_core/Transform.cpp +207 -0
- torchcodec/_core/Transform.h +125 -0
- torchcodec/_core/ValidationUtils.cpp +65 -0
- torchcodec/_core/ValidationUtils.h +29 -0
- torchcodec/_core/WavDecoder.cpp +494 -0
- torchcodec/_core/WavDecoder.h +73 -0
- torchcodec/_core/__init__.py +45 -0
- torchcodec/_core/_decoder_utils.py +258 -0
- torchcodec/_core/_ffmpeg_op_names.py +95 -0
- torchcodec/_core/_ffmpeg_ops.py +699 -0
- torchcodec/_core/_file_like.py +221 -0
- torchcodec/_core/_metadata.py +402 -0
- torchcodec/_core/color_conversion.cpp +316 -0
- torchcodec/_core/color_conversion.cu +391 -0
- torchcodec/_core/color_conversion.h +150 -0
- torchcodec/_core/custom_ops.cpp +2438 -0
- torchcodec/_core/fetch_and_expose_non_gpl_ffmpeg_libs.cmake +192 -0
- torchcodec/_core/fetch_avif_from_s3.cmake +81 -0
- torchcodec/_core/giflib/README +28 -0
- torchcodec/_core/giflib/dgif_lib.c +1313 -0
- torchcodec/_core/giflib/gif_hash.c +129 -0
- torchcodec/_core/giflib/gif_hash.h +43 -0
- torchcodec/_core/giflib/gif_lib.h +292 -0
- torchcodec/_core/giflib/gif_lib_private.h +73 -0
- torchcodec/_core/giflib/gifalloc.c +426 -0
- torchcodec/_core/giflib/openbsd-reallocarray.c +74 -0
- torchcodec/_core/heic_custom_ops.cpp +20 -0
- torchcodec/_core/image_custom_ops.cpp +137 -0
- torchcodec/_core/nvcuvid_include/cuviddec.h +1374 -0
- torchcodec/_core/nvcuvid_include/nvcuvid.h +610 -0
- torchcodec/_core/ops.py +103 -0
- torchcodec/_core/sources.bzl +113 -0
- torchcodec/_frame.py +146 -0
- torchcodec/_internally_replaced_utils.py +129 -0
- torchcodec/_logging.py +59 -0
- torchcodec/decoders/__init__.py +50 -0
- torchcodec/decoders/_audio_decoder.py +183 -0
- torchcodec/decoders/_blocks/__init__.py +48 -0
- torchcodec/decoders/_blocks/_audio_converter.py +155 -0
- torchcodec/decoders/_blocks/_codec_parameters.py +229 -0
- torchcodec/decoders/_blocks/_color_converter.py +107 -0
- torchcodec/decoders/_blocks/_demuxer.py +678 -0
- torchcodec/decoders/_blocks/_frame.py +577 -0
- torchcodec/decoders/_blocks/_helpers.py +53 -0
- torchcodec/decoders/_blocks/_packet_decoder.py +357 -0
- torchcodec/decoders/_decoder_utils.py +128 -0
- torchcodec/decoders/_image_decoders.py +1575 -0
- torchcodec/decoders/_video_decoder.py +592 -0
- torchcodec/decoders/_wav_decoder.py +131 -0
- torchcodec/encoders/__init__.py +4 -0
- torchcodec/encoders/_audio_encoder.py +167 -0
- torchcodec/encoders/_image_encoders.py +181 -0
- torchcodec/encoders/_multi_stream_encoder.py +272 -0
- torchcodec/encoders/_video_encoder.py +227 -0
- torchcodec/jpeg8.dll +0 -0
- torchcodec/libavif.dll +0 -0
- torchcodec/libpng16.dll +0 -0
- torchcodec/libsharpyuv.dll +0 -0
- torchcodec/libtorchcodec_core4.dll +0 -0
- torchcodec/libtorchcodec_core5.dll +0 -0
- torchcodec/libtorchcodec_core6.dll +0 -0
- torchcodec/libtorchcodec_core7.dll +0 -0
- torchcodec/libtorchcodec_core8.dll +0 -0
- torchcodec/libtorchcodec_core9.dll +0 -0
- torchcodec/libtorchcodec_custom_ops4.dll +0 -0
- torchcodec/libtorchcodec_custom_ops5.dll +0 -0
- torchcodec/libtorchcodec_custom_ops6.dll +0 -0
- torchcodec/libtorchcodec_custom_ops7.dll +0 -0
- torchcodec/libtorchcodec_custom_ops8.dll +0 -0
- torchcodec/libtorchcodec_custom_ops9.dll +0 -0
- torchcodec/libtorchcodec_heic.dll +0 -0
- torchcodec/libtorchcodec_image.dll +0 -0
- torchcodec/libwebp.dll +0 -0
- torchcodec/libwebpdecoder.dll +0 -0
- torchcodec/libwebpdemux.dll +0 -0
- torchcodec/libwebpmux.dll +0 -0
- torchcodec/libzstd.dll +0 -0
- torchcodec/py.typed +0 -0
- torchcodec/samplers/__init__.py +2 -0
- torchcodec/samplers/_common.py +83 -0
- torchcodec/samplers/_index_based.py +287 -0
- torchcodec/samplers/_time_based.py +360 -0
- torchcodec/share/cmake/TorchCodec/TorchCodecConfig.cmake +76 -0
- torchcodec/share/cmake/TorchCodec/ffmpeg_versions.cmake +128 -0
- torchcodec/transforms/__init__.py +12 -0
- torchcodec/transforms/_decoder_transforms.py +375 -0
- torchcodec/version.py +1 -0
- torchcodec/zlib.dll +0 -0
- torchcodec-1.0.0.dist-info/METADATA +275 -0
- torchcodec-1.0.0.dist-info/RECORD +179 -0
- torchcodec-1.0.0.dist-info/WHEEL +5 -0
- torchcodec-1.0.0.dist-info/licenses/LICENSE +28 -0
- torchcodec-1.0.0.dist-info/licenses/third_party/COPYING.dav1d +23 -0
- torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libavif +387 -0
- torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libjpeg-turbo +135 -0
- torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libpng +134 -0
- torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libwebp +30 -0
- torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libyuv +29 -0
- torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.zlib +22 -0
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.18)
|
|
2
|
+
project(TorchCodec)
|
|
3
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
4
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
5
|
+
|
|
6
|
+
# Guard against accidentally building a distributable wheel that dynamically
|
|
7
|
+
# links against a GPL build of FFmpeg (e.g. from conda/system), which would be a
|
|
8
|
+
# license violation. Wheels are expected to link against our pre-built non-GPL
|
|
9
|
+
# FFmpeg (BUILD_AGAINST_ALL_FFMPEG_FROM_S3).
|
|
10
|
+
if(SKBUILD_STATE STREQUAL "wheel"
|
|
11
|
+
AND NOT DEFINED ENV{BUILD_AGAINST_ALL_FFMPEG_FROM_S3}
|
|
12
|
+
AND NOT DEFINED ENV{I_CONFIRM_THIS_IS_NOT_A_LICENSE_VIOLATION})
|
|
13
|
+
message(FATAL_ERROR
|
|
14
|
+
"It looks like you're trying to build a wheel. You probably want to set "
|
|
15
|
+
"BUILD_AGAINST_ALL_FFMPEG_FROM_S3. If you have a good reason *not* to, "
|
|
16
|
+
"then set I_CONFIRM_THIS_IS_NOT_A_LICENSE_VIOLATION.")
|
|
17
|
+
endif()
|
|
18
|
+
|
|
19
|
+
find_package(Torch REQUIRED)
|
|
20
|
+
find_package(Python3 COMPONENTS Interpreter)
|
|
21
|
+
|
|
22
|
+
if(APPLE)
|
|
23
|
+
# Some CI runners ship a Mono.framework which contains headers for libjpeg,
|
|
24
|
+
# libpng, etc. We do not want those headers to be found - they're old and
|
|
25
|
+
# incompatible with what we do here (e.g. missing eXIf support in libpng).
|
|
26
|
+
# On the CI we want the conda-forge-provided libraries to be found first. So
|
|
27
|
+
# we tell CMake to search for 'frameworks' last.
|
|
28
|
+
set(CMAKE_FIND_FRAMEWORK LAST)
|
|
29
|
+
endif()
|
|
30
|
+
|
|
31
|
+
# Image decoder build toggles. By default all image decoders are built and
|
|
32
|
+
# *required*: if a codec's lib can't be found/fetched the build fails loudly,
|
|
33
|
+
# telling the user how to opt out. This is controlled by:
|
|
34
|
+
# - TORCHCODEC_BUILD_IMAGE (catch-all, default ON)
|
|
35
|
+
# - TORCHCODEC_BUILD_{JPEG,PNG,WEBP,AVIF,GIF} (default AUTO = inherit catch-all)
|
|
36
|
+
# A codec set to OFF is not built; its decode_*() then raises an actionable error
|
|
37
|
+
# at call time (see e.g. DecodeJpeg.cpp's !TORCHCODEC_ENABLE_JPEG stub), while importing
|
|
38
|
+
# torchcodec still works. We default the flags here too so that direct `cmake`
|
|
39
|
+
# invocations (e.g. the C++ tests build) behave like the scikit-build path,
|
|
40
|
+
# which passes them via pyproject.toml.
|
|
41
|
+
if(NOT DEFINED TORCHCODEC_BUILD_IMAGE)
|
|
42
|
+
set(TORCHCODEC_BUILD_IMAGE "ON")
|
|
43
|
+
endif()
|
|
44
|
+
foreach(_codec JPEG PNG WEBP AVIF GIF HEIC NVJPEG)
|
|
45
|
+
if(NOT DEFINED TORCHCODEC_BUILD_${_codec})
|
|
46
|
+
set(TORCHCODEC_BUILD_${_codec} "AUTO")
|
|
47
|
+
endif()
|
|
48
|
+
endforeach()
|
|
49
|
+
|
|
50
|
+
# Returns true (via out_want) if TORCHCODEC_BUILD_IMAGE is on, or if that
|
|
51
|
+
# specific codec flag is explicitly on, and false otherwise.
|
|
52
|
+
function(resolve_image_codec codec_flag out_want)
|
|
53
|
+
if(codec_flag STREQUAL "AUTO")
|
|
54
|
+
set(_resolved "${TORCHCODEC_BUILD_IMAGE}")
|
|
55
|
+
else()
|
|
56
|
+
set(_resolved "${codec_flag}")
|
|
57
|
+
endif()
|
|
58
|
+
if(_resolved)
|
|
59
|
+
set(${out_want} TRUE PARENT_SCOPE)
|
|
60
|
+
else()
|
|
61
|
+
set(${out_want} FALSE PARENT_SCOPE)
|
|
62
|
+
endif()
|
|
63
|
+
endfunction()
|
|
64
|
+
|
|
65
|
+
function(discover_image_codecs)
|
|
66
|
+
resolve_image_codec("${TORCHCODEC_BUILD_JPEG}" want_jpeg)
|
|
67
|
+
if(want_jpeg)
|
|
68
|
+
if(NOT DEFINED JPEG_ROOT AND DEFINED ENV{CONDA_PREFIX})
|
|
69
|
+
# JPEG_ROOT will automatically be passed to find_package(JPEG) by CMake
|
|
70
|
+
# if it is set. We fallback to the conda prefix if it is not set.
|
|
71
|
+
if(WIN32)
|
|
72
|
+
set(JPEG_ROOT "$ENV{CONDA_PREFIX}/Library")
|
|
73
|
+
else()
|
|
74
|
+
set(JPEG_ROOT "$ENV{CONDA_PREFIX}")
|
|
75
|
+
endif()
|
|
76
|
+
endif()
|
|
77
|
+
find_package(JPEG) # Not REQUIRED: we emit our own actionable error below.
|
|
78
|
+
if(JPEG_FOUND)
|
|
79
|
+
message(STATUS "libjpeg found: building torchcodec with JPEG image decoding support.")
|
|
80
|
+
else()
|
|
81
|
+
message(FATAL_ERROR
|
|
82
|
+
"libjpeg not found, but JPEG image decoding is enabled. Install "
|
|
83
|
+
"libjpeg[-turbo] and its development headers, or set "
|
|
84
|
+
"TORCHCODEC_BUILD_JPEG=0 to build without JPEG support (decode_jpeg "
|
|
85
|
+
"will raise at runtime), or TORCHCODEC_BUILD_IMAGE=0 to disable all "
|
|
86
|
+
"image decoders.")
|
|
87
|
+
endif()
|
|
88
|
+
else()
|
|
89
|
+
message(STATUS "Not building torchcodec with JPEG image decoding support (disabled via TORCHCODEC_BUILD_JPEG/TORCHCODEC_BUILD_IMAGE): decode_jpeg will raise at runtime.")
|
|
90
|
+
endif()
|
|
91
|
+
|
|
92
|
+
resolve_image_codec("${TORCHCODEC_BUILD_PNG}" want_png)
|
|
93
|
+
if(want_png)
|
|
94
|
+
if(NOT DEFINED PNG_ROOT AND DEFINED ENV{CONDA_PREFIX})
|
|
95
|
+
if(WIN32)
|
|
96
|
+
set(PNG_ROOT "$ENV{CONDA_PREFIX}/Library")
|
|
97
|
+
else()
|
|
98
|
+
set(PNG_ROOT "$ENV{CONDA_PREFIX}")
|
|
99
|
+
endif()
|
|
100
|
+
endif()
|
|
101
|
+
find_package(PNG) # Transitively pulls in ZLIB.
|
|
102
|
+
if(PNG_FOUND)
|
|
103
|
+
message(STATUS "libpng found: building torchcodec with PNG image decoding support.")
|
|
104
|
+
else()
|
|
105
|
+
message(FATAL_ERROR
|
|
106
|
+
"libpng not found, but PNG image decoding is enabled. Install libpng "
|
|
107
|
+
"and its development headers, or set TORCHCODEC_BUILD_PNG=0 to build "
|
|
108
|
+
"without PNG support (decode_png will raise at runtime), or "
|
|
109
|
+
"TORCHCODEC_BUILD_IMAGE=0 to disable all image decoders.")
|
|
110
|
+
endif()
|
|
111
|
+
else()
|
|
112
|
+
message(STATUS "Not building torchcodec with PNG image decoding support (disabled via TORCHCODEC_BUILD_PNG/TORCHCODEC_BUILD_IMAGE): decode_png will raise at runtime.")
|
|
113
|
+
endif()
|
|
114
|
+
|
|
115
|
+
resolve_image_codec("${TORCHCODEC_BUILD_WEBP}" want_webp)
|
|
116
|
+
if(want_webp)
|
|
117
|
+
if(NOT DEFINED WebP_ROOT AND DEFINED ENV{CONDA_PREFIX})
|
|
118
|
+
if(WIN32)
|
|
119
|
+
set(WebP_ROOT "$ENV{CONDA_PREFIX}/Library")
|
|
120
|
+
else()
|
|
121
|
+
set(WebP_ROOT "$ENV{CONDA_PREFIX}")
|
|
122
|
+
endif()
|
|
123
|
+
endif()
|
|
124
|
+
find_package(WebP) # Provides the WebP::webp and WebP::webpdemux targets.
|
|
125
|
+
if(WebP_FOUND)
|
|
126
|
+
message(STATUS "libwebp found: building torchcodec with WebP image decoding support.")
|
|
127
|
+
else()
|
|
128
|
+
message(FATAL_ERROR
|
|
129
|
+
"libwebp not found, but WebP image decoding is enabled. Install "
|
|
130
|
+
"libwebp and its development headers, or set TORCHCODEC_BUILD_WEBP=0 "
|
|
131
|
+
"to build without WebP support (decode_webp will raise at runtime), "
|
|
132
|
+
"or TORCHCODEC_BUILD_IMAGE=0 to disable all image decoders.")
|
|
133
|
+
endif()
|
|
134
|
+
else()
|
|
135
|
+
message(STATUS "Not building torchcodec with WebP image decoding support (disabled via TORCHCODEC_BUILD_WEBP/TORCHCODEC_BUILD_IMAGE): decode_webp will raise at runtime.")
|
|
136
|
+
endif()
|
|
137
|
+
|
|
138
|
+
resolve_image_codec("${TORCHCODEC_BUILD_AVIF}" want_avif)
|
|
139
|
+
if(want_avif)
|
|
140
|
+
include(${CMAKE_CURRENT_SOURCE_DIR}/fetch_avif_from_s3.cmake)
|
|
141
|
+
set(libavif_FOUND TRUE)
|
|
142
|
+
message(STATUS "Building torchcodec with AVIF image decoding support (libavif from S3).")
|
|
143
|
+
else()
|
|
144
|
+
message(STATUS "Not building torchcodec with AVIF image decoding support (disabled via TORCHCODEC_BUILD_AVIF/TORCHCODEC_BUILD_IMAGE): decode_avif will raise at runtime.")
|
|
145
|
+
endif()
|
|
146
|
+
|
|
147
|
+
resolve_image_codec("${TORCHCODEC_BUILD_GIF}" want_gif)
|
|
148
|
+
if(want_gif)
|
|
149
|
+
message(STATUS "Building torchcodec with GIF image decoding support (vendored giflib).")
|
|
150
|
+
else()
|
|
151
|
+
message(STATUS "Not building torchcodec with GIF image decoding support (disabled via TORCHCODEC_BUILD_GIF/TORCHCODEC_BUILD_IMAGE): decode_gif will raise at runtime.")
|
|
152
|
+
endif()
|
|
153
|
+
|
|
154
|
+
# Re-export the resolved want_<codec> booleans and (for Windows) the avif
|
|
155
|
+
# runtime lib path to make_torchcodec_image_library, our caller.
|
|
156
|
+
foreach(_codec jpeg png webp avif gif)
|
|
157
|
+
set(want_${_codec} "${want_${_codec}}" PARENT_SCOPE)
|
|
158
|
+
endforeach()
|
|
159
|
+
set(avif_runtime_lib "${avif_runtime_lib}" PARENT_SCOPE)
|
|
160
|
+
endfunction()
|
|
161
|
+
|
|
162
|
+
# Read a list variable from sources.bzl, the single source of truth for the
|
|
163
|
+
# _core C++ source files shared with the internal Buck build. The .bzl file is
|
|
164
|
+
# valid Python, so we exec it and print the requested list; configure_file
|
|
165
|
+
# registers it as a dependency so re-running CMake picks up edits.
|
|
166
|
+
configure_file(
|
|
167
|
+
${CMAKE_CURRENT_SOURCE_DIR}/sources.bzl
|
|
168
|
+
${CMAKE_CURRENT_BINARY_DIR}/sources.bzl
|
|
169
|
+
COPYONLY)
|
|
170
|
+
|
|
171
|
+
function(read_sources_from_bzl output_var list_name)
|
|
172
|
+
execute_process(
|
|
173
|
+
COMMAND "${Python3_EXECUTABLE}" -c
|
|
174
|
+
"exec(open('${CMAKE_CURRENT_SOURCE_DIR}/sources.bzl').read()); print(';'.join(${list_name}))"
|
|
175
|
+
OUTPUT_VARIABLE _sources
|
|
176
|
+
RESULT_VARIABLE _retval
|
|
177
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
178
|
+
if(NOT _retval EQUAL 0)
|
|
179
|
+
message(FATAL_ERROR "Failed to read '${list_name}' from sources.bzl")
|
|
180
|
+
endif()
|
|
181
|
+
set(${output_var} ${_sources} PARENT_SCOPE)
|
|
182
|
+
endfunction()
|
|
183
|
+
|
|
184
|
+
read_sources_from_bzl(TORCHCODEC_DECODER_CORE_SOURCES decoder_core_sources)
|
|
185
|
+
read_sources_from_bzl(TORCHCODEC_FFMPEG_COMMON_SOURCES ffmpeg_common_sources)
|
|
186
|
+
read_sources_from_bzl(TORCHCODEC_IO_SOURCES io_sources)
|
|
187
|
+
read_sources_from_bzl(TORCHCODEC_DECODER_CORE_CUDA_SOURCES decoder_core_cuda_sources)
|
|
188
|
+
read_sources_from_bzl(TORCHCODEC_FILE_LIKE_CONTEXT_SOURCES file_like_context_sources)
|
|
189
|
+
read_sources_from_bzl(TORCHCODEC_CUSTOM_OPS_SOURCES custom_ops_sources)
|
|
190
|
+
read_sources_from_bzl(TORCHCODEC_IMAGE_SOURCES image_sources)
|
|
191
|
+
read_sources_from_bzl(TORCHCODEC_IMAGE_OPS_SOURCES image_ops_sources)
|
|
192
|
+
read_sources_from_bzl(TORCHCODEC_GIFLIB_SOURCES giflib_sources)
|
|
193
|
+
read_sources_from_bzl(TORCHCODEC_HEIC_SOURCES heic_sources)
|
|
194
|
+
read_sources_from_bzl(TORCHCODEC_HEIC_OPS_SOURCES heic_ops_sources)
|
|
195
|
+
|
|
196
|
+
if(DEFINED TORCHCODEC_DISABLE_COMPILE_WARNING_AS_ERROR AND TORCHCODEC_DISABLE_COMPILE_WARNING_AS_ERROR)
|
|
197
|
+
set(TORCHCODEC_WERROR_OPTION "")
|
|
198
|
+
else()
|
|
199
|
+
if (WIN32)
|
|
200
|
+
# TODO set warnings as errors on Windows as well.
|
|
201
|
+
# set(TORCHCODEC_WERROR_OPTION "/WX")
|
|
202
|
+
else()
|
|
203
|
+
set(TORCHCODEC_WERROR_OPTION "-Werror")
|
|
204
|
+
endif()
|
|
205
|
+
endif()
|
|
206
|
+
|
|
207
|
+
if (WIN32)
|
|
208
|
+
# Avoid warnings about non-ASCII characters in source files.
|
|
209
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819")
|
|
210
|
+
# Required for Unicode support in fmt library (bundled with PyTorch).
|
|
211
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
|
|
212
|
+
# Important for when we add Windows CUDA: exporting all symbols is limited to
|
|
213
|
+
# 65535 symbols, which (apparently) will not work for CUDA.
|
|
214
|
+
# https://github.com/pytorch/pytorch/pull/3650
|
|
215
|
+
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
|
216
|
+
endif()
|
|
217
|
+
|
|
218
|
+
if (WIN32)
|
|
219
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 ${TORCHCODEC_WERROR_OPTION} ${TORCH_CXX_FLAGS}")
|
|
220
|
+
else()
|
|
221
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic ${TORCHCODEC_WERROR_OPTION} ${TORCH_CXX_FLAGS}")
|
|
222
|
+
endif()
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
function(make_torchcodec_sublibrary
|
|
226
|
+
library_name
|
|
227
|
+
type
|
|
228
|
+
sources
|
|
229
|
+
library_dependencies)
|
|
230
|
+
|
|
231
|
+
add_library(${library_name} ${type} ${sources})
|
|
232
|
+
set_target_properties(${library_name} PROPERTIES CXX_STANDARD 20)
|
|
233
|
+
target_include_directories(${library_name}
|
|
234
|
+
PRIVATE
|
|
235
|
+
./../../../
|
|
236
|
+
"${TORCH_INSTALL_PREFIX}/include"
|
|
237
|
+
)
|
|
238
|
+
# Use fmt library in header-only mode (bundled with PyTorch): the fmt
|
|
239
|
+
# library is bundled with PyTorch and the headers are available in
|
|
240
|
+
# TORCH_INSTALL_PREFIX/include/, which we add above. To be compatible with
|
|
241
|
+
# torch, we want to rely on the "header-only" mode of these headers and hit
|
|
242
|
+
# all the `#ifdef FMT_HEADER_ONLY` paths, so we define FMT_HEADER_ONLY here.```
|
|
243
|
+
target_compile_definitions(${library_name} PRIVATE FMT_HEADER_ONLY)
|
|
244
|
+
# TC is ABI-stable w.r.t. torch since torch 2.11
|
|
245
|
+
target_compile_definitions(${library_name} PRIVATE TORCH_TARGET_VERSION=0x020b000000000000)
|
|
246
|
+
|
|
247
|
+
# Avoid adding the "lib" prefix which we already add explicitly.
|
|
248
|
+
set_target_properties(${library_name} PROPERTIES PREFIX "")
|
|
249
|
+
|
|
250
|
+
# On macOS, for wheels, add Homebrew's FFmpeg library path to the rpath so
|
|
251
|
+
# that users with Homebrew-installed FFmpeg can use torchcodec without
|
|
252
|
+
# setting DYLD_LIBRARY_PATH. See
|
|
253
|
+
# https://github.com/pytorch/torchcodec/issues/570.
|
|
254
|
+
# That's the behavior we enable by default when building TorchCodec wheels
|
|
255
|
+
# which we'll ship on PyPI.
|
|
256
|
+
# Note that this means homebrew-FFmpeg will always take precedence over
|
|
257
|
+
# conda-FFmpeg. For this reason, this behavior can (and should!) be disabled
|
|
258
|
+
# when building TorchCodec for conda, by setting
|
|
259
|
+
# TORCHCODEC_DISABLE_HOMEBREW_RPATH.
|
|
260
|
+
# We should have the following behavior for users:
|
|
261
|
+
# - For TorchCodec installed from PyPI (pip or uv): Users don't have to use
|
|
262
|
+
# a conda env, and by default the homebrew-ffmpeg should be found. For
|
|
263
|
+
# users who do use a conda env, they should be able to use the
|
|
264
|
+
# conda-installed FFmpeg, but only if HomeBrew FFmpeg doesn't exist since
|
|
265
|
+
# homebrew will take precedence.
|
|
266
|
+
# - For TorchCodec installed from conda, users must install FFmpeg from
|
|
267
|
+
# conda as well (it should be a dependency of the TorchCodec conda
|
|
268
|
+
# package). Homebrew FFmpeg shouldn't be used.
|
|
269
|
+
if(APPLE AND NOT (DEFINED TORCHCODEC_DISABLE_HOMEBREW_RPATH AND TORCHCODEC_DISABLE_HOMEBREW_RPATH))
|
|
270
|
+
if(DEFINED ENV{HOMEBREW_PREFIX})
|
|
271
|
+
set(HOMEBREW_FFMPEG_LIB "$ENV{HOMEBREW_PREFIX}/opt/ffmpeg/lib")
|
|
272
|
+
else()
|
|
273
|
+
# Default Homebrew location on Apple Silicon
|
|
274
|
+
set(HOMEBREW_FFMPEG_LIB "/opt/homebrew/opt/ffmpeg/lib")
|
|
275
|
+
endif()
|
|
276
|
+
set_target_properties(${library_name} PROPERTIES
|
|
277
|
+
INSTALL_RPATH "${HOMEBREW_FFMPEG_LIB}"
|
|
278
|
+
)
|
|
279
|
+
endif()
|
|
280
|
+
|
|
281
|
+
target_link_libraries(
|
|
282
|
+
${library_name}
|
|
283
|
+
PUBLIC
|
|
284
|
+
${library_dependencies}
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
endfunction()
|
|
288
|
+
|
|
289
|
+
function(make_torchcodec_libraries
|
|
290
|
+
ffmpeg_major_version
|
|
291
|
+
ffmpeg_target)
|
|
292
|
+
|
|
293
|
+
# We create two shared libraries per version of FFmpeg, where the version
|
|
294
|
+
# is denoted by N:
|
|
295
|
+
#
|
|
296
|
+
# 1. libtorchcodec_coreN.{ext}: Base library which contains the
|
|
297
|
+
# implementation of VideoDecoder and everything VideoDecoder needs. On
|
|
298
|
+
# Linux, {ext} is so. On Mac, it is dylib. On Windows it's dll.
|
|
299
|
+
#
|
|
300
|
+
# 2. libtorchcodec_custom_opsN.{ext}: Implementation of the PyTorch custom
|
|
301
|
+
# ops. Depends on libtorchcodec_coreN.{ext}. On Linux, {ext} is so.
|
|
302
|
+
# On Mac, it is dylib. On Windows it's dll.
|
|
303
|
+
#
|
|
304
|
+
# None of our libraries use the CPython C API: they're all loaded through
|
|
305
|
+
# torch.ops.load_library, which is what lets us ship Python-agnostic
|
|
306
|
+
# (py3-none) wheels. Don't link against Python or pybind11.
|
|
307
|
+
|
|
308
|
+
# 1. Create libtorchcodec_coreN.{ext}.
|
|
309
|
+
set(core_library_name "libtorchcodec_core${ffmpeg_major_version}")
|
|
310
|
+
set(core_sources
|
|
311
|
+
${TORCHCODEC_DECODER_CORE_SOURCES}
|
|
312
|
+
${TORCHCODEC_FFMPEG_COMMON_SOURCES}
|
|
313
|
+
${TORCHCODEC_IO_SOURCES}
|
|
314
|
+
${TORCHCODEC_FILE_LIKE_CONTEXT_SOURCES}
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
if(ENABLE_CUDA)
|
|
318
|
+
enable_language(CUDA)
|
|
319
|
+
list(APPEND core_sources ${TORCHCODEC_DECODER_CORE_CUDA_SOURCES})
|
|
320
|
+
endif()
|
|
321
|
+
|
|
322
|
+
set(core_library_dependencies
|
|
323
|
+
${ffmpeg_target}
|
|
324
|
+
${TORCH_LIBRARIES}
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
make_torchcodec_sublibrary(
|
|
328
|
+
"${core_library_name}"
|
|
329
|
+
SHARED
|
|
330
|
+
"${core_sources}"
|
|
331
|
+
"${core_library_dependencies}"
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
if(ENABLE_CUDA)
|
|
335
|
+
# We define USE_CUDA to guard CUDA-specific code paths (e.g.
|
|
336
|
+
# NVDECCache usage in NVDECCacheConfig.cpp) and because some torch
|
|
337
|
+
# APIs like aoti_torch_get_current_cuda_stream are only exposed when
|
|
338
|
+
# USE_CUDA is defined.
|
|
339
|
+
# https://github.com/pytorch/pytorch/blob/98e36864e640023a716e058d894ea2d20e76e5f7/torch/csrc/inductor/aoti_torch/c/shim.h#L573-L602
|
|
340
|
+
target_compile_definitions(${core_library_name} PRIVATE USE_CUDA)
|
|
341
|
+
set_property(TARGET ${core_library_name} PROPERTY CUDA_STANDARD 17)
|
|
342
|
+
if(WIN32)
|
|
343
|
+
# CUDA 13.2+ CCCL headers require MSVC's standard-conforming
|
|
344
|
+
# preprocessor when compiling .cu files.
|
|
345
|
+
target_compile_options(${core_library_name} PRIVATE
|
|
346
|
+
$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=/Zc:preprocessor>)
|
|
347
|
+
endif()
|
|
348
|
+
endif()
|
|
349
|
+
|
|
350
|
+
# 2. Create libtorchcodec_custom_opsN.{ext}.
|
|
351
|
+
set(custom_ops_library_name "libtorchcodec_custom_ops${ffmpeg_major_version}")
|
|
352
|
+
set(custom_ops_sources
|
|
353
|
+
${TORCHCODEC_CUSTOM_OPS_SOURCES}
|
|
354
|
+
)
|
|
355
|
+
set(custom_ops_dependencies
|
|
356
|
+
${core_library_name}
|
|
357
|
+
)
|
|
358
|
+
make_torchcodec_sublibrary(
|
|
359
|
+
"${custom_ops_library_name}"
|
|
360
|
+
SHARED
|
|
361
|
+
"${custom_ops_sources}"
|
|
362
|
+
"${custom_ops_dependencies}"
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
# Only the torch op registration needs to be exported. Note that this is
|
|
366
|
+
# Linux only: on Mac hiding visibility can break dynamic casts across shared
|
|
367
|
+
# libraries because the type infos don't get exported.
|
|
368
|
+
if(LINUX)
|
|
369
|
+
target_compile_options(
|
|
370
|
+
${custom_ops_library_name}
|
|
371
|
+
PUBLIC
|
|
372
|
+
"-fvisibility=hidden"
|
|
373
|
+
)
|
|
374
|
+
endif()
|
|
375
|
+
|
|
376
|
+
# We disable the "attributes" warning in the core library.
|
|
377
|
+
# This warning is triggered when, e.g., a class has "default" (i.e.
|
|
378
|
+
# public) visibility but a member of that class has "hidden" visibility.
|
|
379
|
+
# We have such a pattern in the core library with the VideoStreamOptions
|
|
380
|
+
# class and its StableDevice field:
|
|
381
|
+
# - VideoStreamOptions has "default" (public) visibility because it is part
|
|
382
|
+
# of the core library, and the core library must have public symbols
|
|
383
|
+
# because it is depended on by the custom ops library
|
|
384
|
+
# - the StableDevice field has "hidden" visibility because this is how
|
|
385
|
+
# torch::stable exports it.
|
|
386
|
+
# This creates this mismatch where a class has "higher" visibility than its
|
|
387
|
+
# member, hence the warning.
|
|
388
|
+
#
|
|
389
|
+
# We choose to silence this warning here. A possibly better solution would
|
|
390
|
+
# be to have a more fine-grained visibility control where each
|
|
391
|
+
# class/function would be "hidden" unless explicitly marked as public, e.g.
|
|
392
|
+
# through a TORCHCODEC_API annotation. In this case, it is likely that
|
|
393
|
+
# VideoStreamOptions could be in fact "hidden" as well.
|
|
394
|
+
# TODO_STABLE_ABI: do that!
|
|
395
|
+
if (LINUX)
|
|
396
|
+
target_compile_options(
|
|
397
|
+
${core_library_name}
|
|
398
|
+
PRIVATE
|
|
399
|
+
"-Wno-attributes"
|
|
400
|
+
)
|
|
401
|
+
endif()
|
|
402
|
+
|
|
403
|
+
# Install all libraries.
|
|
404
|
+
set(
|
|
405
|
+
all_libraries
|
|
406
|
+
${core_library_name}
|
|
407
|
+
${custom_ops_library_name}
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
# We want the built libraries to end up in [src/]torchcodec so that the
|
|
411
|
+
# Python runtime loader can find them. This is done in two mutually exclusive
|
|
412
|
+
# ways depending on the build mode. Crucially, scikit-build-core doesn't
|
|
413
|
+
# trigger cmake's install() step on editable installs:
|
|
414
|
+
#
|
|
415
|
+
# - Editable installs (`pip install -e .`, SKBUILD_STATE=="editable"): build
|
|
416
|
+
# the compiled libraries directly into the source package dir
|
|
417
|
+
# (src/torchcodec).
|
|
418
|
+
# - Wheel builds and `pip install .`: install() copies the libraries into
|
|
419
|
+
# scikit-build-core's staging dir (which becomes the wheel).
|
|
420
|
+
# scikit-build-core manages the prefix, so we give a destination *relative* to it: "torchcodec/".
|
|
421
|
+
if(SKBUILD_STATE STREQUAL "editable")
|
|
422
|
+
# src/torchcodec, the parent of this _core dir.
|
|
423
|
+
get_filename_component(
|
|
424
|
+
TORCHCODEC_PACKAGE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." ABSOLUTE)
|
|
425
|
+
set_target_properties(${all_libraries} PROPERTIES
|
|
426
|
+
LIBRARY_OUTPUT_DIRECTORY "${TORCHCODEC_PACKAGE_DIR}"
|
|
427
|
+
RUNTIME_OUTPUT_DIRECTORY "${TORCHCODEC_PACKAGE_DIR}" # Windows
|
|
428
|
+
)
|
|
429
|
+
else()
|
|
430
|
+
install(
|
|
431
|
+
TARGETS ${all_libraries}
|
|
432
|
+
LIBRARY DESTINATION torchcodec
|
|
433
|
+
RUNTIME DESTINATION torchcodec # For Windows
|
|
434
|
+
)
|
|
435
|
+
endif()
|
|
436
|
+
|
|
437
|
+
endfunction()
|
|
438
|
+
|
|
439
|
+
# Create libtorchcodec_image, the shared library holding the CPU image decoders
|
|
440
|
+
# (JPEG/PNG/WebP/GIF) and their custom-op registration.
|
|
441
|
+
#
|
|
442
|
+
# This is deliberately SEPARATE from the FFmpeg-linked core libraries and links
|
|
443
|
+
# NO FFmpeg. It is loaded at runtime via its own torch.ops.load_library call (see
|
|
444
|
+
# load_torchcodec_shared_libraries), which puts it in its own RTLD_LOCAL symbol
|
|
445
|
+
# group. That isolation is the whole point: our bundled image codec libs
|
|
446
|
+
# (libjpeg/libpng/libwebp) and the codec libs pulled in by the user's FFmpeg
|
|
447
|
+
# (which also links libpng/libjpeg/... with the same sonames) then live in
|
|
448
|
+
# separate scopes and cannot interpose on each other.
|
|
449
|
+
function(make_torchcodec_image_library)
|
|
450
|
+
# This will expose the want_<codec> booleans and (for Windows) the avif
|
|
451
|
+
# runtime lib path
|
|
452
|
+
discover_image_codecs()
|
|
453
|
+
|
|
454
|
+
set(image_library_name "libtorchcodec_image")
|
|
455
|
+
set(image_library_sources
|
|
456
|
+
${TORCHCODEC_IMAGE_SOURCES}
|
|
457
|
+
${TORCHCODEC_IMAGE_OPS_SOURCES}
|
|
458
|
+
${TORCHCODEC_IO_SOURCES}
|
|
459
|
+
${TORCHCODEC_FILE_LIKE_CONTEXT_SOURCES}
|
|
460
|
+
)
|
|
461
|
+
if(want_gif)
|
|
462
|
+
list(APPEND image_library_sources ${TORCHCODEC_GIFLIB_SOURCES})
|
|
463
|
+
endif()
|
|
464
|
+
|
|
465
|
+
make_torchcodec_sublibrary(
|
|
466
|
+
"${image_library_name}"
|
|
467
|
+
SHARED
|
|
468
|
+
"${image_library_sources}"
|
|
469
|
+
"${TORCH_LIBRARIES}"
|
|
470
|
+
)
|
|
471
|
+
|
|
472
|
+
resolve_image_codec("${TORCHCODEC_BUILD_NVJPEG}" want_nvjpeg)
|
|
473
|
+
if(ENABLE_CUDA AND want_nvjpeg)
|
|
474
|
+
find_package(CUDAToolkit REQUIRED)
|
|
475
|
+
target_link_libraries(${image_library_name} PRIVATE CUDA::nvjpeg CUDA::cudart)
|
|
476
|
+
target_compile_definitions(${image_library_name} PRIVATE TORCHCODEC_ENABLE_NVJPEG=1 USE_CUDA)
|
|
477
|
+
message(STATUS "Building torchcodec with nvJPEG GPU JPEG decoding/encoding support.")
|
|
478
|
+
elseif(ENABLE_CUDA)
|
|
479
|
+
message(STATUS "Not building torchcodec with nvJPEG support (disabled via TORCHCODEC_BUILD_NVJPEG/TORCHCODEC_BUILD_IMAGE): decode_jpeg(device='cuda') and encode_jpeg() on CUDA tensors will raise at runtime.")
|
|
480
|
+
endif()
|
|
481
|
+
|
|
482
|
+
if(want_jpeg)
|
|
483
|
+
target_compile_definitions(${image_library_name} PRIVATE TORCHCODEC_ENABLE_JPEG=1)
|
|
484
|
+
target_link_libraries(${image_library_name} PRIVATE JPEG::JPEG)
|
|
485
|
+
endif()
|
|
486
|
+
if(want_png)
|
|
487
|
+
target_compile_definitions(${image_library_name} PRIVATE TORCHCODEC_ENABLE_PNG=1)
|
|
488
|
+
target_link_libraries(${image_library_name} PRIVATE PNG::PNG)
|
|
489
|
+
endif()
|
|
490
|
+
if(want_webp)
|
|
491
|
+
target_compile_definitions(${image_library_name} PRIVATE TORCHCODEC_ENABLE_WEBP=1)
|
|
492
|
+
# WebP::webpdemux provides the WebPAnimDecoder API used for animated
|
|
493
|
+
# webp files.
|
|
494
|
+
target_link_libraries(${image_library_name} PRIVATE WebP::webp WebP::webpdemux)
|
|
495
|
+
endif()
|
|
496
|
+
if(want_avif)
|
|
497
|
+
target_compile_definitions(${image_library_name} PRIVATE TORCHCODEC_ENABLE_AVIF=1)
|
|
498
|
+
target_link_libraries(${image_library_name} PRIVATE avif)
|
|
499
|
+
endif()
|
|
500
|
+
if(want_gif)
|
|
501
|
+
target_compile_definitions(${image_library_name} PRIVATE TORCHCODEC_ENABLE_GIF=1)
|
|
502
|
+
endif()
|
|
503
|
+
|
|
504
|
+
# Hide our own (and statically linked giflib's) symbols so the only thing
|
|
505
|
+
# exported is the torch op registration. Belt-and-suspenders on top of the
|
|
506
|
+
# RTLD_LOCAL isolation.
|
|
507
|
+
if(LINUX)
|
|
508
|
+
target_compile_options(${image_library_name} PRIVATE "-fvisibility=hidden")
|
|
509
|
+
endif()
|
|
510
|
+
|
|
511
|
+
if(SKBUILD_STATE STREQUAL "editable")
|
|
512
|
+
get_filename_component(
|
|
513
|
+
TORCHCODEC_PACKAGE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." ABSOLUTE)
|
|
514
|
+
set_target_properties(${image_library_name} PROPERTIES
|
|
515
|
+
LIBRARY_OUTPUT_DIRECTORY "${TORCHCODEC_PACKAGE_DIR}"
|
|
516
|
+
RUNTIME_OUTPUT_DIRECTORY "${TORCHCODEC_PACKAGE_DIR}" # Windows
|
|
517
|
+
)
|
|
518
|
+
if(WIN32 AND want_avif)
|
|
519
|
+
# Windows editable build needs the libavif DLL next to the image
|
|
520
|
+
# lib. Note that the other image codec lib don't, because they are
|
|
521
|
+
# already on the DLL search path. This is speculative and untested,
|
|
522
|
+
# we're just trying to be nice to Windows editable builds.
|
|
523
|
+
file(COPY "${avif_runtime_lib}" DESTINATION "${TORCHCODEC_PACKAGE_DIR}")
|
|
524
|
+
endif()
|
|
525
|
+
else()
|
|
526
|
+
install(
|
|
527
|
+
TARGETS ${image_library_name}
|
|
528
|
+
LIBRARY DESTINATION torchcodec
|
|
529
|
+
RUNTIME DESTINATION torchcodec # For Windows
|
|
530
|
+
)
|
|
531
|
+
endif()
|
|
532
|
+
endfunction()
|
|
533
|
+
|
|
534
|
+
# Create libtorchcodec_heic, a SEPARATE library holding just the HEIC decoder.
|
|
535
|
+
#
|
|
536
|
+
# HEIC links libheif (+ its HEVC decoder libde265), which are LGPL and therefore
|
|
537
|
+
# NOT bundled in our wheels: we treat libheif like FFmpeg, an optional
|
|
538
|
+
# user-supplied runtime dependency, and most of torchcodec should just work
|
|
539
|
+
# without libheif - we should only fail at runtime if it can't be found *and* if
|
|
540
|
+
# it's needed.
|
|
541
|
+
function(make_torchcodec_heic_library)
|
|
542
|
+
set(heic_library_name "libtorchcodec_heic")
|
|
543
|
+
set(heic_library_sources
|
|
544
|
+
${TORCHCODEC_HEIC_SOURCES}
|
|
545
|
+
${TORCHCODEC_HEIC_OPS_SOURCES}
|
|
546
|
+
)
|
|
547
|
+
|
|
548
|
+
make_torchcodec_sublibrary(
|
|
549
|
+
"${heic_library_name}"
|
|
550
|
+
SHARED
|
|
551
|
+
"${heic_library_sources}"
|
|
552
|
+
"${TORCH_LIBRARIES}"
|
|
553
|
+
)
|
|
554
|
+
|
|
555
|
+
resolve_image_codec("${TORCHCODEC_BUILD_HEIC}" want_heic)
|
|
556
|
+
if(want_heic)
|
|
557
|
+
# conda-forge's libheif ships a CMake package config (libheif-config.cmake)
|
|
558
|
+
# exposing the `heif` imported target. Fall back to pkg-config otherwise.
|
|
559
|
+
if(NOT DEFINED libheif_ROOT AND DEFINED ENV{CONDA_PREFIX})
|
|
560
|
+
if(WIN32)
|
|
561
|
+
set(libheif_ROOT "$ENV{CONDA_PREFIX}/Library")
|
|
562
|
+
else()
|
|
563
|
+
set(libheif_ROOT "$ENV{CONDA_PREFIX}")
|
|
564
|
+
endif()
|
|
565
|
+
endif()
|
|
566
|
+
set(heic_found FALSE)
|
|
567
|
+
find_package(libheif CONFIG QUIET)
|
|
568
|
+
if(libheif_FOUND)
|
|
569
|
+
set(heic_found TRUE)
|
|
570
|
+
target_link_libraries(${heic_library_name} PRIVATE heif)
|
|
571
|
+
else()
|
|
572
|
+
find_package(PkgConfig QUIET)
|
|
573
|
+
if(PkgConfig_FOUND)
|
|
574
|
+
pkg_check_modules(HEIF QUIET IMPORTED_TARGET libheif)
|
|
575
|
+
if(HEIF_FOUND)
|
|
576
|
+
set(heic_found TRUE)
|
|
577
|
+
target_link_libraries(${heic_library_name} PRIVATE PkgConfig::HEIF)
|
|
578
|
+
endif()
|
|
579
|
+
endif()
|
|
580
|
+
endif()
|
|
581
|
+
|
|
582
|
+
if(heic_found)
|
|
583
|
+
target_compile_definitions(${heic_library_name} PRIVATE TORCHCODEC_ENABLE_HEIC=1)
|
|
584
|
+
message(STATUS "libheif found: building torchcodec with HEIC image decoding support.")
|
|
585
|
+
else()
|
|
586
|
+
message(FATAL_ERROR
|
|
587
|
+
"libheif not found, but HEIC image decoding is enabled. Install "
|
|
588
|
+
"libheif and its development headers (e.g. `conda install -c "
|
|
589
|
+
"conda-forge libheif`), or set TORCHCODEC_BUILD_HEIC=0 to build "
|
|
590
|
+
"without HEIC support (decode_heic will raise at runtime), or "
|
|
591
|
+
"TORCHCODEC_BUILD_IMAGE=0 to disable all image decoders.")
|
|
592
|
+
endif()
|
|
593
|
+
else()
|
|
594
|
+
message(STATUS "Not building torchcodec with HEIC image decoding support (disabled via TORCHCODEC_BUILD_HEIC/TORCHCODEC_BUILD_IMAGE): decode_heic will raise at runtime.")
|
|
595
|
+
endif()
|
|
596
|
+
|
|
597
|
+
# Hide everything except the torch op registration, like the image library.
|
|
598
|
+
if(LINUX)
|
|
599
|
+
target_compile_options(${heic_library_name} PRIVATE "-fvisibility=hidden")
|
|
600
|
+
endif()
|
|
601
|
+
|
|
602
|
+
if(SKBUILD_STATE STREQUAL "editable")
|
|
603
|
+
get_filename_component(
|
|
604
|
+
TORCHCODEC_PACKAGE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." ABSOLUTE)
|
|
605
|
+
set_target_properties(${heic_library_name} PROPERTIES
|
|
606
|
+
LIBRARY_OUTPUT_DIRECTORY "${TORCHCODEC_PACKAGE_DIR}"
|
|
607
|
+
RUNTIME_OUTPUT_DIRECTORY "${TORCHCODEC_PACKAGE_DIR}" # Windows
|
|
608
|
+
)
|
|
609
|
+
else()
|
|
610
|
+
install(
|
|
611
|
+
TARGETS ${heic_library_name}
|
|
612
|
+
LIBRARY DESTINATION torchcodec
|
|
613
|
+
RUNTIME DESTINATION torchcodec # For Windows
|
|
614
|
+
)
|
|
615
|
+
endif()
|
|
616
|
+
endfunction()
|
|
617
|
+
|
|
618
|
+
make_torchcodec_image_library()
|
|
619
|
+
make_torchcodec_heic_library()
|
|
620
|
+
|
|
621
|
+
if(DEFINED ENV{BUILD_AGAINST_ALL_FFMPEG_FROM_S3})
|
|
622
|
+
message(
|
|
623
|
+
STATUS
|
|
624
|
+
"Building and dynamically linking libtorchcodec against our pre-built
|
|
625
|
+
non-GPL FFmpeg libraries. These libraries are only used at build time,
|
|
626
|
+
you still need a different FFmpeg to be installed for run time!"
|
|
627
|
+
)
|
|
628
|
+
|
|
629
|
+
# This will expose the torchcodec::ffmpeg{N} (N=4,5,6,7,8,9) targets
|
|
630
|
+
include(
|
|
631
|
+
${CMAKE_CURRENT_SOURCE_DIR}/fetch_and_expose_non_gpl_ffmpeg_libs.cmake
|
|
632
|
+
)
|
|
633
|
+
|
|
634
|
+
make_torchcodec_libraries(9 torchcodec::ffmpeg9)
|
|
635
|
+
make_torchcodec_libraries(8 torchcodec::ffmpeg8)
|
|
636
|
+
make_torchcodec_libraries(7 torchcodec::ffmpeg7)
|
|
637
|
+
make_torchcodec_libraries(6 torchcodec::ffmpeg6)
|
|
638
|
+
make_torchcodec_libraries(4 torchcodec::ffmpeg4)
|
|
639
|
+
make_torchcodec_libraries(5 torchcodec::ffmpeg5)
|
|
640
|
+
else()
|
|
641
|
+
message(
|
|
642
|
+
STATUS
|
|
643
|
+
"Building and dynamically linking libtorchcodec against the installed
|
|
644
|
+
FFmpeg libraries. This require pkg-config to be installed. If you have
|
|
645
|
+
installed FFmpeg from conda, make sure pkg-config is installed from
|
|
646
|
+
conda as well."
|
|
647
|
+
)
|
|
648
|
+
|
|
649
|
+
# This will expose `add_ffmpeg_target_with_pkg_config`
|
|
650
|
+
include("${CMAKE_CURRENT_SOURCE_DIR}/../share/cmake/TorchCodec/ffmpeg_versions.cmake")
|
|
651
|
+
|
|
652
|
+
add_ffmpeg_target_with_pkg_config(ffmpeg_major_version)
|
|
653
|
+
make_torchcodec_libraries(${ffmpeg_major_version} torchcodec::ffmpeg${ffmpeg_major_version})
|
|
654
|
+
|
|
655
|
+
# Expose these values updwards so that the test compilation does not need
|
|
656
|
+
# to re-figure it out. FIXME: it's not great that we just copy-paste the
|
|
657
|
+
# library names.
|
|
658
|
+
set(libtorchcodec_library_name "libtorchcodec_core${ffmpeg_major_version}" PARENT_SCOPE)
|
|
659
|
+
set(libtorchcodec_custom_ops_name "libtorchcodec_custom_ops${ffmpeg_major_version}" PARENT_SCOPE)
|
|
660
|
+
set(libav_include_dirs ${LIBAV_INCLUDE_DIRS} PARENT_SCOPE)
|
|
661
|
+
endif()
|