urllib下载文件并保存,cv2打开视频并把第一帧截图
import urllib.request as req
import cv2
def download(url):
f = req.urlopen(url)
name="这里自己编.mp4"
with open(name,'wb') as fd:
fd.write(f.read())
return name
def screenShot(name):
vc = cv2.VideoCapture(name)
rval,frame = vc.read()
cv2.imwrite(name.strip('.mp4')+'.jpg',frame)
vc.release()
if __name__ == '__main__':
url = '视频url'
name = download(url)
screenShot(name)