Skip to content
Draft
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
4 changes: 1 addition & 3 deletions .github/scripts/setup-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ case $(uname) in
esac

echo '::group::Create build environment'
# See https://github.com/pytorch/vision/issues/7296 for ffmpeg
conda create \
--name ci \
--quiet --yes \
python="${PYTHON_VERSION}" pip \
ninja cmake \
libpng \
libwebp \
'ffmpeg<4.3'
libwebp
conda activate ci
conda install --quiet --yes libjpeg-turbo -c pytorch
pip install --progress-bar=off --upgrade setuptools==72.1.0
Expand Down
3 changes: 1 addition & 2 deletions .github/scripts/unittest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ echo '::endgroup::'

python test/smoke_test.py

# We explicitly ignore the video tests until we resolve https://github.com/pytorch/vision/issues/8162
pytest --ignore-glob="*test_video*" --ignore-glob="*test_onnx*" --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25 -k "not TestFxFeatureExtraction"
pytest --ignore-glob="*test_onnx*" --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25 -k "not TestFxFeatureExtraction"
6 changes: 0 additions & 6 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ jobs:
CONDA_PATH=$(which conda)
eval "$(${CONDA_PATH} shell.bash hook)"
conda activate ci
# FIXME: not sure why we need this. `ldd torchvision/video_reader.so` shows that it
# already links against the one pulled from conda. However, at runtime it pulls from
# /lib64
# Should we maybe always do this in `./.github/scripts/setup-env.sh` so that we don't
# have to pay attention in all other workflows?
export LD_LIBRARY_PATH="${CONDA_PREFIX}/lib:${LD_LIBRARY_PATH}"

cd docs

Expand Down
23 changes: 4 additions & 19 deletions docs/source/io.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Decoding / Encoding images and videos
=====================================
Decoding / Encoding images
==========================

.. currentmodule:: torchvision.io

The :mod:`torchvision.io` module provides utilities for decoding and encoding
images and videos.
images.

Image Decoding
--------------
Expand Down Expand Up @@ -92,7 +92,7 @@ Video - DEPREACTED
.. warning::

DEPRECATED: All the video decoding and encoding capabilities of torchvision
are deprecated from version 0.22 and will be removed in version 0.24. We
are deprecated from version 0.22 and will be removed in version 0.25. We
recommend that you migrate to
`TorchCodec <https://github.com/pytorch/torchcodec>`__, where we'll
consolidate the future decoding/encoding capabilities of PyTorch
Expand All @@ -101,19 +101,4 @@ Video - DEPREACTED
:toctree: generated/
:template: function.rst

read_video
read_video_timestamps
write_video


**Fine-grained video API**

In addition to the :mod:`read_video` function, we provide a high-performance
lower-level API for more fine-grained control compared to the :mod:`read_video` function.
It does all this whilst fully supporting torchscript.

.. autosummary::
:toctree: generated/
:template: class.rst

VideoReader
4 changes: 0 additions & 4 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ ignore_errors = True

ignore_errors = True

[mypy-torchvision.io.video_reader]

ignore_errors = True

[mypy-torchvision.models.*]

ignore_errors=True
Expand Down
3 changes: 1 addition & 2 deletions packaging/pre_build_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ if [[ "$(uname)" == Darwin || "$OSTYPE" == "msys" ]]; then
# Installing webp also installs a non-turbo jpeg, so we uninstall jpeg stuff
# before re-installing them
conda uninstall libjpeg-turbo libjpeg -y
conda install -y ffmpeg=4.2 -c pytorch
conda install -y libjpeg-turbo -c pytorch

# Copy binaries to be included in the wheel distribution
Expand All @@ -30,7 +29,7 @@ else

if [[ "$ARCH" == "aarch64" ]]; then
conda install libpng -y
conda install -y ffmpeg=4.2 libjpeg-turbo -c pytorch-nightly
conda install -y libjpeg-turbo -c pytorch-nightly
fi

conda install libwebp -y
Expand Down
10 changes: 6 additions & 4 deletions packaging/wheel/relocate.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,9 @@ def patch_linux():
output_dir = osp.join(PACKAGE_ROOT, "dist", ".wheel-process")

image_binary = "image.so"
video_binary = "video_reader.so"
torchvision_binaries = [image_binary, video_binary]
torchvision_binaries = [
image_binary,
]
for wheel in wheels:
if osp.exists(output_dir):
shutil.rmtree(output_dir)
Expand Down Expand Up @@ -352,8 +353,9 @@ def patch_win():
output_dir = osp.join(PACKAGE_ROOT, "dist", ".wheel-process")

image_binary = "image.pyd"
video_binary = "video_reader.pyd"
torchvision_binaries = [image_binary, video_binary]
torchvision_binaries = [
image_binary,
]
for wheel in wheels:
if osp.exists(output_dir):
shutil.rmtree(output_dir)
Expand Down
163 changes: 0 additions & 163 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@
USE_WEBP = os.getenv("TORCHVISION_USE_WEBP", "1") == "1"
USE_NVJPEG = os.getenv("TORCHVISION_USE_NVJPEG", "1") == "1"
NVCC_FLAGS = os.getenv("NVCC_FLAGS", None)
# Note: the GPU video decoding stuff used to be called "video codec", which
# isn't an accurate or descriptive name considering there are at least 2 other
# video decoding backends in torchvision. I'm renaming this to "gpu video
# decoder" where possible, keeping user facing names (like the env var below) to
# the old scheme for BC.
USE_GPU_VIDEO_DECODER = os.getenv("TORCHVISION_USE_VIDEO_CODEC", "1") == "1"
# Same here: "use ffmpeg" was used to denote "use cpu video decoder".
USE_CPU_VIDEO_DECODER = os.getenv("TORCHVISION_USE_FFMPEG", "1") == "1"

TORCHVISION_INCLUDE = os.environ.get("TORCHVISION_INCLUDE", "")
TORCHVISION_LIBRARY = os.environ.get("TORCHVISION_LIBRARY", "")
Expand All @@ -52,8 +44,6 @@
print(f"{USE_WEBP = }")
print(f"{USE_NVJPEG = }")
print(f"{NVCC_FLAGS = }")
print(f"{USE_CPU_VIDEO_DECODER = }")
print(f"{USE_GPU_VIDEO_DECODER = }")
print(f"{TORCHVISION_INCLUDE = }")
print(f"{TORCHVISION_LIBRARY = }")
print(f"{IS_ROCM = }")
Expand Down Expand Up @@ -371,158 +361,6 @@ def make_image_extension():
)


def make_video_decoders_extensions():
print("Building video decoder extensions")

build_without_extensions_msg = "Building without video decoders extensions."
if sys.platform != "linux" or (sys.version_info.major == 3 and sys.version_info.minor == 9):
# FIXME: Building torchvision with ffmpeg on MacOS or with Python 3.9
# FIXME: causes crash. See the following GitHub issues for more details.
# FIXME: https://github.com/pytorch/pytorch/issues/65000
# FIXME: https://github.com/pytorch/vision/issues/3367
print("Can only build video decoder extensions on linux and Python != 3.9")
return []

ffmpeg_exe = shutil.which("ffmpeg")
if ffmpeg_exe is None:
print(f"{build_without_extensions_msg} Couldn't find ffmpeg binary.")
return []

def find_ffmpeg_libraries():
ffmpeg_libraries = {"libavcodec", "libavformat", "libavutil", "libswresample", "libswscale"}

ffmpeg_bin = os.path.dirname(ffmpeg_exe)
ffmpeg_root = os.path.dirname(ffmpeg_bin)
ffmpeg_include_dir = os.path.join(ffmpeg_root, "include")
ffmpeg_library_dir = os.path.join(ffmpeg_root, "lib")

gcc = os.environ.get("CC", shutil.which("gcc"))
platform_tag = subprocess.run([gcc, "-print-multiarch"], stdout=subprocess.PIPE)
platform_tag = platform_tag.stdout.strip().decode("utf-8")

if platform_tag:
# Most probably a Debian-based distribution
ffmpeg_include_dir = [ffmpeg_include_dir, os.path.join(ffmpeg_include_dir, platform_tag)]
ffmpeg_library_dir = [ffmpeg_library_dir, os.path.join(ffmpeg_library_dir, platform_tag)]
else:
ffmpeg_include_dir = [ffmpeg_include_dir]
ffmpeg_library_dir = [ffmpeg_library_dir]

for library in ffmpeg_libraries:
library_found = False
for search_path in ffmpeg_include_dir + TORCHVISION_INCLUDE:
full_path = os.path.join(search_path, library, "*.h")
library_found |= len(glob.glob(full_path)) > 0

if not library_found:
print(f"{build_without_extensions_msg}")
print(f"{library} header files were not found.")
return None, None

return ffmpeg_include_dir, ffmpeg_library_dir

ffmpeg_include_dir, ffmpeg_library_dir = find_ffmpeg_libraries()
if ffmpeg_include_dir is None or ffmpeg_library_dir is None:
return []

print("Found ffmpeg:")
print(f" ffmpeg include path: {ffmpeg_include_dir}")
print(f" ffmpeg library_dir: {ffmpeg_library_dir}")

extensions = []
if USE_CPU_VIDEO_DECODER:
print("Building with CPU video decoder support")

# TorchVision base decoder + video reader
video_reader_src_dir = os.path.join(ROOT_DIR, "torchvision", "csrc", "io", "video_reader")
video_reader_src = glob.glob(os.path.join(video_reader_src_dir, "*.cpp"))
base_decoder_src_dir = os.path.join(ROOT_DIR, "torchvision", "csrc", "io", "decoder")
base_decoder_src = glob.glob(os.path.join(base_decoder_src_dir, "*.cpp"))
# Torchvision video API
videoapi_src_dir = os.path.join(ROOT_DIR, "torchvision", "csrc", "io", "video")
videoapi_src = glob.glob(os.path.join(videoapi_src_dir, "*.cpp"))
# exclude tests
base_decoder_src = [x for x in base_decoder_src if "_test.cpp" not in x]

combined_src = video_reader_src + base_decoder_src + videoapi_src

extensions.append(
CppExtension(
# This is an awful name. It should be "cpu_video_decoder". Keeping for BC.
"torchvision.video_reader",
combined_src,
include_dirs=[
base_decoder_src_dir,
video_reader_src_dir,
videoapi_src_dir,
str(CSRS_DIR),
*ffmpeg_include_dir,
*TORCHVISION_INCLUDE,
],
library_dirs=ffmpeg_library_dir + TORCHVISION_LIBRARY,
libraries=[
"avcodec",
"avformat",
"avutil",
"swresample",
"swscale",
],
extra_compile_args=["-std=c++17"] if os.name != "nt" else ["/std:c++17", "/MP"],
extra_link_args=["-std=c++17" if os.name != "nt" else "/std:c++17"],
)
)

if USE_GPU_VIDEO_DECODER:
# Locating GPU video decoder headers and libraries
# CUDA_HOME should be set to the cuda root directory.
# TORCHVISION_INCLUDE and TORCHVISION_LIBRARY should include the locations
# to the headers and libraries below
if not (
BUILD_CUDA_SOURCES
and CUDA_HOME is not None
and any([os.path.exists(os.path.join(folder, "cuviddec.h")) for folder in TORCHVISION_INCLUDE])
and any([os.path.exists(os.path.join(folder, "nvcuvid.h")) for folder in TORCHVISION_INCLUDE])
and any([os.path.exists(os.path.join(folder, "libnvcuvid.so")) for folder in TORCHVISION_LIBRARY])
and any([os.path.exists(os.path.join(folder, "libavcodec", "bsf.h")) for folder in ffmpeg_include_dir])
):
print("Could not find necessary dependencies. Refer the setup.py to check which ones are needed.")
print("Building without GPU video decoder support")
return extensions
print("Building torchvision with GPU video decoder support")

gpu_decoder_path = os.path.join(CSRS_DIR, "io", "decoder", "gpu")
gpu_decoder_src = glob.glob(os.path.join(gpu_decoder_path, "*.cpp"))
cuda_libs = os.path.join(CUDA_HOME, "lib64")
cuda_inc = os.path.join(CUDA_HOME, "include")

_, extra_compile_args = get_macros_and_flags()
extensions.append(
CUDAExtension(
"torchvision.gpu_decoder",
gpu_decoder_src,
include_dirs=[CSRS_DIR] + TORCHVISION_INCLUDE + [gpu_decoder_path] + [cuda_inc] + ffmpeg_include_dir,
library_dirs=ffmpeg_library_dir + TORCHVISION_LIBRARY + [cuda_libs],
libraries=[
"avcodec",
"avformat",
"avutil",
"swresample",
"swscale",
"nvcuvid",
"cuda",
"cudart",
"z",
"pthread",
"dl",
"nppicc",
],
extra_compile_args=extra_compile_args,
)
)

return extensions


class clean(distutils.command.clean.clean):
def run(self):
with open(".gitignore") as f:
Expand Down Expand Up @@ -550,7 +388,6 @@ def run(self):
extensions = [
make_C_extension(),
make_image_extension(),
*make_video_decoders_extensions(),
]

setup(
Expand Down
12 changes: 0 additions & 12 deletions test/test_datasets_video_utils_opt.py

This file was deleted.

Loading
Loading