video_to_image.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. print(file)
  19. from subprocess import call
  20. if (file.endswith(".avi")):
  21. call("mkdir " + output + folder, shell=True)
  22. if (os.path.isdir(output + folder + "/" + file)):
  23. print("Folder already exist")
  24. else:
  25. call("cd " + output + folder + " && mkdir " + file, shell=True)
  26. call("ls", shell=True)
  27. location = dir + folder + "/" + file
  28. gt_address = "cp " + location[
  29. 0:-4] + ".gt.xml " + output + folder + "/" + file + "/" + file + ".gt"
  30. call(gt_address, shell=True)
  31. command = "ffmpeg -i " + location + " " + output + folder + "/" + file + "/%3d.jpg"
  32. print(command)
  33. call(command, shell=True)