video_to_image.py 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. import os
  2. def argsProcessor():
  3. import argparse
  4. parser = argparse.ArgumentParser()
  5. parser.add_argument("-d", "--dataPath", help="path to main data folder")
  6. parser.add_argument("-o", "--outputPath", help="output data")
  7. return parser.parse_args()
  8. if __name__ == '__main__':
  9. args = argsProcessor()
  10. dir = args.dataPath
  11. output = args.outputPath
  12. if (not os.path.isdir(output)):
  13. os.mkdir(output)
  14. for folder in os.listdir(dir):
  15. if os.path.isdir(dir + "/" + folder):
  16. dir_temp = dir+ "/" + folder + "/"
  17. for file in os.listdir(dir_temp):
  18. from subprocess import call
  19. if (file.endswith(".avi")):
  20. os.mkdir(output + "/" + folder)
  21. if (os.path.isdir(output + "/" + folder + "/" + file)):
  22. print("Folder already exist")
  23. else:
  24. call("cd " + output + "/" + folder + " && mkdir " + file, shell=True)
  25. location = dir + "/" + folder + "/" + file
  26. command = "ffmpeg -i " + location + " " + output + "/" + folder + "/" + file + "/%3d.jpg"
  27. # print(command)
  28. call(command, shell=True)
  29. print(file + "done!")