-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYT.py
35 lines (31 loc) · 1.16 KB
/
YT.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
import pafy #open anaconda prompt and type pip install pafy
import cv2
url = "https://www.youtube.com/watch?v=SLD9xzJ4oeU"
data = pafy.new(url )
data = data.getbest(preftype="mp4")
cap = cv2.VideoCapture() #Here parameter 0 is a path of any video use for webcam
cap.open(data.url)
#it is 4 byte code which is use to specify the video codec
fourcc = cv2.VideoWriter_fourcc(*"XVID") # *"XVID"
#It contain 4 parameter , name, codec,fps,resolution
output = cv2.VideoWriter("/root/Videos/out.avi",fourcc,20.0,(640,480),0)
while(cap.isOpened()):
ret, frame = cap.read() #here read the frame
if ret==True:
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
#here flip is used to lip the video at recording time
#frame = cv2.flip(frame,0)
#output.write(gray)
#cv2.imshow("Gray Frame",gray)
cv2.imshow('Colorframe',frame)
if cv2.waitKey(1) & 0xFF == ord('q'): #press to exit
break
else:
break
# Release everything if job is finished
cap.release()
output.release()
cv2.destroyAllWindows()
#if any os error regarding youtube-dl occur thn
#conda install -c forge youtube-dl
#pip3 install youtube-dl