Skip to content

Move torchcodec/decoders/_core into torchcodec/_core #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.18)
project(TorchCodec)

add_subdirectory(src/torchcodec/decoders/_core)
add_subdirectory(src/torchcodec/_core)


option(BUILD_TESTS "Build tests" OFF)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/decoders/benchmark_decoders_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

import torch
import torch.utils.benchmark as benchmark
from torchcodec.decoders import VideoDecoder, VideoStreamMetadata

from torchcodec.decoders._core import (
from torchcodec._core import (
_add_video_stream,
create_from_file,
get_frames_at_indices,
Expand All @@ -24,6 +23,7 @@
get_next_frame,
seek_to_pts,
)
from torchcodec.decoders import VideoDecoder, VideoStreamMetadata

torch._dynamo.config.cache_size_limit = 100
torch._dynamo.config.capture_dynamic_output_shape_ops = True
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/decoders/gpu_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def decode_full_video(video_path, decode_device_string, resize_device_string):
# We use the core API instead of SimpleVideoDecoder because the core API
# allows us to natively resize as part of the decode step.
print(f"{decode_device_string=} {resize_device_string=}")
decoder = torchcodec.decoders._core.create_from_file(video_path)
decoder = torchcodec._core.create_from_file(video_path)
num_threads = None
if "cuda" in decode_device_string:
num_threads = 1
Expand All @@ -34,7 +34,7 @@ def decode_full_video(video_path, decode_device_string, resize_device_string):
if "native" in resize_device_string:
width = RESIZED_WIDTH
height = RESIZED_HEIGHT
torchcodec.decoders._core._add_video_stream(
torchcodec._core._add_video_stream(
decoder,
stream_index=-1,
device=decode_device_string,
Expand All @@ -47,7 +47,7 @@ def decode_full_video(video_path, decode_device_string, resize_device_string):
frame_count = 0
while True:
try:
frame, *_ = torchcodec.decoders._core.get_next_frame(decoder)
frame, *_ = torchcodec._core.get_next_frame(decoder)
if resize_device_string != "none" and "native" not in resize_device_string:
frame = transfer_and_resize_frame(frame, resize_device_string)

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/decoders/memprofile_decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import torch
from memory_profiler import profile
from torchcodec.decoders._core import add_video_stream, create_from_file, get_next_frame
from torchcodec._core import add_video_stream, create_from_file, get_next_frame

torch._dynamo.config.cache_size_limit = 100
torch._dynamo.config.capture_dynamic_output_shape_ops = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

#include "src/torchcodec/decoders/_core/AVIOBytesContext.h"
#include "src/torchcodec/_core/AVIOBytesContext.h"
#include <torch/types.h>

namespace facebook::torchcodec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma once

#include "src/torchcodec/decoders/_core/AVIOContextHolder.h"
#include "src/torchcodec/_core/AVIOContextHolder.h"

namespace facebook::torchcodec {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

#include "src/torchcodec/decoders/_core/AVIOContextHolder.h"
#include "src/torchcodec/_core/AVIOContextHolder.h"
#include <torch/types.h>

namespace facebook::torchcodec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma once

#include "src/torchcodec/decoders/_core/FFMPEGCommon.h"
#include "src/torchcodec/_core/FFMPEGCommon.h"

namespace facebook::torchcodec {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

#include "src/torchcodec/decoders/_core/AVIOFileLikeContext.h"
#include "src/torchcodec/_core/AVIOFileLikeContext.h"
#include <torch/types.h>

namespace facebook::torchcodec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include "src/torchcodec/decoders/_core/AVIOContextHolder.h"
#include "src/torchcodec/_core/AVIOContextHolder.h"

namespace py = pybind11;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function(make_torchcodec_sublibrary
set_target_properties(${library_name} PROPERTIES CXX_STANDARD 17)
target_include_directories(${library_name}
PRIVATE
./../../../../
./../../../
"${TORCH_INSTALL_PREFIX}/include"
${Python3_INCLUDE_DIRS}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <torch/types.h>
#include "src/torchcodec/decoders/_core/DeviceInterface.h"
#include "src/torchcodec/_core/DeviceInterface.h"

namespace facebook::torchcodec {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <torch/types.h>
#include <mutex>

#include "src/torchcodec/decoders/_core/DeviceInterface.h"
#include "src/torchcodec/decoders/_core/FFMPEGCommon.h"
#include "src/torchcodec/decoders/_core/VideoDecoder.h"
#include "src/torchcodec/_core/DeviceInterface.h"
#include "src/torchcodec/_core/FFMPEGCommon.h"
#include "src/torchcodec/_core/VideoDecoder.h"

extern "C" {
#include <libavutil/hwcontext_cuda.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <stdexcept>
#include <string>
#include "FFMPEGCommon.h"
#include "src/torchcodec/decoders/_core/VideoDecoder.h"
#include "src/torchcodec/_core/VideoDecoder.h"

namespace facebook::torchcodec {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

#include "src/torchcodec/decoders/_core/FFMPEGCommon.h"
#include "src/torchcodec/_core/FFMPEGCommon.h"

#include <c10/util/Exception.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

#include "src/torchcodec/decoders/_core/VideoDecoder.h"
#include "src/torchcodec/_core/VideoDecoder.h"
#include <cstdint>
#include <cstdio>
#include <cstdlib>
Expand All @@ -13,7 +13,7 @@
#include <sstream>
#include <stdexcept>
#include <string_view>
#include "src/torchcodec/decoders/_core/DeviceInterface.h"
#include "src/torchcodec/_core/DeviceInterface.h"
#include "torch/types.h"

extern "C" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <ostream>
#include <string_view>

#include "src/torchcodec/decoders/_core/AVIOContextHolder.h"
#include "src/torchcodec/decoders/_core/FFMPEGCommon.h"
#include "src/torchcodec/_core/AVIOContextHolder.h"
#include "src/torchcodec/_core/FFMPEGCommon.h"

namespace facebook::torchcodec {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import torch

from torchcodec.decoders._core.ops import (
from torchcodec._core.ops import (
_get_container_json_metadata,
_get_stream_json_metadata,
create_from_file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <string>
#include "c10/core/SymIntArrayRef.h"
#include "c10/util/Exception.h"
#include "src/torchcodec/decoders/_core/AVIOBytesContext.h"
#include "src/torchcodec/decoders/_core/VideoDecoder.h"
#include "src/torchcodec/_core/AVIOBytesContext.h"
#include "src/torchcodec/_core/VideoDecoder.h"

namespace facebook::torchcodec {

Expand All @@ -25,7 +25,7 @@ namespace facebook::torchcodec {
// https://github.com/pytorch/pytorch/tree/main/aten/src/ATen/native#readme
TORCH_LIBRARY(torchcodec_ns, m) {
m.impl_abstract_pystub(
"torchcodec.decoders._core.ops", "//pytorch/torchcodec:torchcodec");
"torchcodec._core.ops", "//pytorch/torchcodec:torchcodec");
m.def("create_from_file(str filename, str? seek_mode=None) -> Tensor");
m.def(
"create_from_tensor(Tensor video_tensor, str? seek_mode=None) -> Tensor");
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <cstdint>
#include <string>

#include "src/torchcodec/decoders/_core/AVIOFileLikeContext.h"
#include "src/torchcodec/decoders/_core/VideoDecoder.h"
#include "src/torchcodec/_core/AVIOFileLikeContext.h"
#include "src/torchcodec/_core/VideoDecoder.h"

namespace py = pybind11;

Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_samplers/video_clip_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import torch
from torch import nn, Tensor

from torchcodec.decoders._core import (
from torchcodec._core import (
add_video_stream,
create_from_tensor,
get_frames_at_indices,
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/decoders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

from .._core import AudioStreamMetadata, VideoStreamMetadata
from ._audio_decoder import AudioDecoder # noqa
from ._core import AudioStreamMetadata, VideoStreamMetadata
from ._video_decoder import VideoDecoder # noqa

SimpleVideoDecoder = VideoDecoder
3 changes: 1 addition & 2 deletions src/torchcodec/decoders/_audio_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

from torch import Tensor

from torchcodec import AudioSamples
from torchcodec.decoders import _core as core
from torchcodec import _core as core, AudioSamples
from torchcodec.decoders._decoder_utils import (
create_decoder,
ERROR_REPORTING_INSTRUCTIONS,
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/decoders/_decoder_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Union

from torch import Tensor
from torchcodec.decoders import _core as core
from torchcodec import _core as core

ERROR_REPORTING_INSTRUCTIONS = """
This should never happen. Please report an issue following the steps in
Expand Down
3 changes: 1 addition & 2 deletions src/torchcodec/decoders/_video_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

from torch import device, Tensor

from torchcodec import Frame, FrameBatch
from torchcodec.decoders import _core as core
from torchcodec import _core as core, Frame, FrameBatch
from torchcodec.decoders._decoder_utils import (
create_decoder,
ERROR_REPORTING_INSTRUCTIONS,
Expand Down
4 changes: 2 additions & 2 deletions test/decoders/VideoDecoderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

#include "src/torchcodec/decoders/_core/VideoDecoder.h"
#include "src/torchcodec/decoders/_core/AVIOBytesContext.h"
#include "src/torchcodec/_core/VideoDecoder.h"
#include "src/torchcodec/_core/AVIOBytesContext.h"

#include <c10/util/Flags.h>
#include <gtest/gtest.h>
Expand Down
8 changes: 4 additions & 4 deletions test/decoders/manual_smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

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

decoder = torchcodec.decoders._core.create_from_file(
decoder = torchcodec._core.create_from_file(
str(Path(__file__).parent / "../resources/nasa_13013.mp4")
)
torchcodec.decoders._core.scan_all_streams_to_update_metadata(decoder)
torchcodec.decoders._core.add_video_stream(decoder, stream_index=3)
frame, _, _ = torchcodec.decoders._core.get_frame_at_index(decoder, frame_index=180)
torchcodec._core.scan_all_streams_to_update_metadata(decoder)
torchcodec._core.add_video_stream(decoder, stream_index=3)
frame, _, _ = torchcodec._core.get_frame_at_index(decoder, frame_index=180)
write_png(frame, "frame180.png")
11 changes: 7 additions & 4 deletions test/decoders/test_decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import numpy
import pytest
import torch
from torchcodec import FrameBatch

from torchcodec.decoders import _core, VideoDecoder, VideoStreamMetadata
from torchcodec.decoders._audio_decoder import AudioDecoder
from torchcodec.decoders._core._metadata import AudioStreamMetadata
from torchcodec import _core, FrameBatch
from torchcodec.decoders import (
AudioDecoder,
AudioStreamMetadata,
VideoDecoder,
VideoStreamMetadata,
)

from ..utils import (
assert_frames_equal,
Expand Down
4 changes: 2 additions & 2 deletions test/decoders/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import functools

import pytest
from torchcodec.decoders import AudioDecoder, VideoDecoder

from torchcodec.decoders._core import (
from torchcodec._core import (
AudioStreamMetadata,
create_from_file,
get_container_metadata,
get_container_metadata_from_header,
get_ffmpeg_library_versions,
VideoStreamMetadata,
)
from torchcodec.decoders import AudioDecoder, VideoDecoder

from ..utils import NASA_AUDIO_MP3, NASA_VIDEO

Expand Down
2 changes: 1 addition & 1 deletion test/decoders/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import torch

from torchcodec.decoders._core import (
from torchcodec._core import (
_add_video_stream,
_test_frame_pts_equality,
add_audio_stream,
Expand Down
2 changes: 1 addition & 1 deletion test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import torch

from torchcodec.decoders._core import get_ffmpeg_library_versions
from torchcodec._core import get_ffmpeg_library_versions


# Decorator for skipping CUDA tests when CUDA isn't available. The tests are
Expand Down
Loading