class_docstr: Implementation of a video dataset.
  
  The VideoDataset allows random reads from a video file without extracting
  all frames beforehand. This is more storage efficient but is slower.
  
  Attributes:
      root:
          Root directory path.
      extensions:
          Tuple of allowed extensions.
      transform:
          Function that takes a PIL image and returns transformed version
      target_transform:
          As transform but for targets
      is_valid_file:
          Used to check corrupt files
      exception_on_non_increasing_timestamp:
          If True, a NonIncreasingTimestampError is raised when trying to load
          a frame that has a timestamp lower or equal to the timestamps of
          previous frames in the same video.
class_docstr_tok: ["Implementation","of","a","video","dataset",".","The","VideoDataset","allows","random","reads","from","a","video","file","without","extracting","all","frames","beforehand",".","This","is","more","storage","efficient","but","is","slower",".","Attributes",":","root",":","Root","directory","path",".","extensions",":","Tuple","of","allowed","extensions",".","transform",":","Function","that","takes","a","PIL","image","and","returns","transformed","version","target_transform",":","As","transform","but","for","targets","is_valid_file",":","Used","to","check","corrupt","files","exception_on_non_increasing_timestamp",":","If","True",",","a","NonIncreasingTimestampError","is","raised","when","trying","to","load","a","frame","that","has","a","timestamp","lower","or","equal","to","the","timestamps","of","previous","frames","in","the","same","video","."]
docstr: Returns a filename for the frame at index.
  
  The filename is created from the video filename, the frame number, and
  the video format. The frame number will be zero padded to make sure
  all filenames have the same length and can easily be sorted.
  E.g. when retrieving a sample from the video
  `my_video.mp4` at frame 153, the filename will be:
  
  >>> my_video-153-mp4.png
  
  Args:
      index:
          Index of the frame to retrieve.
  
  Returns:
      The filename of the frame as described above.
docstr_tok: ["Returns","a","filename","for","the","frame","at","index",".","The","filename","is","created","from","the","video","filename",",","the","frame","number",",","and","the","video","format",".","The","frame","number","will","be","zero","padded","to","make","sure","all","filenames","have","the","same","length","and","can","easily","be","sorted",".","E.g",".","when","retrieving","a","sample","from","the","video","`","my_video.mp4","`","at","frame","153",",","the","filename","will","be",":",">",">",">","my_video-153-mp4.png","Args",":","index",":","Index","of","the","frame","to","retrieve",".","Returns",":","The","filename","of","the","frame","as","described","above","."]
code: def get_filename(self, index):
      """Returns a filename for the frame at index.
  
      The filename is created from the video filename, the frame number, and
      the video format. The frame number will be zero padded to make sure
      all filenames have the same length and can easily be sorted.
      E.g. when retrieving a sample from the video
      `my_video.mp4` at frame 153, the filename will be:
  
      >>> my_video-153-mp4.png
  
      Args:
          index:
              Index of the frame to retrieve.
  
      Returns:
          The filename of the frame as described above.
  
      """
      if index < 0 or index >= self.__len__():
          raise IndexError(
              f"Index {index} is out of bounds for VideoDataset"
              f" of size {self.__len__()}."
          )
  
      # each sample belongs to a video, to load the sample at index, we need
      # to find the video to which the sample belongs and then read the frame
      # from this video on the disk.
      i = len(self.offsets) - 1
      while self.offsets[i] > index:
          i = i - 1
  
      # get filename of the video file
      video = self.videos[i]
      video_name, video_format = self._video_name_format(video)
  
      # get frame number
      frame_number = index - self.offsets[i]
  
      n_frames = self._video_frame_count(i)
      zero_padding = len(str(n_frames))
  
      return self._format_filename(
          video_name=video_name,
          video_format=video_format,
          frame_number=frame_number,
          zero_padding=zero_padding,
      )
  
imports: import os
  import threading
  import warnings
  import weakref
  from fractions import Fraction
  from typing import Any, Dict, List, Tuple
  import numpy
  import torch
  import torchvision
  from PIL import Image
  from torch.utils.data import DataLoader, Dataset
  from torchvision import datasets, io
  from tqdm import tqdm
label_desc: Use image node_id 4 for calling the VideoDataset obj's underlying member method code with example usage: obj.get_filename(index) and returns: self