Skip to content
Akash Mahanty edited this page Dec 24, 2021 · 14 revisions

VideoHash class

Only one parameter out of path and url must have an argument, passing both will raise ValueError. And if none of them has an argument the instance will raise videohash.exceptions.DidNotSupplyPathOrUrl.

videohash.VideoHash(path=None, url=None, storage_path=None, download_worst=False, frame_interval=1)

  • creates a VideoHash object that can be used to calculate the video hash value for a video

  • Parameters:

  • path - Absolute path of the video file.
  • url - URL of the video file. Every URL that is supported by the yt-dlp package can be used.
  • storage_path - If you want to provide a storage path for the files created/downloaded by the instance, pass the absolute path to that directory.
  • download_worst - If set to True, download the worst quality video. The default value is False, set True to conserve bandwidth.
  • frame_interval - Number of frames extracted per unit time, the default value is 1 per unit time. For 1 frame per 5 seconds pass 1/5 or 0.2. For 5 fps pass 5. Smaller frame_interval implies fewer frames and vice-versa.

Video Duration

videohash.video_duration(video_path, ffmpeg_path = None)

  • Retrieve the exact video duration as echoed by the FFmpeg and return the duration in seconds. The maximum duration supported is 999 hours, above which the regex is doomed to fail(no match). the return type is float.

  • Parameters:

  • video_path - Absolute path of the video file.
  • ffmpeg_path - Path of the FFmpeg software if not in path.

Exceptions

VideoHashError
  • Base Exception for the videohash package. All the other exceptions inherit from VideoHashError.
StoragePathDoesNotExist
  • The storage path passed by the user does not exist. Make sure that the absolute directory path passed ends with either '/' or '' depending on your system to avoid this exception.
FramesExtractorOutPutDirDoesNotExist
  • The frames output directory passed to the frame extractor does not exist.
DownloadOutPutDirDoesNotExist
  • The output directory passed to downloader for storing the downloaded video does not exist.
DidNotSupplyPathOrUrl
  • Must supply either a path for the video or a valid URL.
CollageOfZeroFramesError
  • Raised if zero frames are passed for collage making.
DownloadFailed
  • Download software failed to download the video from the URL.
FFmpegError
  • Base error for the FFmpeg software.
FFmpegNotFound
  • FFmpeg is either not installed or not in the executable path of the system.
FFmpegFailedToExtractFrames
  • FFmpeg failed to extract any frame at all. Maybe the input video is damaged or corrupt.