Skip to content

Commit f93f4e7

Browse files
author
pytorchbot
committed
2025-04-02 nightly release (f4337de)
1 parent a2d3f72 commit f93f4e7

37 files changed

+202
-314
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.18)
22
project(TorchCodec)
33

4-
add_subdirectory(src/torchcodec/decoders/_core)
4+
add_subdirectory(src/torchcodec/_core)
55

66

77
option(BUILD_TESTS "Build tests" OFF)

benchmarks/decoders/benchmark_audio_decoders.py

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import subprocess
2-
31
from argparse import ArgumentParser
42
from datetime import timedelta
53
from pathlib import Path
@@ -46,30 +44,6 @@ def report_stats(times: Tensor, unit: str = "ms", prefix: str = "") -> float:
4644
)
4745

4846

49-
def get_duration(path: Path) -> str:
50-
try:
51-
result = subprocess.run(
52-
[
53-
"ffprobe",
54-
"-v",
55-
"error",
56-
"-show_entries",
57-
"format=duration",
58-
"-of",
59-
"default=noprint_wrappers=1:nokey=1",
60-
str(path),
61-
],
62-
stdout=subprocess.PIPE,
63-
stderr=subprocess.PIPE,
64-
text=True,
65-
)
66-
67-
# Remove microseconds
68-
return str(timedelta(seconds=float(result.stdout.strip()))).split(".")[0]
69-
except Exception:
70-
return "?"
71-
72-
7347
def decode_with_torchcodec(path: Path) -> None:
7448
AudioDecoder(path).get_all_samples()
7549

@@ -97,25 +71,31 @@ def decode_with_torchaudio_load(path: Path, backend: str) -> None:
9771
args = parser.parse_args()
9872
path = Path(args.path)
9973

74+
metadata = AudioDecoder(path).metadata
75+
duration = str(timedelta(seconds=metadata.duration_seconds_from_header)).split(".")[0]
10076

10177
print(
102-
f"Benchmarking {path.name}, duration: {get_duration(path)}, averaging over {args.num_exp} runs:"
78+
f"Benchmarking {path.name}, duration: {duration}, codec: {metadata.codec}, format: {metadata.sample_format}, averaging over {args.num_exp} runs:"
10379
)
10480

105-
times = bench(decode_with_torchcodec, path, num_exp=args.num_exp)
106-
report_stats(times, prefix="torchcodec.AudioDecoder")
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+
):
10796

108-
times = bench(decode_with_torchaudio_load, path, backend="ffmpeg", num_exp=args.num_exp)
109-
report_stats(times, prefix="torchaudio.load(backend='ffmpeg')")
110-
111-
prefix = "torchaudio.load(backend='sox')"
112-
try:
113-
times = bench(
114-
decode_with_torchaudio_load, path, backend="sox", num_exp=args.num_exp
115-
)
116-
report_stats(times, prefix=prefix)
117-
except RuntimeError:
118-
print(f"{prefix:<40} Not supported")
119-
120-
times = bench(decode_with_torchaudio_StreamReader, path, num_exp=args.num_exp)
121-
report_stats(times, prefix="torchaudio.StreamReader")
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")

benchmarks/decoders/benchmark_decoders_library.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313

1414
import torch
1515
import torch.utils.benchmark as benchmark
16-
from torchcodec.decoders import VideoDecoder, VideoStreamMetadata
1716

18-
from torchcodec.decoders._core import (
17+
from torchcodec._core import (
1918
_add_video_stream,
2019
create_from_file,
2120
get_frames_at_indices,
@@ -24,6 +23,7 @@
2423
get_next_frame,
2524
seek_to_pts,
2625
)
26+
from torchcodec.decoders import VideoDecoder, VideoStreamMetadata
2727

2828
torch._dynamo.config.cache_size_limit = 100
2929
torch._dynamo.config.capture_dynamic_output_shape_ops = True

benchmarks/decoders/gpu_benchmark.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def decode_full_video(video_path, decode_device_string, resize_device_string):
2525
# We use the core API instead of SimpleVideoDecoder because the core API
2626
# allows us to natively resize as part of the decode step.
2727
print(f"{decode_device_string=} {resize_device_string=}")
28-
decoder = torchcodec.decoders._core.create_from_file(video_path)
28+
decoder = torchcodec._core.create_from_file(video_path)
2929
num_threads = None
3030
if "cuda" in decode_device_string:
3131
num_threads = 1
@@ -34,7 +34,7 @@ def decode_full_video(video_path, decode_device_string, resize_device_string):
3434
if "native" in resize_device_string:
3535
width = RESIZED_WIDTH
3636
height = RESIZED_HEIGHT
37-
torchcodec.decoders._core._add_video_stream(
37+
torchcodec._core._add_video_stream(
3838
decoder,
3939
stream_index=-1,
4040
device=decode_device_string,
@@ -47,7 +47,7 @@ def decode_full_video(video_path, decode_device_string, resize_device_string):
4747
frame_count = 0
4848
while True:
4949
try:
50-
frame, *_ = torchcodec.decoders._core.get_next_frame(decoder)
50+
frame, *_ = torchcodec._core.get_next_frame(decoder)
5151
if resize_device_string != "none" and "native" not in resize_device_string:
5252
frame = transfer_and_resize_frame(frame, resize_device_string)
5353

benchmarks/decoders/memprofile_decoders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import torch
1111
from memory_profiler import profile
12-
from torchcodec.decoders._core import add_video_stream, create_from_file, get_next_frame
12+
from torchcodec._core import add_video_stream, create_from_file, get_next_frame
1313

1414
torch._dynamo.config.cache_size_limit = 100
1515
torch._dynamo.config.capture_dynamic_output_shape_ops = True

src/torchcodec/decoders/_core/AVIOBytesContext.cpp renamed to src/torchcodec/_core/AVIOBytesContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// This source code is licensed under the BSD-style license found in the
55
// LICENSE file in the root directory of this source tree.
66

7-
#include "src/torchcodec/decoders/_core/AVIOBytesContext.h"
7+
#include "src/torchcodec/_core/AVIOBytesContext.h"
88
#include <torch/types.h>
99

1010
namespace facebook::torchcodec {

src/torchcodec/decoders/_core/AVIOBytesContext.h renamed to src/torchcodec/_core/AVIOBytesContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#pragma once
88

9-
#include "src/torchcodec/decoders/_core/AVIOContextHolder.h"
9+
#include "src/torchcodec/_core/AVIOContextHolder.h"
1010

1111
namespace facebook::torchcodec {
1212

src/torchcodec/decoders/_core/AVIOContextHolder.cpp renamed to src/torchcodec/_core/AVIOContextHolder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// This source code is licensed under the BSD-style license found in the
55
// LICENSE file in the root directory of this source tree.
66

7-
#include "src/torchcodec/decoders/_core/AVIOContextHolder.h"
7+
#include "src/torchcodec/_core/AVIOContextHolder.h"
88
#include <torch/types.h>
99

1010
namespace facebook::torchcodec {

src/torchcodec/decoders/_core/AVIOContextHolder.h renamed to src/torchcodec/_core/AVIOContextHolder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#pragma once
88

9-
#include "src/torchcodec/decoders/_core/FFMPEGCommon.h"
9+
#include "src/torchcodec/_core/FFMPEGCommon.h"
1010

1111
namespace facebook::torchcodec {
1212

src/torchcodec/decoders/_core/AVIOFileLikeContext.cpp renamed to src/torchcodec/_core/AVIOFileLikeContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// This source code is licensed under the BSD-style license found in the
55
// LICENSE file in the root directory of this source tree.
66

7-
#include "src/torchcodec/decoders/_core/AVIOFileLikeContext.h"
7+
#include "src/torchcodec/_core/AVIOFileLikeContext.h"
88
#include <torch/types.h>
99

1010
namespace facebook::torchcodec {

0 commit comments

Comments
 (0)