{"id":23116088,"url":"https://github.com/ibaigorordo/cap_from_youtube","last_synced_at":"2025-05-12T14:43:57.816Z","repository":{"id":56959481,"uuid":"526876190","full_name":"ibaiGorordo/cap_from_youtube","owner":"ibaiGorordo","description":"Get an OpenCV video capture from an YouTube video URL","archived":false,"fork":false,"pushed_at":"2024-08-26T01:13:54.000Z","size":33,"stargazers_count":25,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T23:22:41.640Z","etag":null,"topics":["opencv","opencv-python","python","video-capture","youtube","youtube-dl","yt-dlp"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ibaiGorordo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-20T09:04:18.000Z","updated_at":"2025-03-18T20:13:06.000Z","dependencies_parsed_at":"2022-08-21T09:50:32.950Z","dependency_job_id":null,"html_url":"https://github.com/ibaiGorordo/cap_from_youtube","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibaiGorordo%2Fcap_from_youtube","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibaiGorordo%2Fcap_from_youtube/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibaiGorordo%2Fcap_from_youtube/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibaiGorordo%2Fcap_from_youtube/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibaiGorordo","download_url":"https://codeload.github.com/ibaiGorordo/cap_from_youtube/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253757190,"owners_count":21959351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["opencv","opencv-python","python","video-capture","youtube","youtube-dl","yt-dlp"],"created_at":"2024-12-17T04:11:00.442Z","updated_at":"2025-05-12T14:43:57.778Z","avatar_url":"https://github.com/ibaiGorordo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cap_from_youtube\n Get an OpenCV video capture from an YouTube video URL\n\n[![PyPI](https://img.shields.io/pypi/v/cap-from-youtube?color=2BAF2B)](https://pypi.org/project/cap-from-youtube/)\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/ibaiGorordo/cap_from_youtube/main/doc/img/cap_from_youtube_logo.png\" /\u003e\n\u003c/p\u003e\n\n# Why\n- 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...).\n- 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.\n- It uses YT-DLP (https://github.com/yt-dlp/yt-dlp), which is a fork of youtube-dl that is updated frequently.\n\n# Requirement\n* YT-DLP\n* OpenCV\n* NumPy\n \n# Installation\n- The easiest way is to install it with pip:\n\n```bash\npip install cap_from_youtube\n```\n- You can also install it from GitHub:\n\n```bash\npip install git+https://github.com/ibaiGorordo/cap_from_youtube\n```\n\n# Usage\n\n## cap_from_youtube()\n- `cap_from_youtube()` is the main function to obtain a video capture from a YouTube video URL. \n- It requires the video URL as input and returns a `cv2.VideoCapture` object.\n- By default, it returns the video with the highest resolution available.\n- You can specify the resolution you want to get with the `resolution` parameter.\n  - Available resolutions: '144p', '240p', '360p', '480p', '720p', '720p60', '1080p', '1080p60', 'best'\n- Example:\n\n```python\nfrom datetime import timedelta\nimport cv2\nfrom cap_from_youtube import cap_from_youtube\n\nyoutube_url = 'https://youtu.be/LXb3EKWsInQ'\nstart_time = timedelta(seconds=5)\ncap = cap_from_youtube(youtube_url, 'best', start=start_time)\n\ncv2.namedWindow('video', cv2.WINDOW_NORMAL)\nwhile True:\n    ret, frame = cap.read()\n    if not ret:\n        break\n    cv2.imshow('video', frame)\n    if cv2.waitKey(1) \u0026 0xFF == ord('q'):\n        break\n```\n\n## list_video_streams()\n- You can also use the `list_video_streams()` function to get the list of available video streams.\n- It requires the video URL as input and returns two values: \n  - streams: a list of VideoStream with the information of the available video streams.\n  - resolutions: a NumPy array with the available resolutions.\n- Example:\n```python\nfrom cap_from_youtube import list_video_streams\n\nyoutube_url = 'https://youtu.be/LXb3EKWsInQ'\nstreams, resolutions = list_video_streams(youtube_url)\n\nfor stream in streams:\n    print(stream)\n```\n \n# References\n- pafy: https://github.com/mps-youtube/pafy\n- yt-dlp: https://github.com/yt-dlp/yt-dlp\n- imread_from_url: https://github.com/Kazuhito00/imread_from_url\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibaigorordo%2Fcap_from_youtube","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibaigorordo%2Fcap_from_youtube","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibaigorordo%2Fcap_from_youtube/lists"}