jameson512 commited on
Commit
b47dcee
·
1 Parent(s): be808ed

Upload files via LFS

Browse files
.gitignore ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.log
2
+ *.srt
3
+ *.7z
4
+ *.wav
5
+ *.spec
6
+ *.ui
7
+ *.bak
8
+ *.bat
9
+ *.aac
10
+ *.pyi
11
+ *.mp4
12
+ *副本.py
13
+ .agree.txt
14
+ .git
15
+ .github
16
+ .idea
17
+ .venv
18
+ .pytest_cache
19
+ .mimocode
20
+ AGENTS.md
21
+ err.txt
22
+ nolang.txt
23
+ edgetts.txt
24
+ debug*.py
25
+ ceshi*
26
+
27
+
28
+ ffmpeg/ffmpeg.exe
29
+ ffmpeg/ffprobe.exe
30
+ ffmpeg/ffplay.exe
31
+ ffmpeg/ytwin32.exe
32
+
33
+
34
+ videotrans/translator/freechatgpt.py
35
+ videotrans/ass.json
36
+ videotrans/codec.json
37
+ videotrans/cfg.json
38
+ videotrans/params.json
39
+ videotrans/glossary.txt
40
+ videotrans/newlang.txt
41
+
42
+
43
+ output/
44
+ hooks
45
+ tmp
46
+ images
47
+ logs
48
+ models
49
+ dev
50
+ venv
51
+ chatterbox
52
+ !f5-tts/nverguo.wav
53
+ apidata
54
+ dist
55
+ source
56
+ build
57
+ ytlinux
58
+ ytdarwin
59
+ __pycache__
60
+ pretrained_models
61
+ runtime
62
+
63
+ # Arquivos do sistema
64
+ .DS_Store
65
+ .DS_Store?
66
+ ._*
67
+ .Spotlight-V100
68
+ .Trashes
69
+ ehthumbs.db
70
+ Thumbs.db
71
+
72
+ test.py
videotrans/__pycache__/__init__.cpython-310.pyc DELETED
Binary file (1.33 kB)
 
videotrans/task/trans_create.py CHANGED
@@ -1370,10 +1370,8 @@ class TransCreate(BaseTask):
1370
  tmp_target_mp4_basename = os.path.basename(tmp_target_mp4)
1371
 
1372
  # 获取可用的硬件
1373
- print('############a1')
1374
  if not app_cfg.video_codec:
1375
- app_cfg.video_codec = 'libx264'#get_video_codec()
1376
- print('############a2')
1377
 
1378
  cmd0 = [
1379
  "-y",
@@ -1388,7 +1386,7 @@ class TransCreate(BaseTask):
1388
  target_m4a_basename
1389
  ]
1390
  enc_qua = ['-crf', f'{settings.get("crf", 23)}', '-preset', settings.get('preset', 'medium')]
1391
- print('@@@@@@@@@@@@@@@@@@@@@@@')
1392
  # 若选 cfr,无论是否有视频慢速,均固定帧率输出
1393
  # 若选vfr仅在有视频慢速时使用,其他使用ffmpeg默认auto
1394
  fps_mode=None
@@ -1456,7 +1454,6 @@ class TransCreate(BaseTask):
1456
  else:
1457
  cmd1.append('-filter_complex')
1458
  subtitle_filter = [f"[0:v]subtitles=filename='{subtitles_file}'[v_out]"]
1459
- print(f'嵌入硬字幕 {subtitle_filter=}')
1460
  cmd2 = [
1461
  "-map",
1462
  "[v_out]",
@@ -1474,10 +1471,9 @@ class TransCreate(BaseTask):
1474
  #"-t", str(duration_s),
1475
  cmd3.extend(['-shortest', tmp_target_mp4_basename])
1476
  if app_cfg.video_codec.startswith('libx') or settings.get('force_lib'):
1477
- print(f'[最终视频合成]不支持硬件编解码或指定了强制软编解码:\n{cmd0 + cmd1 + cmd2}')
1478
  runffmpeg(cmd0 + cmd1 + subtitle_filter + cmd2 + enc_qua + cmd3,
1479
  cmd_dir=self.cfg.cache_folder, force_cpu=True)
1480
- print(f'{subtitle_filter=}')
1481
  else:
1482
  # 如果硬件处理失败,回退软编
1483
  try:
@@ -1486,7 +1482,7 @@ class TransCreate(BaseTask):
1486
  self._subprocess(cmd0 + hw_decode_args + cmd1 + [vf_string] + cmd2 + enc_args + cmd3)
1487
  except Exception as e:
1488
  cmd2[cmd2.index('-c:v') + 1] = f'libx{self.video_codec_num}'
1489
- print(f'硬件处理视频合成失败,回退软编 {e}', exc_info=True)
1490
  runffmpeg(cmd0 + cmd1 + subtitle_filter + cmd2 + enc_qua + cmd3,
1491
  cmd_dir=self.cfg.cache_folder, force_cpu=True)
1492
  except Exception as e:
@@ -1663,7 +1659,7 @@ class TransCreate(BaseTask):
1663
  return global_args, vf_string, vcodec, enc_args
1664
 
1665
  def _subprocess(self, cmd):
1666
- print(f'[尝试硬件编解码执行命令]\n{" ".join(cmd)}\n')
1667
  try:
1668
  if app_cfg.exit_soft: return
1669
  cmd = ["ffmpeg", '-nostdin'] + cmd
@@ -1679,7 +1675,6 @@ class TransCreate(BaseTask):
1679
  creationflags=subprocess.CREATE_NO_WINDOW if sys.platform == 'win32' else 0,
1680
  cwd=self.cfg.cache_folder
1681
  )
1682
- logger.debug(f'[_subprocess]:{cmd=}')
1683
  return True
1684
  except subprocess.CalledProcessError as e:
1685
  raise FFmpegError(f"尝试使用硬件执行命令出错[CalledProcessError]:{e.stderr}\n{e.stdout},{e}") from e
 
1370
  tmp_target_mp4_basename = os.path.basename(tmp_target_mp4)
1371
 
1372
  # 获取可用的硬件
 
1373
  if not app_cfg.video_codec:
1374
+ app_cfg.video_codec = get_video_codec()
 
1375
 
1376
  cmd0 = [
1377
  "-y",
 
1386
  target_m4a_basename
1387
  ]
1388
  enc_qua = ['-crf', f'{settings.get("crf", 23)}', '-preset', settings.get('preset', 'medium')]
1389
+
1390
  # 若选 cfr,无论是否有视频慢速,均固定帧率输出
1391
  # 若选vfr仅在有视频慢速时使用,其他使用ffmpeg默认auto
1392
  fps_mode=None
 
1454
  else:
1455
  cmd1.append('-filter_complex')
1456
  subtitle_filter = [f"[0:v]subtitles=filename='{subtitles_file}'[v_out]"]
 
1457
  cmd2 = [
1458
  "-map",
1459
  "[v_out]",
 
1471
  #"-t", str(duration_s),
1472
  cmd3.extend(['-shortest', tmp_target_mp4_basename])
1473
  if app_cfg.video_codec.startswith('libx') or settings.get('force_lib'):
1474
+ logger.debug(f'[最终视频合成]不支持硬件编解码或指定了强制软编解码:\n{cmd0 + cmd1 + cmd2}')
1475
  runffmpeg(cmd0 + cmd1 + subtitle_filter + cmd2 + enc_qua + cmd3,
1476
  cmd_dir=self.cfg.cache_folder, force_cpu=True)
 
1477
  else:
1478
  # 如果硬件处理失败,回退软编
1479
  try:
 
1482
  self._subprocess(cmd0 + hw_decode_args + cmd1 + [vf_string] + cmd2 + enc_args + cmd3)
1483
  except Exception as e:
1484
  cmd2[cmd2.index('-c:v') + 1] = f'libx{self.video_codec_num}'
1485
+ logger.exception(f'硬件处理视频合成失败,回退软编 {e}', exc_info=True)
1486
  runffmpeg(cmd0 + cmd1 + subtitle_filter + cmd2 + enc_qua + cmd3,
1487
  cmd_dir=self.cfg.cache_folder, force_cpu=True)
1488
  except Exception as e:
 
1659
  return global_args, vf_string, vcodec, enc_args
1660
 
1661
  def _subprocess(self, cmd):
1662
+ logger.debug(f'[尝试硬件编解码执行命令]\n{" ".join(cmd)}\n')
1663
  try:
1664
  if app_cfg.exit_soft: return
1665
  cmd = ["ffmpeg", '-nostdin'] + cmd
 
1675
  creationflags=subprocess.CREATE_NO_WINDOW if sys.platform == 'win32' else 0,
1676
  cwd=self.cfg.cache_folder
1677
  )
 
1678
  return True
1679
  except subprocess.CalledProcessError as e:
1680
  raise FFmpegError(f"尝试使用硬件执行命令出错[CalledProcessError]:{e.stderr}\n{e.stdout},{e}") from e
videotrans/util/__pycache__/ListenVoice.cpython-310.pyc DELETED
Binary file (1.21 kB)
 
videotrans/util/__pycache__/TestSrtTrans.cpython-310.pyc DELETED
Binary file (1.37 kB)
 
videotrans/util/__pycache__/__init__.cpython-310.pyc DELETED
Binary file (138 Bytes)
 
videotrans/util/__pycache__/checkgpu.cpython-310.pyc DELETED
Binary file (941 Bytes)
 
videotrans/util/__pycache__/gpus.cpython-310.pyc DELETED
Binary file (1.69 kB)
 
videotrans/util/__pycache__/help_down.cpython-310.pyc DELETED
Binary file (10.7 kB)
 
videotrans/util/__pycache__/help_ffmpeg.cpython-310.pyc DELETED
Binary file (19.6 kB)
 
videotrans/util/__pycache__/help_misc.cpython-310.pyc DELETED
Binary file (14.6 kB)
 
videotrans/util/__pycache__/help_role.cpython-310.pyc DELETED
Binary file (11.8 kB)
 
videotrans/util/__pycache__/help_srt.cpython-310.pyc DELETED
Binary file (12.8 kB)
 
videotrans/util/__pycache__/tools.cpython-310.pyc DELETED
Binary file (246 Bytes)
 
videotrans/util/help_ffmpeg.py CHANGED
@@ -50,11 +50,11 @@ def runffmpeg(arg, *, noextname=None, force_cpu=True, cmd_dir=None):
50
  if settings.get('ffmpeg_cmd'):
51
  custom_params = [p for p in settings.get('ffmpeg_cmd', '').split(' ') if p]
52
  cmd = cmd[:-1] + custom_params + cmd[-1:]
53
-
 
54
  try:
55
  if app_cfg.exit_soft:
56
  return
57
- print(f'runffmpeg {cmd=}')
58
  subprocess.run(
59
  cmd,
60
  stdout=subprocess.PIPE,
@@ -241,7 +241,7 @@ def get_video_codec(compat=None) -> str:
241
 
242
  _codec_cache[cache_key] = selected_codec
243
  # 保存缓存到本地
244
- #Path(f"{ROOT_DIR}/videotrans/codec.json").write_text(json.dumps(_codec_cache))
245
  except Exception as e:
246
  # 发生异常不缓存
247
  logger.exception(f"在编码器测试期间发生意外,将使用软件编码: {e}", exc_info=True)
 
50
  if settings.get('ffmpeg_cmd'):
51
  custom_params = [p for p in settings.get('ffmpeg_cmd', '').split(' ') if p]
52
  cmd = cmd[:-1] + custom_params + cmd[-1:]
53
+ if cmd[-1].endswith('.mp4'):
54
+ logger.debug(f'runffmpeg:{cmd=}')
55
  try:
56
  if app_cfg.exit_soft:
57
  return
 
58
  subprocess.run(
59
  cmd,
60
  stdout=subprocess.PIPE,
 
241
 
242
  _codec_cache[cache_key] = selected_codec
243
  # 保存缓存到本地
244
+ Path(f"{ROOT_DIR}/videotrans/codec.json").write_text(json.dumps(_codec_cache))
245
  except Exception as e:
246
  # 发生异常不缓存
247
  logger.exception(f"在编码器测试期间发生意外,将使用软件编码: {e}", exc_info=True)
webui.py CHANGED
@@ -1133,7 +1133,8 @@ def build_ui():
1133
  for stage_name, method, done_msg in stages:
1134
  yield log(stage_name), None, [], _BTN_RUNNING
1135
  getattr(trk, method)()
1136
- yield log(f"✓ {done_msg}"), None, [], _BTN_RUNNING
 
1137
 
1138
  trk.task_done()
1139
  yield log("✓ 视频合成完成"), None, [], _BTN_RUNNING
@@ -1155,6 +1156,12 @@ def build_ui():
1155
  video_preview_path = str(f)
1156
  elif f.suffix.lower() in ('.mkv', '.wav', '.srt', '.txt', '.mp3'):
1157
  output_files.append(str(f))
 
 
 
 
 
 
1158
  yield log(f"输出目录: {_target_dir}"), video_preview_path, output_files, _BTN_IDLE
1159
 
1160
  except Exception as e:
 
1133
  for stage_name, method, done_msg in stages:
1134
  yield log(stage_name), None, [], _BTN_RUNNING
1135
  getattr(trk, method)()
1136
+ if method != "assembling":
1137
+ yield log(f"✓ {done_msg}"), None, [], _BTN_RUNNING
1138
 
1139
  trk.task_done()
1140
  yield log("✓ 视频合成完成"), None, [], _BTN_RUNNING
 
1156
  video_preview_path = str(f)
1157
  elif f.suffix.lower() in ('.mkv', '.wav', '.srt', '.txt', '.mp3'):
1158
  output_files.append(str(f))
1159
+ # 添加当天日志文件到输出列表
1160
+ import datetime
1161
+ log_file = Path(ROOT_DIR) / "logs" / f"{datetime.datetime.now().strftime('%Y%m%d')}.log"
1162
+ if log_file.exists():
1163
+ output_files.append(str(log_file))
1164
+
1165
  yield log(f"输出目录: {_target_dir}"), video_preview_path, output_files, _BTN_IDLE
1166
 
1167
  except Exception as e: