Skip to content
Open
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
5 changes: 5 additions & 0 deletions src/torchcodec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import os.path as _osp

# Note: usort wants to put Frame and FrameBatch after decoders and samplers,
# but that results in circular import.
from ._core import core_library_path, variant
from ._frame import AudioSamples, Frame, FrameBatch # usort:skip # noqa
from . import decoders, samplers # noqa

Expand All @@ -14,3 +17,5 @@
from .version import __version__ # noqa: F401
except Exception:
pass

cmake_prefix_path = _osp.join(_osp.dirname(__file__), "share", "cmake")
2 changes: 1 addition & 1 deletion src/torchcodec/_core/AVIOContextHolder.cpp
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/_core/AVIOContextHolder.h"
#include "AVIOContextHolder.h"
#include <torch/types.h>

namespace facebook::torchcodec {
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/AVIOContextHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma once

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

namespace facebook::torchcodec {

Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/AVIOFileLikeContext.cpp
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/_core/AVIOFileLikeContext.h"
#include "AVIOFileLikeContext.h"
#include <torch/types.h>

namespace facebook::torchcodec {
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/AVIOFileLikeContext.h
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/_core/AVIOContextHolder.h"
#include "AVIOContextHolder.h"

namespace py = pybind11;

Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/AVIOTensorContext.cpp
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/_core/AVIOTensorContext.h"
#include "AVIOTensorContext.h"
#include <torch/types.h>

namespace facebook::torchcodec {
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/AVIOTensorContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#pragma once

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

namespace facebook::torchcodec {

Expand Down
14 changes: 7 additions & 7 deletions src/torchcodec/_core/BetaCudaDeviceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

#pragma once

#include "src/torchcodec/_core/CUDACommon.h"
#include "src/torchcodec/_core/Cache.h"
#include "src/torchcodec/_core/DeviceInterface.h"
#include "src/torchcodec/_core/FFMPEGCommon.h"
#include "src/torchcodec/_core/NVDECCache.h"
#include "CUDACommon.h"
#include "Cache.h"
#include "DeviceInterface.h"
#include "FFMPEGCommon.h"
#include "NVDECCache.h"

#include <map>
#include <memory>
Expand All @@ -28,8 +28,8 @@
#include <unordered_map>
#include <vector>

#include "src/torchcodec/_core/nvcuvid_include/cuviddec.h"
#include "src/torchcodec/_core/nvcuvid_include/nvcuvid.h"
#include "nvcuvid_include/cuviddec.h"
#include "nvcuvid_include/nvcuvid.h"

namespace facebook::torchcodec {

Expand Down
6 changes: 3 additions & 3 deletions src/torchcodec/_core/CUDACommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include <npp.h>
#include <torch/types.h>

#include "src/torchcodec/_core/Cache.h"
#include "src/torchcodec/_core/FFMPEGCommon.h"
#include "src/torchcodec/_core/Frame.h"
#include "Cache.h"
#include "FFMPEGCommon.h"
#include "Frame.h"

extern "C" {
#include <libavutil/hwcontext_cuda.h>
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/CpuDeviceInterface.cpp
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/_core/CpuDeviceInterface.h"
#include "CpuDeviceInterface.h"

namespace facebook::torchcodec {
namespace {
Expand Down
6 changes: 3 additions & 3 deletions src/torchcodec/_core/CpuDeviceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

#pragma once

#include "src/torchcodec/_core/DeviceInterface.h"
#include "src/torchcodec/_core/FFMPEGCommon.h"
#include "src/torchcodec/_core/FilterGraph.h"
#include "DeviceInterface.h"
#include "FFMPEGCommon.h"
#include "FilterGraph.h"

namespace facebook::torchcodec {

Expand Down
6 changes: 3 additions & 3 deletions src/torchcodec/_core/CudaDeviceInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <torch/types.h>
#include <mutex>

#include "src/torchcodec/_core/Cache.h"
#include "src/torchcodec/_core/CudaDeviceInterface.h"
#include "src/torchcodec/_core/FFMPEGCommon.h"
#include "Cache.h"
#include "CudaDeviceInterface.h"
#include "FFMPEGCommon.h"

extern "C" {
#include <libavutil/hwcontext_cuda.h>
Expand Down
6 changes: 3 additions & 3 deletions src/torchcodec/_core/CudaDeviceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

#pragma once

#include "src/torchcodec/_core/CUDACommon.h"
#include "src/torchcodec/_core/DeviceInterface.h"
#include "src/torchcodec/_core/FilterGraph.h"
#include "CUDACommon.h"
#include "DeviceInterface.h"
#include "FilterGraph.h"

namespace facebook::torchcodec {

Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/DeviceInterface.cpp
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/_core/DeviceInterface.h"
#include "DeviceInterface.h"
#include <map>
#include <mutex>

Expand Down
6 changes: 3 additions & 3 deletions src/torchcodec/_core/DeviceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include <stdexcept>
#include <string>
#include "FFMPEGCommon.h"
#include "src/torchcodec/_core/Frame.h"
#include "src/torchcodec/_core/StreamOptions.h"
#include "src/torchcodec/_core/Transform.h"
#include "Frame.h"
#include "StreamOptions.h"
#include "Transform.h"

namespace facebook::torchcodec {

Expand Down
4 changes: 2 additions & 2 deletions src/torchcodec/_core/Encoder.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <sstream>

#include "src/torchcodec/_core/AVIOTensorContext.h"
#include "src/torchcodec/_core/Encoder.h"
#include "AVIOTensorContext.h"
#include "Encoder.h"
#include "torch/types.h"

namespace facebook::torchcodec {
Expand Down
6 changes: 3 additions & 3 deletions src/torchcodec/_core/Encoder.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once
#include <torch/types.h>
#include "src/torchcodec/_core/AVIOContextHolder.h"
#include "src/torchcodec/_core/FFMPEGCommon.h"
#include "src/torchcodec/_core/StreamOptions.h"
#include "AVIOContextHolder.h"
#include "FFMPEGCommon.h"
#include "StreamOptions.h"

namespace facebook::torchcodec {
class AudioEncoder {
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/FFMPEGCommon.cpp
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/_core/FFMPEGCommon.h"
#include "FFMPEGCommon.h"

#include <c10/util/Exception.h>

Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/FilterGraph.cpp
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/_core/FilterGraph.h"
#include "FilterGraph.h"

extern "C" {
#include <libavfilter/buffersink.h>
Expand Down
4 changes: 2 additions & 2 deletions src/torchcodec/_core/FilterGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#pragma once

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

namespace facebook::torchcodec {

Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/Frame.cpp
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/_core/Frame.h"
#include "Frame.h"

namespace facebook::torchcodec {

Expand Down
6 changes: 3 additions & 3 deletions src/torchcodec/_core/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#pragma once

#include <torch/types.h>
#include "src/torchcodec/_core/FFMPEGCommon.h"
#include "src/torchcodec/_core/Metadata.h"
#include "src/torchcodec/_core/StreamOptions.h"
#include "FFMPEGCommon.h"
#include "Metadata.h"
#include "StreamOptions.h"

namespace facebook::torchcodec {

Expand Down
4 changes: 2 additions & 2 deletions src/torchcodec/_core/NVDECCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <mutex>

#include <cuda.h>
#include "src/torchcodec/_core/nvcuvid_include/cuviddec.h"
#include "src/torchcodec/_core/nvcuvid_include/nvcuvid.h"
#include "nvcuvid_include/cuviddec.h"
#include "nvcuvid_include/nvcuvid.h"

namespace facebook::torchcodec {

Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/SingleStreamDecoder.cpp
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/_core/SingleStreamDecoder.h"
#include "SingleStreamDecoder.h"
#include <cstdint>
#include <cstdio>
#include <iostream>
Expand Down
12 changes: 6 additions & 6 deletions src/torchcodec/_core/SingleStreamDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#include <ostream>
#include <string_view>

#include "src/torchcodec/_core/AVIOContextHolder.h"
#include "src/torchcodec/_core/DeviceInterface.h"
#include "src/torchcodec/_core/FFMPEGCommon.h"
#include "src/torchcodec/_core/Frame.h"
#include "src/torchcodec/_core/StreamOptions.h"
#include "src/torchcodec/_core/Transform.h"
#include "AVIOContextHolder.h"
#include "DeviceInterface.h"
#include "FFMPEGCommon.h"
#include "Frame.h"
#include "StreamOptions.h"
#include "Transform.h"

namespace facebook::torchcodec {

Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <optional>
#include <string>
#include "src/torchcodec/_core/Frame.h"
#include "Frame.h"

namespace facebook::torchcodec {

Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/ValidationUtils.cpp
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/_core/ValidationUtils.h"
#include "ValidationUtils.h"
#include <limits>
#include "c10/util/Exception.h"

Expand Down
2 changes: 2 additions & 0 deletions src/torchcodec/_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
_test_frame_pts_equality,
add_audio_stream,
add_video_stream,
core_library_path,
create_from_bytes,
create_from_file,
create_from_file_like,
Expand All @@ -38,4 +39,5 @@
get_next_frame,
scan_all_streams_to_update_metadata,
seek_to_pts,
variant,
)
10 changes: 5 additions & 5 deletions src/torchcodec/_core/custom_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#include <string>
#include "c10/core/SymIntArrayRef.h"
#include "c10/util/Exception.h"
#include "src/torchcodec/_core/AVIOFileLikeContext.h"
#include "src/torchcodec/_core/AVIOTensorContext.h"
#include "src/torchcodec/_core/Encoder.h"
#include "src/torchcodec/_core/SingleStreamDecoder.h"
#include "src/torchcodec/_core/ValidationUtils.h"
#include "AVIOFileLikeContext.h"
#include "AVIOTensorContext.h"
#include "Encoder.h"
#include "SingleStreamDecoder.h"
#include "ValidationUtils.h"

namespace facebook::torchcodec {

Expand Down
10 changes: 9 additions & 1 deletion src/torchcodec/_core/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import io
import json
import os
import warnings
from types import ModuleType
from typing import List, Optional, Tuple, Union
Expand All @@ -21,6 +22,8 @@

_pybind_ops: Optional[ModuleType] = None

variant = None
core_library_path = None

def load_torchcodec_shared_libraries():
# Successively try to load the shared libraries for each version of FFmpeg
Expand All @@ -47,14 +50,19 @@ def load_torchcodec_shared_libraries():
custom_ops_library_name = f"libtorchcodec_custom_ops{ffmpeg_major_version}"
pybind_ops_library_name = f"libtorchcodec_pybind_ops{ffmpeg_major_version}"
try:
torch.ops.load_library(_get_extension_path(decoder_library_name))
decoder_library_path = _get_extension_path(decoder_library_name)
torch.ops.load_library(decoder_library_path)
torch.ops.load_library(_get_extension_path(custom_ops_library_name))

pybind_ops_library_path = _get_extension_path(pybind_ops_library_name)
global _pybind_ops
_pybind_ops = _load_pybind11_module(
pybind_ops_module_name, pybind_ops_library_path
)
global variant
global core_library_path
variant = ffmpeg_major_version
core_library_path = decoder_library_path
return
except Exception as e:
# TODO: recording and reporting exceptions this way is OK for now as it's just for debugging,
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/pybind_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <pybind11/stl.h>
#include <cstdint>

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

namespace py = pybind11;

Expand Down
Loading