-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyoutube_videos_capture_frames.py
42 lines (32 loc) · 1.26 KB
/
youtube_videos_capture_frames.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
### Capturing images from YouTube videos without downloading Video using Python's VidGear Module
## pip install vidgear
import cv2
import os
from vidgear.gears import CamGear
### Replace this youtube video link with your one
# https://www.youtube.com/watch?v=lQc432kUOpM
stream = CamGear(
source="https://www.youtube.com/watch?v=69X8ZLj1ukw",
stream_mode=True,
time_delay=1,
logging=True,
).start()
# this should be the path where u want ur images
# path = 'C:\\Users\\user\\Desktop\\Capture Frames from Online YouTube Video\\cars\\'
path = "D:\\github codes\\test\\"
currentframe = 0
while True:
frame = stream.read() ### using functions from vidGear module
if frame is None:
break
cv2.imshow("Output Frame", frame) # optional if u want to show the frames
name = path + "./frames" + str(currentframe) + ".jpg"
print("Creating..." + name)
cv2.imwrite(name, frame)
currentframe += 5 ##chnage 5 with the number of frames. Here 5 means capture frame after every 5 frames
###usually videos are 30fps so if here 30 is provided a frame will be captures after every second.
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
cv2.destroyAllWindows()
stream.stop()