ae_movie_export_sound.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from tools import tools
  2. class MyTools(tools.Tools):
  3. def _initialize(self):
  4. self.add_argument_file('--in_path', 'in_path')
  5. self.add_argument_file('--out_path', 'out_path', exists=None)
  6. self.add_argument_dir('--export_path', 'export_path', exists=None)
  7. self.add_argument('--export_name', 'export_name')
  8. self.add_argument('--project_name', 'project_name')
  9. self.add_argument('--write_name', 'write_name')
  10. self.add_argument('--write_path', 'write_path')
  11. self.add_argument_bool('--use_sha1', 'use_sha1')
  12. pass
  13. def _run(self, args):
  14. ffmpeg_path = self.get_tools_path("ffmpeg.exe")
  15. if self.exist_file(ffmpeg_path) is False:
  16. self.error_result("Not found ffmpeg.exe")
  17. return False
  18. pass
  19. sha1path = None
  20. if args.use_sha1 is True:
  21. sha1hex, sha1path = self.get_file_sha1_new_path(args.in_path, ".ogg")
  22. sha1tag = "export_sound"
  23. temp_path = self.get_sha1_cach_path(sha1tag, sha1hex + ".export_sound")
  24. out_path = args.export_path + ".store_sounds" + "/" + sha1path
  25. pass
  26. else:
  27. temp_path = self.get_temp_path("export_sound.info")
  28. out_path = self.change_ext(args.out_path, "ogg")
  29. pass
  30. if args.use_sha1 is False or ((args.out_path is not None and self.exist_file(out_path) is False) or self.exist_file(temp_path) is False):
  31. if out_path is not None:
  32. self.make_dir_for_file(out_path)
  33. pass
  34. command_args = ["-loglevel", "error"
  35. , "-y"
  36. , "-threads", "4"
  37. , "-i", "{0}".format(args.in_path)
  38. , "-map_metadata", "-1"
  39. , "-ac", "2"
  40. , "-ar", "44100"
  41. , "-aq", "100"
  42. , "-acodec", "libvorbis"
  43. , "{0}".format(out_path)
  44. ]
  45. if self.command_call("ffmpeg sound", ffmpeg_path, command_args) is False:
  46. return False
  47. pass
  48. with open(temp_path, "w") as f:
  49. pass
  50. pass
  51. if args.use_sha1 is True:
  52. print("write_name = {0}\n".format(sha1path))
  53. pass
  54. else:
  55. print("write_name = Movies2_{0}_{1}_{2}\n".format(args.project_name, "Sound", args.write_name))
  56. pass
  57. if args.use_sha1 is True:
  58. ogg_write_path = self.change_ext(sha1path, "ogg")
  59. pass
  60. else:
  61. ogg_write_path = self.change_ext(args.write_path, "ogg")
  62. pass
  63. print("write_path = {0}\n".format(ogg_write_path))
  64. print("codec = 1\n")
  65. return True
  66. pass
  67. pass
  68. tools.run(MyTools)