You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

  1. """
  2. video.py h265[h264]
  3. """
  4. import sys
  5. import subprocess
  6. import time
  7. import os
  8. DAT_FOLDER = "/media-file/origin"
  9. TARGET_FOLDER="/media-file/camera"
  10. SUFFIX=".dat"
  11. TARGET_SUFFIX=".mp4"
  12. codec = "h265"
  13. if(len(sys.argv)>1):
  14. codec=sys.argv[1]
  15. # timeout=sys.argv[2]
  16. print("codec:: {0}".format(codec))
  17. current_time=time.strftime(time.strftime("%Y-%m-%d-%H"),time.localtime())
  18. file_list = os.listdir(DAT_FOLDER)
  19. if file_list:
  20. for dat in file_list:
  21. if current_time+".dat" == dat:
  22. print("{0} ignore".format(dat))
  23. continue
  24. cmd = "ffmpeg -i " + os.path.join(DAT_FOLDER,dat) + " -c copy " + os.path.join(TARGET_FOLDER, codec, dat.split(".")[0], TARGET_SUFFIX)
  25. print("cmd:: {0}".format(cmd))
  26. status, output = subprocess.getstatusoutput(cmd)
  27. print("status:: {0}, output {1}".format(status,output))
  28. if status==0:
  29. print("{0} convert sucessfull, origin dat will remove!".format(dat))
  30. os.remove(os.path.join(DAT_FOLDER, dat))
  31. else:
  32. print("{0} convert fail".format(dat))
  33. else:
  34. print("folder is empty")