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,207 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
// All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
// This source code is licensed under the BSD-style license found in the
|
|
5
|
+
// LICENSE file in the root directory of this source tree.
|
|
6
|
+
|
|
7
|
+
#include "EncodePng.h"
|
|
8
|
+
|
|
9
|
+
#include <torch/csrc/stable/library.h>
|
|
10
|
+
#include <torch/csrc/stable/ops.h>
|
|
11
|
+
#include <torch/headeronly/util/Exception.h>
|
|
12
|
+
|
|
13
|
+
#include "StableABICompat.h"
|
|
14
|
+
|
|
15
|
+
#if !TORCHCODEC_ENABLE_PNG
|
|
16
|
+
|
|
17
|
+
namespace facebook::torchcodec {
|
|
18
|
+
|
|
19
|
+
void encode_png(
|
|
20
|
+
[[maybe_unused]] const torch::stable::Tensor& img,
|
|
21
|
+
[[maybe_unused]] int64_t compression_level,
|
|
22
|
+
[[maybe_unused]] IOInterface& interface) {
|
|
23
|
+
STD_TORCH_CHECK(
|
|
24
|
+
false,
|
|
25
|
+
"encode_png: torchcodec was not compiled with libpng support. Rebuild "
|
|
26
|
+
"torchcodec with TORCHCODEC_BUILD_PNG=1. If you see this error in a "
|
|
27
|
+
"prebuilt wheel, please report it to the TorchCodec repo.");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
} // namespace facebook::torchcodec
|
|
31
|
+
|
|
32
|
+
#else
|
|
33
|
+
|
|
34
|
+
#include <png.h>
|
|
35
|
+
#include <setjmp.h>
|
|
36
|
+
|
|
37
|
+
#include <cstdint>
|
|
38
|
+
#include <cstdio>
|
|
39
|
+
#include <exception>
|
|
40
|
+
|
|
41
|
+
namespace facebook::torchcodec {
|
|
42
|
+
|
|
43
|
+
namespace {
|
|
44
|
+
|
|
45
|
+
struct ErrorCtx {
|
|
46
|
+
char error_message[256] = "";
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
void error_callback(png_structp png_ptr, png_const_charp error_message) {
|
|
50
|
+
auto* error_ctx = static_cast<ErrorCtx*>(png_get_error_ptr(png_ptr));
|
|
51
|
+
if (error_ctx != nullptr) {
|
|
52
|
+
std::snprintf(
|
|
53
|
+
error_ctx->error_message,
|
|
54
|
+
sizeof(error_ctx->error_message),
|
|
55
|
+
"%s",
|
|
56
|
+
error_message);
|
|
57
|
+
}
|
|
58
|
+
png_longjmp(png_ptr, 1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
struct IOCtx {
|
|
62
|
+
IOInterface* interface;
|
|
63
|
+
std::exception_ptr interface_exception;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// libpng calls write_callback with chunks of encoded output, which we forward
|
|
67
|
+
// to the IOInterface. The interface->write() call may throw (e.g. a Python
|
|
68
|
+
// file-like raising, or a disk error), but a C++ exception must not unwind
|
|
69
|
+
// through libpng's C stack. So we capture it and abort encoding by
|
|
70
|
+
// png_longjmp-ing to the setjmp point in write_png_to_io, which rethrows it.
|
|
71
|
+
void write_callback(png_structp png_ptr, png_bytep data, png_size_t length) {
|
|
72
|
+
auto* io_ctx = static_cast<IOCtx*>(png_get_io_ptr(png_ptr));
|
|
73
|
+
try {
|
|
74
|
+
io_ctx->interface->write(
|
|
75
|
+
reinterpret_cast<const uint8_t*>(data), static_cast<int>(length));
|
|
76
|
+
return;
|
|
77
|
+
} catch (...) {
|
|
78
|
+
io_ctx->interface_exception = std::current_exception();
|
|
79
|
+
}
|
|
80
|
+
png_longjmp(png_ptr, 1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
void write_png_to_io(
|
|
84
|
+
png_structp& png_write,
|
|
85
|
+
png_infop& info_ptr,
|
|
86
|
+
ErrorCtx& error_ctx,
|
|
87
|
+
IOCtx& io_ctx,
|
|
88
|
+
const uint8_t* input_ptr,
|
|
89
|
+
int64_t width,
|
|
90
|
+
int64_t height,
|
|
91
|
+
int64_t num_channels,
|
|
92
|
+
int64_t compression_level) {
|
|
93
|
+
if (setjmp(png_jmpbuf(png_write)) != 0) {
|
|
94
|
+
png_destroy_write_struct(&png_write, &info_ptr);
|
|
95
|
+
// We land here on either a libpng error (via error_callback) or a failed
|
|
96
|
+
// write (via write_callback). The latter sets interface_exception, which we
|
|
97
|
+
// rethrow to surface the original exception.
|
|
98
|
+
if (io_ctx.interface_exception) {
|
|
99
|
+
std::rethrow_exception(io_ctx.interface_exception);
|
|
100
|
+
} else {
|
|
101
|
+
STD_TORCH_CHECK(false, "encode_png failed: ", error_ctx.error_message);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
png_set_write_fn(png_write, &io_ctx, write_callback, /*flush_fn=*/nullptr);
|
|
106
|
+
|
|
107
|
+
const int color_type =
|
|
108
|
+
(num_channels == 1) ? PNG_COLOR_TYPE_GRAY : PNG_COLOR_TYPE_RGB;
|
|
109
|
+
png_set_IHDR(
|
|
110
|
+
png_write,
|
|
111
|
+
info_ptr,
|
|
112
|
+
static_cast<png_uint_32>(width),
|
|
113
|
+
static_cast<png_uint_32>(height),
|
|
114
|
+
/*bit_depth=*/8,
|
|
115
|
+
color_type,
|
|
116
|
+
PNG_INTERLACE_NONE,
|
|
117
|
+
PNG_COMPRESSION_TYPE_DEFAULT,
|
|
118
|
+
PNG_FILTER_TYPE_DEFAULT);
|
|
119
|
+
png_set_compression_level(png_write, static_cast<int>(compression_level));
|
|
120
|
+
png_write_info(png_write, info_ptr);
|
|
121
|
+
|
|
122
|
+
const int64_t stride = width * num_channels;
|
|
123
|
+
for (int64_t row = 0; row < height; ++row) {
|
|
124
|
+
png_write_row(png_write, input_ptr + row * stride);
|
|
125
|
+
}
|
|
126
|
+
png_write_end(png_write, info_ptr);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
} // namespace
|
|
130
|
+
|
|
131
|
+
// Important: see Note [libjpeg error handling] in the jpeg decoder: everything
|
|
132
|
+
// applies here too. We must not throw a C++ exception through libpng's C stack
|
|
133
|
+
// (and callbacks), and we must not allocate anything that needs proper
|
|
134
|
+
// destruction in a function that defines a setjmp() point. The IOCtx
|
|
135
|
+
// (which owns a std::exception_ptr) therefore lives here, outside
|
|
136
|
+
// write_png_to_io's setjmp.
|
|
137
|
+
void encode_png(
|
|
138
|
+
const torch::stable::Tensor& img,
|
|
139
|
+
int64_t compression_level,
|
|
140
|
+
IOInterface& interface) {
|
|
141
|
+
STD_TORCH_CHECK(
|
|
142
|
+
compression_level >= 0 && compression_level <= 9,
|
|
143
|
+
"Compression level should be between 0 and 9, got ",
|
|
144
|
+
compression_level,
|
|
145
|
+
".");
|
|
146
|
+
STD_TORCH_CHECK(
|
|
147
|
+
img.device().type() == kStableCPU,
|
|
148
|
+
"Input tensor must be on the CPU, got a tensor on ",
|
|
149
|
+
device_type_name(img.device().type()),
|
|
150
|
+
".");
|
|
151
|
+
STD_TORCH_CHECK(
|
|
152
|
+
img.scalar_type() == kStableUInt8,
|
|
153
|
+
"Input tensor must have uint8 data type, got ",
|
|
154
|
+
torch::headeronly::toString(img.scalar_type()),
|
|
155
|
+
".");
|
|
156
|
+
STD_TORCH_CHECK(
|
|
157
|
+
img.dim() == 3,
|
|
158
|
+
"Input tensor must be a 3-dimensional (C, H, W) tensor, got ",
|
|
159
|
+
img.dim(),
|
|
160
|
+
" dimensions.");
|
|
161
|
+
|
|
162
|
+
const int64_t num_channels = img.size(0);
|
|
163
|
+
const int64_t height = img.size(1);
|
|
164
|
+
const int64_t width = img.size(2);
|
|
165
|
+
STD_TORCH_CHECK(
|
|
166
|
+
num_channels == 1 || num_channels == 3,
|
|
167
|
+
"The number of channels should be 1 or 3, got ",
|
|
168
|
+
num_channels,
|
|
169
|
+
".");
|
|
170
|
+
|
|
171
|
+
// libpng writes rows in HWC interleaved order, so permute from CHW. This
|
|
172
|
+
// contiguous copy is kept alive for the whole encoding below.
|
|
173
|
+
auto input = torch::stable::contiguous(stable_permute(img, {1, 2, 0}));
|
|
174
|
+
|
|
175
|
+
auto png_write =
|
|
176
|
+
png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
|
|
177
|
+
STD_TORCH_CHECK(
|
|
178
|
+
png_write != nullptr, "libpng write structure allocation failed!");
|
|
179
|
+
auto info_ptr = png_create_info_struct(png_write);
|
|
180
|
+
if (info_ptr == nullptr) {
|
|
181
|
+
png_destroy_write_struct(&png_write, nullptr);
|
|
182
|
+
STD_TORCH_CHECK(false, "libpng info structure allocation failed!");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
ErrorCtx error_ctx;
|
|
186
|
+
png_set_error_fn(png_write, &error_ctx, error_callback, /*warn_fn=*/nullptr);
|
|
187
|
+
|
|
188
|
+
IOCtx io_ctx;
|
|
189
|
+
io_ctx.interface = &interface;
|
|
190
|
+
|
|
191
|
+
write_png_to_io(
|
|
192
|
+
png_write,
|
|
193
|
+
info_ptr,
|
|
194
|
+
error_ctx,
|
|
195
|
+
io_ctx,
|
|
196
|
+
input.const_data_ptr<uint8_t>(),
|
|
197
|
+
width,
|
|
198
|
+
height,
|
|
199
|
+
num_channels,
|
|
200
|
+
compression_level);
|
|
201
|
+
|
|
202
|
+
png_destroy_write_struct(&png_write, &info_ptr);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
} // namespace facebook::torchcodec
|
|
206
|
+
|
|
207
|
+
#endif // !TORCHCODEC_ENABLE_PNG
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
// All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
// This source code is licensed under the BSD-style license found in the
|
|
5
|
+
// LICENSE file in the root directory of this source tree.
|
|
6
|
+
|
|
7
|
+
#pragma once
|
|
8
|
+
|
|
9
|
+
#include "IOInterface.h"
|
|
10
|
+
#include "StableABICompat.h"
|
|
11
|
+
|
|
12
|
+
namespace facebook::torchcodec {
|
|
13
|
+
|
|
14
|
+
FORCE_PUBLIC_VISIBILITY void encode_png(
|
|
15
|
+
const torch::stable::Tensor& img,
|
|
16
|
+
int64_t compression_level,
|
|
17
|
+
IOInterface& interface);
|
|
18
|
+
|
|
19
|
+
} // namespace facebook::torchcodec
|