Advertisement
Guest User

Python Frame extractor

a guest
Jan 25th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. import os, cv2
  2. from os import walk
  3.  
  4. currentWorkingDirectory = os.getcwd()
  5. files = []
  6.  
  7. for (dirpath, dirnames, filenames) in walk(currentWorkingDirectory + "/Video"):
  8.     files.extend(filenames)
  9.  
  10. if not files:
  11.     print("== No files found ==")
  12. else:
  13.     for file in files:
  14.         if ".mp4" in file:
  15.             print(currentWorkingDirectory + "/Video/" + file)
  16.             vidcap = cv2.VideoCapture(currentWorkingDirectory + "/Video/" + file)
  17.             success,image = vidcap.read()
  18.             count = 0
  19.             success = True
  20.             output = currentWorkingDirectory + "/Output/" + file
  21.  
  22.             if not os.path.isdir(output):
  23.                 os.mkdir(output)
  24.  
  25.             while success:
  26.               cv2.imwrite(output + "/frame" + str(count) + ".jpg", image)
  27.               success,image = vidcap.read()
  28.               print ("Frame - " + str(count) + " of " + file)
  29.               count += 1
  30.  
  31.             print("\n===============" + len(file) * "=")
  32.             print("== Finished " + file + " ==")
  33.             print("===============" + len(file) * "=" + "\n")
  34.          
  35. print("======= Done =======")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement