Skip to content

Commit 0eb7eb0

Browse files
authored
Move torchcodec/decoders/_core into torchcodec/_core (#609)
1 parent f416dcf commit 0eb7eb0

35 files changed

+52
-51
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_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 {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <pybind11/pybind11.h>
1010
#include <pybind11/stl.h>
1111

12-
#include "src/torchcodec/decoders/_core/AVIOContextHolder.h"
12+
#include "src/torchcodec/_core/AVIOContextHolder.h"
1313

1414
namespace py = pybind11;
1515

src/torchcodec/decoders/_core/CMakeLists.txt renamed to src/torchcodec/_core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function(make_torchcodec_sublibrary
2020
set_target_properties(${library_name} PROPERTIES CXX_STANDARD 17)
2121
target_include_directories(${library_name}
2222
PRIVATE
23-
./../../../../
23+
./../../../
2424
"${TORCH_INSTALL_PREFIX}/include"
2525
${Python3_INCLUDE_DIRS}
2626
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <torch/types.h>
2-
#include "src/torchcodec/decoders/_core/DeviceInterface.h"
2+
#include "src/torchcodec/_core/DeviceInterface.h"
33

44
namespace facebook::torchcodec {
55

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#include <torch/types.h>
55
#include <mutex>
66

7-
#include "src/torchcodec/decoders/_core/DeviceInterface.h"
8-
#include "src/torchcodec/decoders/_core/FFMPEGCommon.h"
9-
#include "src/torchcodec/decoders/_core/VideoDecoder.h"
7+
#include "src/torchcodec/_core/DeviceInterface.h"
8+
#include "src/torchcodec/_core/FFMPEGCommon.h"
9+
#include "src/torchcodec/_core/VideoDecoder.h"
1010

1111
extern "C" {
1212
#include <libavutil/hwcontext_cuda.h>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <stdexcept>
1212
#include <string>
1313
#include "FFMPEGCommon.h"
14-
#include "src/torchcodec/decoders/_core/VideoDecoder.h"
14+
#include "src/torchcodec/_core/VideoDecoder.h"
1515

1616
namespace facebook::torchcodec {
1717

src/torchcodec/decoders/_core/FFMPEGCommon.cpp renamed to src/torchcodec/_core/FFMPEGCommon.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/FFMPEGCommon.h"
7+
#include "src/torchcodec/_core/FFMPEGCommon.h"
88

99
#include <c10/util/Exception.h>
1010

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

Lines changed: 2 additions & 2 deletions
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/VideoDecoder.h"
7+
#include "src/torchcodec/_core/VideoDecoder.h"
88
#include <cstdint>
99
#include <cstdio>
1010
#include <cstdlib>
@@ -13,7 +13,7 @@
1313
#include <sstream>
1414
#include <stdexcept>
1515
#include <string_view>
16-
#include "src/torchcodec/decoders/_core/DeviceInterface.h"
16+
#include "src/torchcodec/_core/DeviceInterface.h"
1717
#include "torch/types.h"
1818

1919
extern "C" {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <ostream>
1313
#include <string_view>
1414

15-
#include "src/torchcodec/decoders/_core/AVIOContextHolder.h"
16-
#include "src/torchcodec/decoders/_core/FFMPEGCommon.h"
15+
#include "src/torchcodec/_core/AVIOContextHolder.h"
16+
#include "src/torchcodec/_core/FFMPEGCommon.h"
1717

1818
namespace facebook::torchcodec {
1919

src/torchcodec/decoders/_core/_metadata.py renamed to src/torchcodec/_core/_metadata.py

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

1313
import torch
1414

15-
from torchcodec.decoders._core.ops import (
15+
from torchcodec._core.ops import (
1616
_get_container_json_metadata,
1717
_get_stream_json_metadata,
1818
create_from_file,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include <string>
1111
#include "c10/core/SymIntArrayRef.h"
1212
#include "c10/util/Exception.h"
13-
#include "src/torchcodec/decoders/_core/AVIOBytesContext.h"
14-
#include "src/torchcodec/decoders/_core/VideoDecoder.h"
13+
#include "src/torchcodec/_core/AVIOBytesContext.h"
14+
#include "src/torchcodec/_core/VideoDecoder.h"
1515

1616
namespace facebook::torchcodec {
1717

@@ -25,7 +25,7 @@ namespace facebook::torchcodec {
2525
// https://github.com/pytorch/pytorch/tree/main/aten/src/ATen/native#readme
2626
TORCH_LIBRARY(torchcodec_ns, m) {
2727
m.impl_abstract_pystub(
28-
"torchcodec.decoders._core.ops", "//pytorch/torchcodec:torchcodec");
28+
"torchcodec._core.ops", "//pytorch/torchcodec:torchcodec");
2929
m.def("create_from_file(str filename, str? seek_mode=None) -> Tensor");
3030
m.def(
3131
"create_from_tensor(Tensor video_tensor, str? seek_mode=None) -> Tensor");
File renamed without changes.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include <cstdint>
1010
#include <string>
1111

12-
#include "src/torchcodec/decoders/_core/AVIOFileLikeContext.h"
13-
#include "src/torchcodec/decoders/_core/VideoDecoder.h"
12+
#include "src/torchcodec/_core/AVIOFileLikeContext.h"
13+
#include "src/torchcodec/_core/VideoDecoder.h"
1414

1515
namespace py = pybind11;
1616

src/torchcodec/_samplers/video_clip_sampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import torch
1414
from torch import nn, Tensor
1515

16-
from torchcodec.decoders._core import (
16+
from torchcodec._core import (
1717
add_video_stream,
1818
create_from_tensor,
1919
get_frames_at_indices,

src/torchcodec/decoders/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
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+
from .._core import AudioStreamMetadata, VideoStreamMetadata
78
from ._audio_decoder import AudioDecoder # noqa
8-
from ._core import AudioStreamMetadata, VideoStreamMetadata
99
from ._video_decoder import VideoDecoder # noqa
1010

1111
SimpleVideoDecoder = VideoDecoder

src/torchcodec/decoders/_audio_decoder.py

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

1010
from torch import Tensor
1111

12-
from torchcodec import AudioSamples
13-
from torchcodec.decoders import _core as core
12+
from torchcodec import _core as core, AudioSamples
1413
from torchcodec.decoders._decoder_utils import (
1514
create_decoder,
1615
ERROR_REPORTING_INSTRUCTIONS,

src/torchcodec/decoders/_decoder_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import Union
1010

1111
from torch import Tensor
12-
from torchcodec.decoders import _core as core
12+
from torchcodec import _core as core
1313

1414
ERROR_REPORTING_INSTRUCTIONS = """
1515
This should never happen. Please report an issue following the steps in

src/torchcodec/decoders/_video_decoder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
from torch import device, Tensor
1212

13-
from torchcodec import Frame, FrameBatch
14-
from torchcodec.decoders import _core as core
13+
from torchcodec import _core as core, Frame, FrameBatch
1514
from torchcodec.decoders._decoder_utils import (
1615
create_decoder,
1716
ERROR_REPORTING_INSTRUCTIONS,

test/decoders/VideoDecoderTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
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/VideoDecoder.h"
8-
#include "src/torchcodec/decoders/_core/AVIOBytesContext.h"
7+
#include "src/torchcodec/_core/VideoDecoder.h"
8+
#include "src/torchcodec/_core/AVIOBytesContext.h"
99

1010
#include <c10/util/Flags.h>
1111
#include <gtest/gtest.h>

test/decoders/manual_smoke_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
print(f"{torchcodec.__version__ = }")
1313

14-
decoder = torchcodec.decoders._core.create_from_file(
14+
decoder = torchcodec._core.create_from_file(
1515
str(Path(__file__).parent / "../resources/nasa_13013.mp4")
1616
)
17-
torchcodec.decoders._core.scan_all_streams_to_update_metadata(decoder)
18-
torchcodec.decoders._core.add_video_stream(decoder, stream_index=3)
19-
frame, _, _ = torchcodec.decoders._core.get_frame_at_index(decoder, frame_index=180)
17+
torchcodec._core.scan_all_streams_to_update_metadata(decoder)
18+
torchcodec._core.add_video_stream(decoder, stream_index=3)
19+
frame, _, _ = torchcodec._core.get_frame_at_index(decoder, frame_index=180)
2020
write_png(frame, "frame180.png")

test/decoders/test_decoders.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
import numpy
1010
import pytest
1111
import torch
12-
from torchcodec import FrameBatch
1312

14-
from torchcodec.decoders import _core, VideoDecoder, VideoStreamMetadata
15-
from torchcodec.decoders._audio_decoder import AudioDecoder
16-
from torchcodec.decoders._core._metadata import AudioStreamMetadata
13+
from torchcodec import _core, FrameBatch
14+
from torchcodec.decoders import (
15+
AudioDecoder,
16+
AudioStreamMetadata,
17+
VideoDecoder,
18+
VideoStreamMetadata,
19+
)
1720

1821
from ..utils import (
1922
assert_frames_equal,

test/decoders/test_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
import functools
88

99
import pytest
10-
from torchcodec.decoders import AudioDecoder, VideoDecoder
1110

12-
from torchcodec.decoders._core import (
11+
from torchcodec._core import (
1312
AudioStreamMetadata,
1413
create_from_file,
1514
get_container_metadata,
1615
get_container_metadata_from_header,
1716
get_ffmpeg_library_versions,
1817
VideoStreamMetadata,
1918
)
19+
from torchcodec.decoders import AudioDecoder, VideoDecoder
2020

2121
from ..utils import NASA_AUDIO_MP3, NASA_VIDEO
2222

test/decoders/test_ops.py

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

1717
import torch
1818

19-
from torchcodec.decoders._core import (
19+
from torchcodec._core import (
2020
_add_video_stream,
2121
_test_frame_pts_equality,
2222
add_audio_stream,

test/utils.py

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

1313
import torch
1414

15-
from torchcodec.decoders._core import get_ffmpeg_library_versions
15+
from torchcodec._core import get_ffmpeg_library_versions
1616

1717

1818
# Decorator for skipping CUDA tests when CUDA isn't available. The tests are

0 commit comments

Comments
 (0)