torchvision.io¶
The torchvision.io
package provides functions for performing IO
operations. They are currently specific to reading and writing video.
Video¶
-
torchvision.io.
read_video
(filename, start_pts=0, end_pts=None, pts_unit='pts')[source]¶ Reads a video from a file, returning both the video frames as well as the audio frames
- Parameters
filename (str) – path to the video file
start_pts (int if pts_unit = 'pts', optional) – float / Fraction if pts_unit = ‘sec’, optional the start presentation time of the video
end_pts (int if pts_unit = 'pts', optional) – float / Fraction if pts_unit = ‘sec’, optional the end presentation time
pts_unit (str, optional) – unit in which start_pts and end_pts values will be interpreted, either ‘pts’ or ‘sec’. Defaults to ‘pts’.
- Returns
vframes (Tensor[T, H, W, C]) – the T video frames
aframes (Tensor[K, L]) – the audio frames, where K is the number of channels and L is the number of points
info (Dict) – metadata for the video and audio. Can contain the fields video_fps (float) and audio_fps (int)
-
torchvision.io.
read_video_timestamps
(filename, pts_unit='pts')[source]¶ List the video frames timestamps.
Note that the function decodes the whole video frame-by-frame.
- Parameters
- Returns
pts (List[int] if pts_unit = ‘pts’) – List[Fraction] if pts_unit = ‘sec’ presentation timestamps for each one of the frames in the video.
video_fps (int) – the frame rate for the video