Skip to content

Commit 49f2919

Browse files
committed
Add deprecation warnings for video stuff
1 parent 4cbf9f3 commit 49f2919

File tree

4 files changed

+44
-28
lines changed

4 files changed

+44
-28
lines changed

docs/source/io.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,11 @@ Video
9191

9292
.. warning::
9393

94-
Torchvision supports video decoding through different APIs listed below,
95-
some of which are still in BETA stage. In the near future, we intend to
96-
centralize PyTorch's video decoding capabilities within the `torchcodec
97-
<https://github.com/pytorch/torchcodec>`_ project. We encourage you to try
98-
it out and share your feedback, as the torchvision video decoders will
99-
eventually be deprecated.
94+
DEPRECATED: All the video decoding and encoding capabilities of torchvision
95+
are deprecated from version 0.22 and will be removed in version 0.24. We
96+
recommend that you migrate to
97+
`TorchCodec<https://github.com/pytorch/torchcodec>`_, where we'll
98+
consolidate the future decoding/encoding capabilities of PyTorch
10099

101100
.. autosummary::
102101
:toctree: generated/

torchvision/io/_video_opt.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def _read_video_from_file(
185185
info (Dict): metadata for the video and audio. Can contain the fields video_fps (float)
186186
and audio_fps (int)
187187
"""
188+
_raise_video_deprecation_warning()
188189
_validate_pts(video_pts_range)
189190
_validate_pts(audio_pts_range)
190191

@@ -256,6 +257,7 @@ def _probe_video_from_file(filename: str) -> VideoMetaData:
256257
"""
257258
Probe a video file and return VideoMetaData with info about the video
258259
"""
260+
_raise_video_deprecation_warning()
259261
result = torch.ops.video_reader.probe_video_from_file(filename)
260262
vtimebase, vfps, vduration, atimebase, asample_rate, aduration = result
261263
info = _fill_info(vtimebase, vfps, vduration, atimebase, asample_rate, aduration)
@@ -331,6 +333,7 @@ def _read_video_from_memory(
331333
`K` is the number of channels
332334
"""
333335

336+
_raise_video_deprecation_warning()
334337
_validate_pts(video_pts_range)
335338
_validate_pts(audio_pts_range)
336339

@@ -405,6 +408,7 @@ def _read_video_timestamps_from_memory(
405408
0, # audio_timebase_num
406409
1, # audio_timebase_den
407410
)
411+
_raise_video_deprecation_warning()
408412
_vframes, vframe_pts, vtimebase, vfps, vduration, _aframes, aframe_pts, atimebase, asample_rate, aduration = result
409413
info = _fill_info(vtimebase, vfps, vduration, atimebase, asample_rate, aduration)
410414

@@ -420,6 +424,7 @@ def _probe_video_from_memory(
420424
Probe a video in memory and return VideoMetaData with info about the video
421425
This function is torchscriptable
422426
"""
427+
_raise_video_deprecation_warning()
423428
if not isinstance(video_data, torch.Tensor):
424429
with warnings.catch_warnings():
425430
# Ignore the warning because we actually don't modify the buffer in this function
@@ -437,6 +442,7 @@ def _read_video(
437442
end_pts: Optional[Union[float, Fraction]] = None,
438443
pts_unit: str = "pts",
439444
) -> Tuple[torch.Tensor, torch.Tensor, Dict[str, float]]:
445+
_raise_video_deprecation_warning()
440446
if end_pts is None:
441447
end_pts = float("inf")
442448

@@ -495,6 +501,7 @@ def get_pts(time_base):
495501
def _read_video_timestamps(
496502
filename: str, pts_unit: str = "pts"
497503
) -> Tuple[Union[List[int], List[Fraction]], Optional[float]]:
504+
_raise_video_deprecation_warning()
498505
if pts_unit == "pts":
499506
warnings.warn(
500507
"The pts_unit 'pts' gives wrong results and will be removed in a "

torchvision/io/video.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from ..utils import _log_api_usage_once
1313
from . import _video_opt
14+
from ._video_deprecation_warning import _raise_video_deprecation_warning
1415

1516
try:
1617
import av
@@ -66,7 +67,15 @@ def write_video(
6667
audio_options: Optional[Dict[str, Any]] = None,
6768
) -> None:
6869
"""
69-
Writes a 4d tensor in [T, H, W, C] format in a video file.
70+
[DEPRECATED] Writes a 4d tensor in [T, H, W, C] format in a video file.
71+
72+
.. warning::
73+
74+
DEPRECATED: All the video decoding and encoding capabilities of torchvision
75+
are deprecated from version 0.22 and will be removed in version 0.24. We
76+
recommend that you migrate to
77+
`TorchCodec<https://github.com/pytorch/torchcodec>`_, where we'll
78+
consolidate the future decoding/encoding capabilities of PyTorch
7079
7180
This function relies on PyAV (therefore, ultimately FFmpeg) to encode
7281
videos, you can get more fine-grained control by referring to the other
@@ -107,6 +116,7 @@ def write_video(
107116
>>> write_video("video.mp4", options = {"crf": "17"})
108117
109118
"""
119+
_raise_video_deprecation_warning()
110120
if not torch.jit.is_scripting() and not torch.jit.is_tracing():
111121
_log_api_usage_once(write_video)
112122
_check_av_available()
@@ -276,16 +286,15 @@ def read_video(
276286
pts_unit: str = "pts",
277287
output_format: str = "THWC",
278288
) -> Tuple[torch.Tensor, torch.Tensor, Dict[str, Any]]:
279-
"""
280-
Reads a video from a file, returning both the video frames and the audio frames
289+
"""[DEPRECATED] Reads a video from a file, returning both the video frames and the audio frames
281290
282291
.. warning::
283292
284-
In the near future, we intend to centralize PyTorch's video decoding
285-
capabilities within the `torchcodec
286-
<https://github.com/pytorch/torchcodec>`_ project. We encourage you to
287-
try it out and share your feedback, as the torchvision video decoders
288-
will eventually be deprecated.
293+
DEPRECATED: All the video decoding and encoding capabilities of torchvision
294+
are deprecated from version 0.22 and will be removed in version 0.24. We
295+
recommend that you migrate to
296+
`TorchCodec<https://github.com/pytorch/torchcodec>`_, where we'll
297+
consolidate the future decoding/encoding capabilities of PyTorch
289298
290299
Args:
291300
filename (str): path to the video file. If using the pyav backend, this can be whatever ``av.open`` accepts.
@@ -302,6 +311,7 @@ def read_video(
302311
aframes (Tensor[K, L]): the audio frames, where `K` is the number of channels and `L` is the number of points
303312
info (Dict): metadata for the video and audio. Can contain the fields video_fps (float) and audio_fps (int)
304313
"""
314+
_raise_video_deprecation_warning()
305315
if not torch.jit.is_scripting() and not torch.jit.is_tracing():
306316
_log_api_usage_once(read_video)
307317

@@ -408,16 +418,15 @@ def _decode_video_timestamps(container: "av.container.Container") -> List[int]:
408418

409419

410420
def read_video_timestamps(filename: str, pts_unit: str = "pts") -> Tuple[List[int], Optional[float]]:
411-
"""
412-
List the video frames timestamps.
421+
"""[DEPREACTED] List the video frames timestamps.
413422
414423
.. warning::
415424
416-
In the near future, we intend to centralize PyTorch's video decoding
417-
capabilities within the `torchcodec
418-
<https://github.com/pytorch/torchcodec>`_ project. We encourage you to
419-
try it out and share your feedback, as the torchvision video decoders
420-
will eventually be deprecated.
425+
DEPRECATED: All the video decoding and encoding capabilities of torchvision
426+
are deprecated from version 0.22 and will be removed in version 0.24. We
427+
recommend that you migrate to
428+
`TorchCodec<https://github.com/pytorch/torchcodec>`_, where we'll
429+
consolidate the future decoding/encoding capabilities of PyTorch
421430
422431
Note that the function decodes the whole video frame-by-frame.
423432
@@ -432,6 +441,7 @@ def read_video_timestamps(filename: str, pts_unit: str = "pts") -> Tuple[List[in
432441
video_fps (float, optional): the frame rate for the video
433442
434443
"""
444+
_raise_video_deprecation_warning()
435445
if not torch.jit.is_scripting() and not torch.jit.is_tracing():
436446
_log_api_usage_once(read_video_timestamps)
437447
from torchvision import get_video_backend

torchvision/io/video_reader.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,19 @@ def _has_video_opt() -> bool:
4545

4646

4747
class VideoReader:
48-
"""
49-
Fine-grained video-reading API.
48+
"""[DEPRECATED] Fine-grained video-reading API.
5049
Supports frame-by-frame reading of various streams from a single video
5150
container. Much like previous video_reader API it supports the following
5251
backends: video_reader, pyav, and cuda.
5352
Backends can be set via `torchvision.set_video_backend` function.
5453
5554
.. warning::
5655
57-
In the near future, we intend to centralize PyTorch's video decoding
58-
capabilities within the `torchcodec
59-
<https://github.com/pytorch/torchcodec>`_ project. We encourage you to
60-
try it out and share your feedback, as the torchvision video decoders
61-
will eventually be deprecated.
56+
DEPRECATED: All the video decoding and encoding capabilities of torchvision
57+
are deprecated from version 0.22 and will be removed in version 0.24. We
58+
recommend that you migrate to
59+
`TorchCodec<https://github.com/pytorch/torchcodec>`_, where we'll
60+
consolidate the future decoding/encoding capabilities of PyTorch
6261
6362
.. betastatus:: VideoReader class
6463
@@ -125,6 +124,7 @@ def __init__(
125124
stream: str = "video",
126125
num_threads: int = 0,
127126
) -> None:
127+
_raise_video_deprecation_warning()
128128
_log_api_usage_once(self)
129129
from .. import get_video_backend
130130

0 commit comments

Comments
 (0)