選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

46 行
1.3 KiB

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