torchcodec 0.6.0__cp312-cp312-macosx_11_0_arm64.whl → 0.8.0__cp312-cp312-macosx_11_0_arm64.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.

Potentially problematic release.


This version of torchcodec might be problematic. Click here for more details.

Files changed (75) hide show
  1. torchcodec/.dylibs/libc++.1.0.dylib +0 -0
  2. torchcodec/.dylibs/libpython3.12.dylib +0 -0
  3. torchcodec/_core/AVIOContextHolder.cpp +10 -5
  4. torchcodec/_core/AVIOContextHolder.h +1 -0
  5. torchcodec/_core/AVIOFileLikeContext.cpp +23 -5
  6. torchcodec/_core/AVIOFileLikeContext.h +2 -1
  7. torchcodec/_core/AVIOTensorContext.cpp +4 -2
  8. torchcodec/_core/BetaCudaDeviceInterface.cpp +636 -0
  9. torchcodec/_core/BetaCudaDeviceInterface.h +191 -0
  10. torchcodec/_core/CMakeLists.txt +92 -20
  11. torchcodec/_core/CUDACommon.cpp +315 -0
  12. torchcodec/_core/CUDACommon.h +46 -0
  13. torchcodec/_core/Cache.h +138 -0
  14. torchcodec/_core/CpuDeviceInterface.cpp +201 -214
  15. torchcodec/_core/CpuDeviceInterface.h +88 -36
  16. torchcodec/_core/CudaDeviceInterface.cpp +239 -164
  17. torchcodec/_core/CudaDeviceInterface.h +33 -4
  18. torchcodec/_core/DeviceInterface.cpp +57 -19
  19. torchcodec/_core/DeviceInterface.h +97 -16
  20. torchcodec/_core/Encoder.cpp +315 -14
  21. torchcodec/_core/Encoder.h +57 -5
  22. torchcodec/_core/FFMPEGCommon.cpp +198 -3
  23. torchcodec/_core/FFMPEGCommon.h +33 -0
  24. torchcodec/_core/FilterGraph.cpp +149 -0
  25. torchcodec/_core/FilterGraph.h +59 -0
  26. torchcodec/_core/Frame.cpp +17 -7
  27. torchcodec/_core/Frame.h +15 -61
  28. torchcodec/_core/Metadata.h +2 -2
  29. torchcodec/_core/NVDECCache.cpp +70 -0
  30. torchcodec/_core/NVDECCache.h +104 -0
  31. torchcodec/_core/SingleStreamDecoder.cpp +233 -229
  32. torchcodec/_core/SingleStreamDecoder.h +39 -14
  33. torchcodec/_core/StreamOptions.h +16 -6
  34. torchcodec/_core/Transform.cpp +60 -0
  35. torchcodec/_core/Transform.h +59 -0
  36. torchcodec/_core/ValidationUtils.cpp +35 -0
  37. torchcodec/_core/ValidationUtils.h +21 -0
  38. torchcodec/_core/__init__.py +2 -0
  39. torchcodec/_core/custom_ops.cpp +199 -51
  40. torchcodec/_core/fetch_and_expose_non_gpl_ffmpeg_libs.cmake +142 -8
  41. torchcodec/_core/nvcuvid_include/cuviddec.h +1374 -0
  42. torchcodec/_core/nvcuvid_include/nvcuvid.h +610 -0
  43. torchcodec/_core/ops.py +120 -21
  44. torchcodec/_core/pybind_ops.cpp +22 -21
  45. torchcodec/_internally_replaced_utils.py +9 -6
  46. torchcodec/_samplers/video_clip_sampler.py +7 -19
  47. torchcodec/decoders/__init__.py +1 -0
  48. torchcodec/decoders/_audio_decoder.py +3 -1
  49. torchcodec/decoders/_decoder_utils.py +62 -2
  50. torchcodec/decoders/_video_decoder.py +128 -33
  51. torchcodec/encoders/_audio_encoder.py +41 -1
  52. torchcodec/libtorchcodec_core4.dylib +0 -0
  53. torchcodec/libtorchcodec_core5.dylib +0 -0
  54. torchcodec/libtorchcodec_core6.dylib +0 -0
  55. torchcodec/libtorchcodec_core7.dylib +0 -0
  56. torchcodec/libtorchcodec_core8.dylib +0 -0
  57. torchcodec/libtorchcodec_custom_ops4.dylib +0 -0
  58. torchcodec/libtorchcodec_custom_ops5.dylib +0 -0
  59. torchcodec/libtorchcodec_custom_ops6.dylib +0 -0
  60. torchcodec/libtorchcodec_custom_ops7.dylib +0 -0
  61. torchcodec/libtorchcodec_custom_ops8.dylib +0 -0
  62. torchcodec/libtorchcodec_pybind_ops4.so +0 -0
  63. torchcodec/libtorchcodec_pybind_ops5.so +0 -0
  64. torchcodec/libtorchcodec_pybind_ops6.so +0 -0
  65. torchcodec/libtorchcodec_pybind_ops7.so +0 -0
  66. torchcodec/libtorchcodec_pybind_ops8.so +0 -0
  67. torchcodec/samplers/_index_based.py +2 -0
  68. torchcodec/samplers/_time_based.py +10 -0
  69. torchcodec/version.py +1 -1
  70. {torchcodec-0.6.0.dist-info → torchcodec-0.8.0.dist-info}/METADATA +31 -47
  71. torchcodec-0.8.0.dist-info/RECORD +82 -0
  72. {torchcodec-0.6.0.dist-info → torchcodec-0.8.0.dist-info}/WHEEL +1 -1
  73. torchcodec-0.6.0.dist-info/RECORD +0 -64
  74. {torchcodec-0.6.0.dist-info → torchcodec-0.8.0.dist-info}/licenses/LICENSE +0 -0
  75. {torchcodec-0.6.0.dist-info → torchcodec-0.8.0.dist-info}/top_level.txt +0 -0
Binary file
Binary file
@@ -14,6 +14,7 @@ void AVIOContextHolder::createAVIOContext(
14
14
  AVIOWriteFunction write,
15
15
  AVIOSeekFunction seek,
16
16
  void* heldData,
17
+ bool isForWriting,
17
18
  int bufferSize) {
18
19
  TORCH_CHECK(
19
20
  bufferSize > 0,
@@ -23,14 +24,18 @@ void AVIOContextHolder::createAVIOContext(
23
24
  buffer != nullptr,
24
25
  "Failed to allocate buffer of size " + std::to_string(bufferSize));
25
26
 
26
- TORCH_CHECK(
27
- (seek != nullptr) && ((write != nullptr) ^ (read != nullptr)),
28
- "seek method must be defined, and either write or read must be defined. "
29
- "But not both!")
27
+ TORCH_CHECK(seek != nullptr, "seek method must be defined");
28
+
29
+ if (isForWriting) {
30
+ TORCH_CHECK(write != nullptr, "write method must be defined for writing");
31
+ } else {
32
+ TORCH_CHECK(read != nullptr, "read method must be defined for reading");
33
+ }
34
+
30
35
  avioContext_.reset(avioAllocContext(
31
36
  buffer,
32
37
  bufferSize,
33
- /*write_flag=*/write != nullptr,
38
+ /*write_flag=*/isForWriting,
34
39
  heldData,
35
40
  read,
36
41
  write,
@@ -51,6 +51,7 @@ class AVIOContextHolder {
51
51
  AVIOWriteFunction write,
52
52
  AVIOSeekFunction seek,
53
53
  void* heldData,
54
+ bool isForWriting,
54
55
  int bufferSize = defaultBufferSize);
55
56
 
56
57
  private:
@@ -9,21 +9,31 @@
9
9
 
10
10
  namespace facebook::torchcodec {
11
11
 
12
- AVIOFileLikeContext::AVIOFileLikeContext(py::object fileLike)
12
+ AVIOFileLikeContext::AVIOFileLikeContext(
13
+ const py::object& fileLike,
14
+ bool isForWriting)
13
15
  : fileLike_{UniquePyObject(new py::object(fileLike))} {
14
16
  {
15
17
  // TODO: Is it necessary to acquire the GIL here? Is it maybe even
16
18
  // harmful? At the moment, this is only called from within a pybind
17
19
  // function, and pybind guarantees we have the GIL.
18
20
  py::gil_scoped_acquire gil;
19
- TORCH_CHECK(
20
- py::hasattr(fileLike, "read"),
21
- "File like object must implement a read method.");
21
+
22
+ if (isForWriting) {
23
+ TORCH_CHECK(
24
+ py::hasattr(fileLike, "write"),
25
+ "File like object must implement a write method for writing.");
26
+ } else {
27
+ TORCH_CHECK(
28
+ py::hasattr(fileLike, "read"),
29
+ "File like object must implement a read method for reading.");
30
+ }
31
+
22
32
  TORCH_CHECK(
23
33
  py::hasattr(fileLike, "seek"),
24
34
  "File like object must implement a seek method.");
25
35
  }
26
- createAVIOContext(&read, nullptr, &seek, &fileLike_);
36
+ createAVIOContext(&read, &write, &seek, &fileLike_, isForWriting);
27
37
  }
28
38
 
29
39
  int AVIOFileLikeContext::read(void* opaque, uint8_t* buf, int buf_size) {
@@ -77,4 +87,12 @@ int64_t AVIOFileLikeContext::seek(void* opaque, int64_t offset, int whence) {
77
87
  return py::cast<int64_t>((*fileLike)->attr("seek")(offset, whence));
78
88
  }
79
89
 
90
+ int AVIOFileLikeContext::write(void* opaque, const uint8_t* buf, int buf_size) {
91
+ auto fileLike = static_cast<UniquePyObject*>(opaque);
92
+ py::gil_scoped_acquire gil;
93
+ py::bytes bytes_obj(reinterpret_cast<const char*>(buf), buf_size);
94
+
95
+ return py::cast<int>((*fileLike)->attr("write")(bytes_obj));
96
+ }
97
+
80
98
  } // namespace facebook::torchcodec
@@ -19,11 +19,12 @@ namespace facebook::torchcodec {
19
19
  // and seek calls back up to the methods on the Python object.
20
20
  class AVIOFileLikeContext : public AVIOContextHolder {
21
21
  public:
22
- explicit AVIOFileLikeContext(py::object fileLike);
22
+ explicit AVIOFileLikeContext(const py::object& fileLike, bool isForWriting);
23
23
 
24
24
  private:
25
25
  static int read(void* opaque, uint8_t* buf, int buf_size);
26
26
  static int64_t seek(void* opaque, int64_t offset, int whence);
27
+ static int write(void* opaque, const uint8_t* buf, int buf_size);
27
28
 
28
29
  // Note that we dynamically allocate the Python object because we need to
29
30
  // strictly control when its destructor is called. We must hold the GIL
@@ -105,12 +105,14 @@ AVIOFromTensorContext::AVIOFromTensorContext(torch::Tensor data)
105
105
  TORCH_CHECK(data.numel() > 0, "data must not be empty");
106
106
  TORCH_CHECK(data.is_contiguous(), "data must be contiguous");
107
107
  TORCH_CHECK(data.scalar_type() == torch::kUInt8, "data must be kUInt8");
108
- createAVIOContext(&read, nullptr, &seek, &tensorContext_);
108
+ createAVIOContext(
109
+ &read, nullptr, &seek, &tensorContext_, /*isForWriting=*/false);
109
110
  }
110
111
 
111
112
  AVIOToTensorContext::AVIOToTensorContext()
112
113
  : tensorContext_{torch::empty({INITIAL_TENSOR_SIZE}, {torch::kUInt8}), 0} {
113
- createAVIOContext(nullptr, &write, &seek, &tensorContext_);
114
+ createAVIOContext(
115
+ nullptr, &write, &seek, &tensorContext_, /*isForWriting=*/true);
114
116
  }
115
117
 
116
118
  torch::Tensor AVIOToTensorContext::getOutputTensor() {