您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

58 行
1.8 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],f.replace(SUFFIX,"")+TARGET_SUFFIX))
  22. def convert(origin, target):
  23. print("origin: {0} ,target: {1}".format(origin,target))
  24. cmd = 'ffmpeg -i {0} -c copy {1}'.format(origin,target)
  25. print("cmd:: {0}".format(cmd))
  26. args = shlex.split(cmd)
  27. # status, output = sp.getstatusoutput(cmd)
  28. print("status:: {0}, output {1}".format(status, output))
  29. proc = sp.Popen(args,stdin=sp.PIPE,stdout=sp.PIPE,stderr=sp.PIPE)
  30. try:
  31. if 'Overwrite ? [y/N]' in outs:
  32. proc.stdin.write("y\n")
  33. outs, errs = proc.communicate(timeout=300)
  34. print(outs,errs)
  35. if p.returncode == 0:
  36. print("{0} convert {1} Success, origin dat will remove!".format(origin, target))
  37. os.remove(origin)
  38. else:
  39. print("{0} convert fail".format(origin))
  40. except TimeoutExpired:
  41. proc.kill()
  42. if __name__ == "__main__":
  43. codec = "h265"
  44. if len(sys.argv) > 1:
  45. codec = sys.argv[1]
  46. # timeout=sys.argv[2]
  47. print("codec:: {0}".format(codec))
  48. list_folder(DAT_FOLDER, TARGET_FOLDER, codec)