Skip to main content

Get an OpenCV video capture from an YouTube video URL

Project description

cap_from_youtube

Get an OpenCV video capture from an YouTube video URL

PyPI

Why

  • pafy is widely used to get the video URL from a YouTube video URL, but since it uses youtube-dl which has not been updated recently, it suffers from some issues (dislike_count not found...).
  • This repository is a simplified version of what pafy does, by just getting the url of the video and creating an OpenCV video capture from it.
  • It uses YT-DLP (https://github.com/yt-dlp/yt-dlp), which is a fork of youtube-dl that is updated frequently.

Requirement

  • YT-DLP
  • OpenCV
  • NumPy

Installation

  • The easiest way is to install it with pip:
pip install cap_from_youtube
  • You can also install it from GitHub:
pip install git+https://github.com/ibaiGorordo/cap_from_youtube

Usage

cap_from_youtube()

  • cap_from_youtube() is the main function to obtain a video capture from a YouTube video URL.
  • It requires the video URL as input and returns a cv2.VideoCapture object.
  • By default, it returns the video with the highest resolution available.
  • You can specify the resolution you want to get with the resolution parameter.
    • Resolution examples: '144p', '240p', '360p', '480p', '720p', '1080p', '1440p', '2160p', 'best'
  • Example:
import cv2
from cap_from_youtube import cap_from_youtube

youtube_url = 'https://youtu.be/LXb3EKWsInQ'
cap = cap_from_youtube(youtube_url, '1440p60')

cv2.namedWindow('video', cv2.WINDOW_NORMAL)
while True:
    ret, frame = cap.read()
    if not ret:
        break
    cv2.imshow('video', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

list_video_streams()

  • You can also use the list_video_streams() function to get the list of available video streams.
  • It requires the video URL as input and returns two values:
    • streams: a list of VideoStream with the information of the available video streams.
    • resolutions: a NumPy array with the available resolutions.
  • Example:
from cap_from_youtube import list_video_streams

youtube_url = 'https://youtu.be/LXb3EKWsInQ'
streams, resolutions = list_video_streams(youtube_url)

for stream in streams:
    print(stream)

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cap_from_youtube-0.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

cap_from_youtube-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file cap_from_youtube-0.1.0.tar.gz.

File metadata

  • Download URL: cap_from_youtube-0.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.8

File hashes

Hashes for cap_from_youtube-0.1.0.tar.gz
Algorithm Hash digest
SHA256 420151d8ee09c15aca7e7aa404a63c3576216b9147941fa5a1b798cfc317af95
MD5 6bb7aebc768270dcac608150dc981c05
BLAKE2b-256 68ee6cb4e839a1818cd89b6c8de6a5d183b2525711afebf1c5f47b1074445835

See more details on using hashes here.

Provenance

File details

Details for the file cap_from_youtube-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cap_from_youtube-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32050375050afa9816ba447fd14f86f30cf4c55a9134606d5d372e0a9ea135d7
MD5 6397c6f9cb671746e5384ac200f6dff6
BLAKE2b-256 b8dff4c2f8b4e09cfd7e067a18d1615ae77867751d57fff7bf82faf7043d7e5c

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page