summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/torchcodec/default.nix
blob: 06833d43c5c078cc6484c153ffbee89147e1f856 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
{
  lib,
  stdenv,
  config,
  buildPythonPackage,
  fetchFromGitHub,

  # nativeBuildInputs
  pkg-config,

  # buildInputs
  ffmpeg,
  cudaPackages,

  # build-system
  cmake,
  setuptools,
  torch,

  # tests
  pytestCheckHook,
  torchvision,

  cudaSupport ? config.cudaSupport,
}:

buildPythonPackage rec {
  pname = "torchcodec";
  version = "0.9.0";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "meta-pytorch";
    repo = "torchcodec";
    tag = "v${version}";
    hash = "sha256-QG7LX9G1HV2l75jsgsbM4ts6bg0wvsNhjml19b7yYEQ=";
  };

  postPatch = ''
    substituteInPlace \
      test/utils.py \
      test/test_encoders.py \
      --replace-fail \
        '"ffprobe"' \
        '"${lib.getExe' ffmpeg "ffprobe"}"'

    substituteInPlace test/test_encoders.py \
      --replace-fail \
        '"ffmpeg"' \
        '"${lib.getExe ffmpeg}"'
  '';

  nativeBuildInputs = [
    pkg-config
  ]
  ++ lib.optionals cudaSupport [
    cudaPackages.cuda_nvcc
  ];

  buildInputs = [
    ffmpeg
  ]
  ++ lib.optionals cudaSupport (
    with cudaPackages;
    [
      cuda_cudart
      cuda_nvrtc
      libcublas # cublas_v2.h
      libcusolver # cusolverDn.h
      libcusparse # cusparse.h
      libnpp # nppicc
    ]
  );

  build-system = [
    cmake
    setuptools
    torch
  ];
  dontUseCmakeConfigure = true;

  dependencies = [
    torch
  ];

  env = {
    # Upstream (Meta) is cautious with linking against GPL ffmpeg
    # We explicitly want to link against our packaged ffmpeg
    I_CONFIRM_THIS_IS_NOT_A_LICENSE_VIOLATION = true;

    ENABLE_CUDA = cudaSupport;
  };

  pythonImportsCheck = [ "torchcodec" ];

  nativeCheckInputs = [
    pytestCheckHook
    torchvision
  ];

  disabledTests =
    lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) [
      # AssertionError: index 0
      "test_get_frames_played_at"

      # AssertionError: Tensor-likes are not equal!
      "test_against_cli"
      "test_against_ref"
      "test_color_conversion_library"
      "test_color_conversion_library_with_dimension_order"
      "test_compile"
      "test_compile_seek_and_next"
      "test_create_decoder"
      "test_crop_transform"
      "test_custom_frame_mappings_json_and_bytes"
      "test_file_like_decoding"
      "test_get_frame_at"
      "test_get_frame_at_av1"
      "test_get_frame_at_index"
      "test_get_frame_at_pts"
      "test_get_frame_played_at"
      "test_get_frame_played_at_h265"
      "test_get_frame_with_info_at_index"
      "test_get_frames_at"
      "test_get_frames_at_indices"
      "test_get_frames_at_indices_negative_indices"
      "test_get_frames_by_pts_in_range"
      "test_get_frames_in_range"
      "test_get_frames_in_range_slice_indices_syntax"
      "test_get_frames_with_missing_num_frames_metadata"
      "test_getitem_int"
      "test_getitem_numpy_int"
      "test_getitem_slice"
      "test_iteration"
      "test_seek_and_next"
      "test_seek_mode_custom_frame_mappings"
      "test_seek_to_negative_pts"
      "test_throws_exception_at_eof"
    ]
    ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) [
      # RuntimeError: Invalid AVIO context holder
      "test_1d_samples"
      "test_against_cli"
      "test_against_to_file"
      "test_against_to_file"
      "test_contiguit"
      "test_crf_valid_value"
      "test_encode_to_tensor_long_outpu"
      "test_round_trip"
      "test_video_encoder_against_ffmpeg_cli"
      "test_video_encoder_round_trip"

      # RuntimeError: Requested next frame while there are no more frames left to decode
      "test_next"
      "test_throws_exception_at_eof"
      "test_throws_exception_if_seek_too_far"
    ];

  meta = {
    description = "PyTorch media decoding and encoding";
    homepage = "https://github.com/meta-pytorch/torchcodec";
    changelog = "https://github.com/meta-pytorch/torchcodec/releases/tag/${src.tag}";
    license = lib.licenses.bsd3;
    maintainers = with lib.maintainers; [ GaetanLepage ];
  };
}