Files
cours-ai-tutorials/Divers/decoupe_video/extract_image_from_video.py

27 lines
513 B
Python
Raw Permalink Normal View History

2026-03-31 13:28:59 +02:00
import cv2
import os
film='Le_chemin_du_passe.mp4'
if not os.path.exists(film):
quit("Le film n'existe pas")
nom_film=film.split('.')[0]
cap=cv2.VideoCapture(film)
if not os.path.isdir(nom_film):
os.mkdir(nom_film)
id=0
while True:
print("#", end="", flush=True)
for cpt in range(500):
ret, frame=cap.read()
if frame is None:
print("")
cap.release()
quit()
cv2.imwrite("{}/{}-{:d}.png".format(nom_film, nom_film, id), frame)
id+=1