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.
Files changed (179) hide show
  1. torchcodec/__init__.py +50 -0
  2. torchcodec/_core/AVIOContextHolder.cpp +85 -0
  3. torchcodec/_core/AVIOContextHolder.h +44 -0
  4. torchcodec/_core/AudioCommon.cpp +101 -0
  5. torchcodec/_core/AudioCommon.h +48 -0
  6. torchcodec/_core/AudioConverter.cpp +130 -0
  7. torchcodec/_core/AudioConverter.h +59 -0
  8. torchcodec/_core/BetaCudaDeviceInterface.cpp +1635 -0
  9. torchcodec/_core/BetaCudaDeviceInterface.h +364 -0
  10. torchcodec/_core/CMakeLists.txt +661 -0
  11. torchcodec/_core/CUDACommon.cpp +129 -0
  12. torchcodec/_core/CUDACommon.h +115 -0
  13. torchcodec/_core/Cache.h +126 -0
  14. torchcodec/_core/CodecParameters.cpp +98 -0
  15. torchcodec/_core/CodecParameters.h +59 -0
  16. torchcodec/_core/ColorConverter.cpp +92 -0
  17. torchcodec/_core/ColorConverter.h +40 -0
  18. torchcodec/_core/CpuDeviceInterface.cpp +654 -0
  19. torchcodec/_core/CpuDeviceInterface.h +153 -0
  20. torchcodec/_core/CudaDeviceInterface.cpp +519 -0
  21. torchcodec/_core/CudaDeviceInterface.h +92 -0
  22. torchcodec/_core/DecodeAvif.cpp +284 -0
  23. torchcodec/_core/DecodeAvif.h +28 -0
  24. torchcodec/_core/DecodeGif.cpp +488 -0
  25. torchcodec/_core/DecodeGif.h +32 -0
  26. torchcodec/_core/DecodeHeic.cpp +306 -0
  27. torchcodec/_core/DecodeHeic.h +18 -0
  28. torchcodec/_core/DecodeJpeg.cpp +489 -0
  29. torchcodec/_core/DecodeJpeg.h +17 -0
  30. torchcodec/_core/DecodeJpegCuda.cpp +638 -0
  31. torchcodec/_core/DecodeJpegCuda.h +92 -0
  32. torchcodec/_core/DecodePng.cpp +569 -0
  33. torchcodec/_core/DecodePng.h +31 -0
  34. torchcodec/_core/DecodeWebp.cpp +238 -0
  35. torchcodec/_core/DecodeWebp.h +17 -0
  36. torchcodec/_core/Demuxer.cpp +415 -0
  37. torchcodec/_core/Demuxer.h +158 -0
  38. torchcodec/_core/DeviceInterface.cpp +152 -0
  39. torchcodec/_core/DeviceInterface.h +255 -0
  40. torchcodec/_core/EncodeJpeg.cpp +223 -0
  41. torchcodec/_core/EncodeJpeg.h +19 -0
  42. torchcodec/_core/EncodeJpegCuda.cpp +272 -0
  43. torchcodec/_core/EncodeJpegCuda.h +56 -0
  44. torchcodec/_core/EncodePng.cpp +207 -0
  45. torchcodec/_core/EncodePng.h +19 -0
  46. torchcodec/_core/Encoder.cpp +1023 -0
  47. torchcodec/_core/Encoder.h +144 -0
  48. torchcodec/_core/Exif.h +241 -0
  49. torchcodec/_core/FFMPEGCommon.cpp +1159 -0
  50. torchcodec/_core/FFMPEGCommon.h +506 -0
  51. torchcodec/_core/FileIO.cpp +78 -0
  52. torchcodec/_core/FileIO.h +34 -0
  53. torchcodec/_core/FileLikeIO.cpp +76 -0
  54. torchcodec/_core/FileLikeIO.h +68 -0
  55. torchcodec/_core/FilterGraph.cpp +211 -0
  56. torchcodec/_core/FilterGraph.h +59 -0
  57. torchcodec/_core/Frame.cpp +75 -0
  58. torchcodec/_core/Frame.h +76 -0
  59. torchcodec/_core/IOInterface.h +44 -0
  60. torchcodec/_core/ImageCommon.h +113 -0
  61. torchcodec/_core/Logging.cpp +42 -0
  62. torchcodec/_core/Logging.h +38 -0
  63. torchcodec/_core/Metadata.cpp +312 -0
  64. torchcodec/_core/Metadata.h +115 -0
  65. torchcodec/_core/NVCUVIDRuntimeLoader.cpp +324 -0
  66. torchcodec/_core/NVCUVIDRuntimeLoader.h +14 -0
  67. torchcodec/_core/NVDECCache.cpp +111 -0
  68. torchcodec/_core/NVDECCache.h +136 -0
  69. torchcodec/_core/NVDECCacheConfig.cpp +61 -0
  70. torchcodec/_core/NVDECCacheConfig.h +30 -0
  71. torchcodec/_core/PacketDecoder.cpp +358 -0
  72. torchcodec/_core/PacketDecoder.h +140 -0
  73. torchcodec/_core/SingleStreamDecoder.cpp +1856 -0
  74. torchcodec/_core/SingleStreamDecoder.h +424 -0
  75. torchcodec/_core/StableABICompat.h +213 -0
  76. torchcodec/_core/StreamOptions.h +93 -0
  77. torchcodec/_core/SwScale.cpp +124 -0
  78. torchcodec/_core/SwScale.h +67 -0
  79. torchcodec/_core/TensorIO.cpp +136 -0
  80. torchcodec/_core/TensorIO.h +53 -0
  81. torchcodec/_core/Transform.cpp +207 -0
  82. torchcodec/_core/Transform.h +125 -0
  83. torchcodec/_core/ValidationUtils.cpp +65 -0
  84. torchcodec/_core/ValidationUtils.h +29 -0
  85. torchcodec/_core/WavDecoder.cpp +494 -0
  86. torchcodec/_core/WavDecoder.h +73 -0
  87. torchcodec/_core/__init__.py +45 -0
  88. torchcodec/_core/_decoder_utils.py +258 -0
  89. torchcodec/_core/_ffmpeg_op_names.py +95 -0
  90. torchcodec/_core/_ffmpeg_ops.py +699 -0
  91. torchcodec/_core/_file_like.py +221 -0
  92. torchcodec/_core/_metadata.py +402 -0
  93. torchcodec/_core/color_conversion.cpp +316 -0
  94. torchcodec/_core/color_conversion.cu +391 -0
  95. torchcodec/_core/color_conversion.h +150 -0
  96. torchcodec/_core/custom_ops.cpp +2438 -0
  97. torchcodec/_core/fetch_and_expose_non_gpl_ffmpeg_libs.cmake +192 -0
  98. torchcodec/_core/fetch_avif_from_s3.cmake +81 -0
  99. torchcodec/_core/giflib/README +28 -0
  100. torchcodec/_core/giflib/dgif_lib.c +1313 -0
  101. torchcodec/_core/giflib/gif_hash.c +129 -0
  102. torchcodec/_core/giflib/gif_hash.h +43 -0
  103. torchcodec/_core/giflib/gif_lib.h +292 -0
  104. torchcodec/_core/giflib/gif_lib_private.h +73 -0
  105. torchcodec/_core/giflib/gifalloc.c +426 -0
  106. torchcodec/_core/giflib/openbsd-reallocarray.c +74 -0
  107. torchcodec/_core/heic_custom_ops.cpp +20 -0
  108. torchcodec/_core/image_custom_ops.cpp +137 -0
  109. torchcodec/_core/nvcuvid_include/cuviddec.h +1374 -0
  110. torchcodec/_core/nvcuvid_include/nvcuvid.h +610 -0
  111. torchcodec/_core/ops.py +103 -0
  112. torchcodec/_core/sources.bzl +113 -0
  113. torchcodec/_frame.py +146 -0
  114. torchcodec/_internally_replaced_utils.py +129 -0
  115. torchcodec/_logging.py +59 -0
  116. torchcodec/decoders/__init__.py +50 -0
  117. torchcodec/decoders/_audio_decoder.py +183 -0
  118. torchcodec/decoders/_blocks/__init__.py +48 -0
  119. torchcodec/decoders/_blocks/_audio_converter.py +155 -0
  120. torchcodec/decoders/_blocks/_codec_parameters.py +229 -0
  121. torchcodec/decoders/_blocks/_color_converter.py +107 -0
  122. torchcodec/decoders/_blocks/_demuxer.py +678 -0
  123. torchcodec/decoders/_blocks/_frame.py +577 -0
  124. torchcodec/decoders/_blocks/_helpers.py +53 -0
  125. torchcodec/decoders/_blocks/_packet_decoder.py +357 -0
  126. torchcodec/decoders/_decoder_utils.py +128 -0
  127. torchcodec/decoders/_image_decoders.py +1575 -0
  128. torchcodec/decoders/_video_decoder.py +592 -0
  129. torchcodec/decoders/_wav_decoder.py +131 -0
  130. torchcodec/encoders/__init__.py +4 -0
  131. torchcodec/encoders/_audio_encoder.py +167 -0
  132. torchcodec/encoders/_image_encoders.py +181 -0
  133. torchcodec/encoders/_multi_stream_encoder.py +272 -0
  134. torchcodec/encoders/_video_encoder.py +227 -0
  135. torchcodec/jpeg8.dll +0 -0
  136. torchcodec/libavif.dll +0 -0
  137. torchcodec/libpng16.dll +0 -0
  138. torchcodec/libsharpyuv.dll +0 -0
  139. torchcodec/libtorchcodec_core4.dll +0 -0
  140. torchcodec/libtorchcodec_core5.dll +0 -0
  141. torchcodec/libtorchcodec_core6.dll +0 -0
  142. torchcodec/libtorchcodec_core7.dll +0 -0
  143. torchcodec/libtorchcodec_core8.dll +0 -0
  144. torchcodec/libtorchcodec_core9.dll +0 -0
  145. torchcodec/libtorchcodec_custom_ops4.dll +0 -0
  146. torchcodec/libtorchcodec_custom_ops5.dll +0 -0
  147. torchcodec/libtorchcodec_custom_ops6.dll +0 -0
  148. torchcodec/libtorchcodec_custom_ops7.dll +0 -0
  149. torchcodec/libtorchcodec_custom_ops8.dll +0 -0
  150. torchcodec/libtorchcodec_custom_ops9.dll +0 -0
  151. torchcodec/libtorchcodec_heic.dll +0 -0
  152. torchcodec/libtorchcodec_image.dll +0 -0
  153. torchcodec/libwebp.dll +0 -0
  154. torchcodec/libwebpdecoder.dll +0 -0
  155. torchcodec/libwebpdemux.dll +0 -0
  156. torchcodec/libwebpmux.dll +0 -0
  157. torchcodec/libzstd.dll +0 -0
  158. torchcodec/py.typed +0 -0
  159. torchcodec/samplers/__init__.py +2 -0
  160. torchcodec/samplers/_common.py +83 -0
  161. torchcodec/samplers/_index_based.py +287 -0
  162. torchcodec/samplers/_time_based.py +360 -0
  163. torchcodec/share/cmake/TorchCodec/TorchCodecConfig.cmake +76 -0
  164. torchcodec/share/cmake/TorchCodec/ffmpeg_versions.cmake +128 -0
  165. torchcodec/transforms/__init__.py +12 -0
  166. torchcodec/transforms/_decoder_transforms.py +375 -0
  167. torchcodec/version.py +1 -0
  168. torchcodec/zlib.dll +0 -0
  169. torchcodec-1.0.0.dist-info/METADATA +275 -0
  170. torchcodec-1.0.0.dist-info/RECORD +179 -0
  171. torchcodec-1.0.0.dist-info/WHEEL +5 -0
  172. torchcodec-1.0.0.dist-info/licenses/LICENSE +28 -0
  173. torchcodec-1.0.0.dist-info/licenses/third_party/COPYING.dav1d +23 -0
  174. torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libavif +387 -0
  175. torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libjpeg-turbo +135 -0
  176. torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libpng +134 -0
  177. torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libwebp +30 -0
  178. torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libyuv +29 -0
  179. torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.zlib +22 -0
@@ -0,0 +1,125 @@
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 <optional>
10
+ #include <string>
11
+ #include "Frame.h"
12
+ #include "Metadata.h"
13
+
14
+ namespace facebook::torchcodec {
15
+
16
+ class Transform {
17
+ public:
18
+ virtual std::string get_filter_graph_cpu() const = 0;
19
+ virtual ~Transform() = default;
20
+
21
+ // If the transformation does not change the output frame dimensions, then
22
+ // there is no need to override this member function. The default
23
+ // implementation returns an empty optional, indicating that the output frame
24
+ // has the same dimensions as the input frame.
25
+ //
26
+ // If the transformation does change the output frame dimensions, then it
27
+ // must override this member function and return the output frame dimensions.
28
+ virtual std::optional<FrameDims> get_output_frame_dims() const {
29
+ return std::nullopt;
30
+ }
31
+
32
+ // The ResizeTransform is special because it is the only transform
33
+ // that swscale can handle.
34
+ virtual bool is_resize() const {
35
+ return false;
36
+ }
37
+
38
+ // The validity of some transforms depends on the characteristics of the
39
+ // AVStream they're being applied to. For example, some transforms will
40
+ // specify coordinates inside a frame, we need to validate that those are
41
+ // within the frame's bounds.
42
+ //
43
+ // Note that the validation function does not return anything. We expect
44
+ // invalid configurations to throw an exception.
45
+ virtual void validate([[maybe_unused]] const FrameDims& input_dims) const {}
46
+ };
47
+
48
+ class ResizeTransform : public Transform {
49
+ public:
50
+ enum class InterpolationMode { BILINEAR };
51
+
52
+ explicit ResizeTransform(const FrameDims& dims)
53
+ : output_dims_(dims), interpolation_mode_(InterpolationMode::BILINEAR) {}
54
+
55
+ ResizeTransform(const FrameDims& dims, InterpolationMode interpolation_mode)
56
+ : output_dims_(dims), interpolation_mode_(interpolation_mode) {}
57
+
58
+ std::string get_filter_graph_cpu() const override;
59
+ std::optional<FrameDims> get_output_frame_dims() const override;
60
+ bool is_resize() const override;
61
+
62
+ int get_sws_flags() const;
63
+
64
+ private:
65
+ FrameDims output_dims_;
66
+ InterpolationMode interpolation_mode_;
67
+ };
68
+
69
+ class CropTransform : public Transform {
70
+ public:
71
+ CropTransform(const FrameDims& dims, int x, int y);
72
+
73
+ // Becomes a center crop if x and y are not specified.
74
+ explicit CropTransform(const FrameDims& dims);
75
+
76
+ std::string get_filter_graph_cpu() const override;
77
+ std::optional<FrameDims> get_output_frame_dims() const override;
78
+ void validate(const FrameDims& input_dims) const override;
79
+
80
+ private:
81
+ FrameDims output_dims_;
82
+ std::optional<int> x_;
83
+ std::optional<int> y_;
84
+ };
85
+
86
+ // Rotation values for RotationTransform.
87
+ // These correspond to video metadata rotation angles.
88
+ enum class Rotation {
89
+ NONE, // 0°
90
+ CCW90, // 90° counter-clockwise
91
+ CW90, // 90° clockwise (or -90°)
92
+ ROTATE180 // 180° (or -180°)
93
+ };
94
+
95
+ // Converts rotation degrees from video metadata to Rotation enum.
96
+ // Input is expected in the range [-180, 180].
97
+ // Rounds to nearest multiple of 90 degrees before converting.
98
+ // Returns Rotation::NONE for nullopt.
99
+ Rotation rotation_from_degrees(std::optional<double> degrees);
100
+
101
+ // Rotates an HWC tensor, returning a contiguous result (`hwc` unchanged for
102
+ // Rotation::NONE). For the paths that can't express rotation as a filter graph
103
+ // and have to apply it to the already-converted RGB frame.
104
+ FORCE_PUBLIC_VISIBILITY torch::stable::Tensor rotate_hwc_tensor(
105
+ const torch::stable::Tensor& hwc,
106
+ Rotation rotation);
107
+
108
+ // Applies rotation in multiples of 90 degrees using FFmpeg's transpose/flip
109
+ // filters. Note: this does not support arbitrary angle rotation
110
+ // like TorchVision's RandomRotation transform.
111
+ // Handles rotation in the filter graph so that user transforms
112
+ // operate in post-rotation coordinate space.
113
+ class RotationTransform : public Transform {
114
+ public:
115
+ RotationTransform(Rotation rotation, const FrameDims& input_dims);
116
+
117
+ std::string get_filter_graph_cpu() const override;
118
+ std::optional<FrameDims> get_output_frame_dims() const override;
119
+
120
+ private:
121
+ Rotation rotation_;
122
+ FrameDims output_dims_;
123
+ };
124
+
125
+ } // namespace facebook::torchcodec
@@ -0,0 +1,65 @@
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 "ValidationUtils.h"
8
+ #include <limits>
9
+ #include "StableABICompat.h"
10
+
11
+ namespace facebook::torchcodec {
12
+
13
+ int validate_int64_to_int(int64_t value, const std::string& parameter_name) {
14
+ STD_TORCH_CHECK(
15
+ value >= std::numeric_limits<int>::min() &&
16
+ value <= std::numeric_limits<int>::max(),
17
+ parameter_name,
18
+ "=",
19
+ value,
20
+ " is out of range for int type.");
21
+
22
+ return static_cast<int>(value);
23
+ }
24
+
25
+ uint32_t validate_int64_to_uint32(
26
+ int64_t value,
27
+ const std::string& parameter_name) {
28
+ STD_TORCH_CHECK(
29
+ value >= 0 && value <= std::numeric_limits<uint32_t>::max(),
30
+ parameter_name,
31
+ "=",
32
+ value,
33
+ " is out of range for uint32 type.");
34
+
35
+ return static_cast<uint32_t>(value);
36
+ }
37
+
38
+ std::optional<int> validate_optional_int64_to_int(
39
+ const std::optional<int64_t>& value,
40
+ const std::string& parameter_name) {
41
+ if (value.has_value()) {
42
+ return validate_int64_to_int(value.value(), parameter_name);
43
+ } else {
44
+ return std::nullopt;
45
+ }
46
+ }
47
+
48
+ std::streampos validate_uint64_to_streampos(
49
+ uint64_t value,
50
+ const std::string& parameter_name) {
51
+ // We validate against streamoff limits because streampos
52
+ // (std::fpos<state_type>) stores the actual position as streamoff internally.
53
+ // https://en.cppreference.com/w/cpp/io/fpos.html
54
+ STD_TORCH_CHECK(
55
+ value <=
56
+ static_cast<uint64_t>(std::numeric_limits<std::streamoff>::max()),
57
+ parameter_name,
58
+ "=",
59
+ value,
60
+ " is out of range for streampos type.");
61
+
62
+ return static_cast<std::streampos>(value);
63
+ }
64
+
65
+ } // namespace facebook::torchcodec
@@ -0,0 +1,29 @@
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 <cstdint>
10
+ #include <optional>
11
+ #include <string>
12
+
13
+ namespace facebook::torchcodec {
14
+
15
+ int validate_int64_to_int(int64_t value, const std::string& parameter_name);
16
+
17
+ uint32_t validate_int64_to_uint32(
18
+ int64_t value,
19
+ const std::string& parameter_name);
20
+
21
+ std::optional<int> validate_optional_int64_to_int(
22
+ const std::optional<int64_t>& value,
23
+ const std::string& parameter_name);
24
+
25
+ std::streampos validate_uint64_to_streampos(
26
+ uint64_t value,
27
+ const std::string& parameter_name);
28
+
29
+ } // namespace facebook::torchcodec