video_to_image.py 1.5 KB

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