"...pipelines/controlnet/pipeline_controlnet_inpaint.py" did not exist on "5c9dd0af952a92f19a1e672b2a9471ad5674841d"
io.rst 2.16 KB
Newer Older
1
2
Reading/Writing images and videos
=================================
3
4
5
6

.. currentmodule:: torchvision.io

The :mod:`torchvision.io` package provides functions for performing IO
7
8
operations. They are currently specific to reading and writing video and
images.
9
10
11
12

Video
-----

13
14
15
.. autosummary::
    :toctree: generated/
    :template: function.rst
16

17
18
19
    read_video
    read_video_timestamps
    write_video
20
21


22
Fine-grained video API
23
----------------------
24
25
26
27
28

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.

29
30
.. betastatus:: fine-grained video API

31
32
33
34
35
.. autosummary::
    :toctree: generated/
    :template: class.rst

    VideoReader
36
37


Bruno Korbar's avatar
Bruno Korbar committed
38
Example of inspecting a video:
39
40
41
42
43
44

.. code:: python

    import torchvision
    video_path = "path to a test video"
    # Constructor allocates memory and a threaded decoder
Hollow Man's avatar
Hollow Man committed
45
    # instance per video. At the moment it takes two arguments:
46
    # path to the video file, and a wanted stream.
47
    reader = torchvision.io.VideoReader(video_path, "video")
48
49
50
51
52
53
54
55
56
57
58
59

    # The information about the video can be retrieved using the 
    # `get_metadata()` method. It returns a dictionary for every stream, with
    # duration and other relevant metadata (often frame rate)
    reader_md = reader.get_metadata()

    # metadata is structured as a dict of dicts with following structure
    # {"stream_type": {"attribute": [attribute per stream]}}
    #
    # following would print out the list of frame rates for every present video stream
    print(reader_md["video"]["fps"])

Bruno Korbar's avatar
Bruno Korbar committed
60
61
62
63
64
    # we explicitly select the stream we would like to operate on. In
    # the constructor we select a default video stream, but
    # in practice, we can set whichever stream we would like 
    video.set_current_stream("video:0")

65

66
67
68
Image
-----

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
.. autosummary::
    :toctree: generated/
    :template: class.rst

    ImageReadMode

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

    read_image
    decode_image
    encode_jpeg
    decode_jpeg
    write_jpeg
    encode_png
    decode_png
    write_png
    read_file
    write_file