25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.9 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. proc = sp.Popen(args, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE)
  31. answer = 'Overwrite ? [y/N]'
  32. try:
  33. outs, errs = proc.communicate(timeout=300)
  34. ret_info = str(outs, encoding='utf-8')
  35. print(ret_info, errs)
  36. if answer in ret_info:
  37. proc.stdin.write(b'y')
  38. elif proc.returncode == 0:
  39. print("{0} convert {1} Success, origin dat will remove!".format(origin, target))
  40. os.remove(origin)
  41. else:
  42. print("{0} convert fail".format(origin))
  43. except sp.TimeoutExpired:
  44. proc.kill()
  45. if __name__ == "__main__":
  46. codec = "h265"
  47. if len(sys.argv) > 1:
  48. codec = sys.argv[1]
  49. # timeout=sys.argv[2]
  50. print("codec:: {0}".format(codec))
  51. list_folder(DAT_FOLDER, TARGET_FOLDER, codec)