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.

67 line
2.1 KiB

  1. """
  2. video.py h265[h264]
  3. """
  4. import sys
  5. import subprocess as sp
  6. import shlex
  7. import time
  8. import os
  9. DAT_FOLDER = "/extdisk/origin"
  10. TARGET_FOLDER = "/extdisk/camera"
  11. SUFFIX = ".dat"
  12. TARGET_SUFFIX = ".mp4"
  13. def list_folder(org_folder, tar_folder, code):
  14. current_time = time.strftime(time.strftime("%Y-%m-%d-%H"), time.localtime())
  15. for root, dirs, files in os.walk(org_folder):
  16. for f in files:
  17. if current_time in f:
  18. print("file ignore: {0} ".format(os.path.join(root, f)))
  19. continue
  20. else:
  21. convert(os.path.join(root, f), os.path.join(tar_folder, code, list(root.split("/"))[-1],
  22. f.replace(SUFFIX, "") + TARGET_SUFFIX))
  23. def convert(origin, target):
  24. print("origin: {0} ,target: {1}".format(origin, target))
  25. cmd = 'ffmpeg -i {0} -c copy {1}'.format(origin, target)
  26. print("cmd:: {0}".format(cmd))
  27. args = shlex.split(cmd)
  28. #status, output = sp.getstatusoutput(cmd)
  29. #print("status:: {0}, output {1}".format(status, output))
  30. #if status ==0:
  31. # print("{0} convert {1} Success, origin dat will remove!".format(origin, target))
  32. # os.remove(origin)
  33. #else:
  34. # print("{0} convert fail".format(origin))
  35. proc = sp.Popen(args, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE)
  36. answer = b'Overwrite ? [y/N]'
  37. try:
  38. outs, errs = proc.communicate()
  39. print(outs, errs)
  40. print("answer in outs : {0}".format(answer in errs))
  41. if answer in errs:
  42. print('write y')
  43. continue
  44. # proc.stdin.write(b'y')
  45. if proc.returncode == 0:
  46. print("{0} convert {1} Success, origin dat will remove!".format(origin, target))
  47. os.remove(origin)
  48. else:
  49. print("{0} convert fail".format(origin))
  50. except sp.TimeoutExpired:
  51. proc.kill()
  52. if __name__ == "__main__":
  53. codec = "h265"
  54. if len(sys.argv) > 1:
  55. codec = sys.argv[1]
  56. # timeout=sys.argv[2]
  57. print("codec:: {0}".format(codec))
  58. list_folder(DAT_FOLDER, TARGET_FOLDER, codec)