Skip to content

Commit a1532c9

Browse files
committed
Merge branch 'main' of github.com:pytorch/torchcodec into encoding_yolo
2 parents 0906fb3 + cb50bbf commit a1532c9

File tree

73 files changed

+10996
-896
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+10996
-896
lines changed

.github/workflows/build_ffmpeg.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
contents: read
3535
with:
3636
job-name: Build
37-
upload-artifact: ffmpeg-lgpl
37+
upload-artifact: ffmpeg-lgpl-linux_x86_64-${{ matrix.ffmpeg-version }}
3838
repository: pytorch/torchcodec
3939
script: |
4040
export FFMPEG_VERSION="${{ matrix.ffmpeg-version }}"
@@ -56,7 +56,7 @@ jobs:
5656
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
5757
with:
5858
job-name: Build
59-
upload-artifact: ffmpeg-lgpl
59+
upload-artifact: ffmpeg-lgpl-macos-${{ matrix.ffmpeg-version }}
6060
repository: pytorch/torchcodec
6161
runner: macos-14-xlarge
6262
script: |

.github/workflows/cpp_tests.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ jobs:
3434
python-version: '3.12'
3535
- name: Update pip
3636
run: python -m pip install --upgrade pip
37-
- name: Install dependencies
37+
- name: Install torch dependencies
3838
run: |
3939
python -m pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu
40-
- name: Install ffmpeg and pkg-config
40+
- name: Install ffmpeg, pkg-config and pybind11
4141
run: |
42-
conda install "ffmpeg=${{ matrix.ffmpeg-version-for-tests }}" pkg-config -c conda-forge
42+
conda install "ffmpeg=${{ matrix.ffmpeg-version-for-tests }}" pkg-config pybind11 -c conda-forge
4343
ffmpeg -version
4444
- name: Build and run C++ tests
4545
run: |

.github/workflows/docs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
test-infra-repository: pytorch/test-infra
3939
test-infra-ref: main
4040
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
41+
pre-script: packaging/pre_build_script.sh
4142
post-script: packaging/post_build_script.sh
4243
smoke-test-script: packaging/fake_smoke_test.py
4344
package-name: torchcodec

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
- name: Install dependencies and FFmpeg
6464
run: |
6565
python -m pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu
66-
conda install "ffmpeg=7.0.1" pkg-config -c conda-forge
66+
conda install "ffmpeg=7.0.1" pkg-config pybind11 -c conda-forge
6767
ffmpeg -version
6868
- name: Build and install torchcodec
6969
run: |

.github/workflows/linux_cuda_wheel.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
test-infra-repository: pytorch/test-infra
4949
test-infra-ref: main
5050
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
51+
pre-script: packaging/pre_build_script.sh
5152
post-script: packaging/post_build_script.sh
5253
smoke-test-script: packaging/fake_smoke_test.py
5354
package-name: torchcodec
@@ -66,7 +67,7 @@ jobs:
6667
# For the actual release we should add that label and change this to
6768
# include more python versions.
6869
python-version: ['3.9']
69-
cuda-version: ['11.8', '12.6']
70+
cuda-version: ['11.8', '12.6', '12.8']
7071
# TODO: put back ffmpeg 5 https://github.com/pytorch/torchcodec/issues/325
7172
ffmpeg-version-for-tests: ['4.4.2', '6', '7']
7273

.github/workflows/linux_wheel.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ jobs:
4949
test-infra-repository: pytorch/test-infra
5050
test-infra-ref: main
5151
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
52+
pre-script: packaging/pre_build_script.sh
5253
post-script: packaging/post_build_script.sh
5354
smoke-test-script: packaging/fake_smoke_test.py
5455
package-name: torchcodec

.github/workflows/macos_wheel.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ jobs:
4949
test-infra-repository: pytorch/test-infra
5050
test-infra-ref: main
5151
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
52+
pre-script: packaging/pre_build_script.sh
5253
post-script: packaging/post_build_script.sh
5354
smoke-test-script: packaging/fake_smoke_test.py
5455
runner-type: macos-m1-stable

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ test locally you will need the following dependencies:
2020
installation already.
2121
- cmake
2222
- pkg-config
23+
- pybind11
2324
- FFmpeg
2425
- PyTorch nightly
2526

@@ -29,7 +30,7 @@ Start by installing the **nightly** build of PyTorch following the
2930
Then, the easiest way to install the rest of the dependencies is to run:
3031

3132
```bash
32-
conda install cmake pkg-config ffmpeg -c conda-forge
33+
conda install cmake pkg-config pybind11 ffmpeg -c conda-forge
3334
```
3435

3536
### Clone and build

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ format you want. Refer to Nvidia's GPU support matrix for more details
152152
the CUDA Toolkit.
153153

154154
2. Install or compile FFmpeg with NVDEC support.
155-
TorchCodec with CUDA should work with FFmpeg versions in [5, 7].
155+
TorchCodec with CUDA should work with FFmpeg versions in [4, 7].
156156

157157
If FFmpeg is not already installed, or you need a more recent version, an
158158
easy way to install it is to use `conda`:
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
from argparse import ArgumentParser
2+
from datetime import timedelta
3+
from pathlib import Path
4+
from time import perf_counter_ns
5+
6+
import torch
7+
import torchaudio
8+
from torch import Tensor
9+
from torchaudio.io import StreamReader
10+
from torchcodec.decoders._audio_decoder import AudioDecoder
11+
12+
DEFAULT_NUM_EXP = 30
13+
14+
15+
def bench(f, *args, num_exp=DEFAULT_NUM_EXP, warmup=1, **kwargs) -> Tensor:
16+
17+
for _ in range(warmup):
18+
f(*args, **kwargs)
19+
20+
times = []
21+
for _ in range(num_exp):
22+
start = perf_counter_ns()
23+
f(*args, **kwargs)
24+
end = perf_counter_ns()
25+
times.append(end - start)
26+
return torch.tensor(times).float()
27+
28+
29+
def report_stats(times: Tensor, unit: str = "ms", prefix: str = "") -> float:
30+
mul = {
31+
"ns": 1,
32+
"µs": 1e-3,
33+
"ms": 1e-6,
34+
"s": 1e-9,
35+
}[unit]
36+
times = times * mul
37+
std = times.std().item()
38+
med = times.median().item()
39+
mean = times.mean().item()
40+
min = times.min().item()
41+
max = times.max().item()
42+
print(
43+
f"{prefix:<40} {med = :.2f}, {mean = :.2f} +- {std:.2f}, {min = :.2f}, {max = :.2f} - in {unit}"
44+
)
45+
46+
47+
def decode_with_torchcodec(path: Path) -> None:
48+
AudioDecoder(path).get_all_samples()
49+
50+
51+
def decode_with_torchaudio_StreamReader(path: Path) -> None:
52+
reader = StreamReader(path)
53+
reader.add_audio_stream(frames_per_chunk=1024)
54+
for _ in reader.stream():
55+
pass
56+
57+
58+
def decode_with_torchaudio_load(path: Path, backend: str) -> None:
59+
torchaudio.load(str(path), backend=backend)
60+
61+
62+
parser = ArgumentParser()
63+
parser.add_argument("--path", type=str, help="path to file", required=True)
64+
parser.add_argument(
65+
"--num-exp",
66+
type=int,
67+
default=DEFAULT_NUM_EXP,
68+
help="number of runs to average over",
69+
)
70+
71+
args = parser.parse_args()
72+
path = Path(args.path)
73+
74+
metadata = AudioDecoder(path).metadata
75+
duration = str(timedelta(seconds=metadata.duration_seconds_from_header)).split(".")[0]
76+
77+
print(
78+
f"Benchmarking {path.name}, duration: {duration}, codec: {metadata.codec}, format: {metadata.sample_format}, averaging over {args.num_exp} runs:"
79+
)
80+
81+
for decode_f, kwargs, prefix in (
82+
(decode_with_torchcodec, {}, "torchcodec.AudioDecoder"),
83+
(
84+
decode_with_torchaudio_load,
85+
{"backend": "ffmpeg"},
86+
"torchaudio.load(backend='ffmpeg')",
87+
),
88+
(decode_with_torchaudio_load, {"backend": "sox"}, "torchaudio.load(backend='sox')"),
89+
(
90+
decode_with_torchaudio_load,
91+
{"backend": "soundfile"},
92+
"torchaudio.load(backend='soundfile')",
93+
),
94+
(decode_with_torchaudio_StreamReader, {}, "torchaudio.StreamReader"),
95+
):
96+
97+
try:
98+
times = bench(decode_f, path, **kwargs, num_exp=args.num_exp)
99+
report_stats(times, prefix=prefix)
100+
except RuntimeError:
101+
print(f"{prefix:<40} Not supported")

0 commit comments

Comments
 (0)