Skip to content

Commit

Permalink
fix: bugs and update
Browse files Browse the repository at this point in the history
  • Loading branch information
jianchang512 committed Mar 30, 2024
1 parent c70f1b7 commit b9eda0c
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 38 deletions.
4 changes: 2 additions & 2 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.43",
"version_num": 11043
"version": "1.44",
"version_num": 11044
}
4 changes: 2 additions & 2 deletions videotrans/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

VERSION="v1.43 pyvideotrans.com"
VERSION_NUM=11043
VERSION="v1.44 pyvideotrans.com"
VERSION_NUM=11044
10 changes: 6 additions & 4 deletions videotrans/mainwin/secwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,17 +643,19 @@ def open_url(self, title):
elif title == 'dll':
webbrowser.open_new_tab("https://github.com/jianchang512/stt/releases/tag/v0.0.1")
elif title == 'gtrans':
webbrowser.open_new_tab("https://juejin.cn/post/7339210740454719523")
webbrowser.open_new_tab("https://www.pyvideotrans.com/15.html")
elif title == 'cuda':
webbrowser.open_new_tab("https://juejin.cn/post/7318704408727519270")
webbrowser.open_new_tab("https://www.pyvideotrans.com/gpu.html")
elif title == 'website':
webbrowser.open_new_tab("https://pyvideotrans.com")
webbrowser.open_new_tab("https://www.pyvideotrans.com")
elif title == 'xinshou':
webbrowser.open_new_tab("https://pyvideotrans.com/guide.html" if config.defaulelang!='zh' else 'https://juejin.cn/post/7331558973657251840')
webbrowser.open_new_tab("https://www.pyvideotrans.com/guide.html")
elif title == "about":
webbrowser.open_new_tab("https://github.com/jianchang512/pyvideotrans/blob/main/about.md")
elif title == 'download':
webbrowser.open_new_tab("https://github.com/jianchang512/pyvideotrans/releases")
elif title == 'online':
webbrowser.open_new_tab("https://tool.pyvideotrans.com/trans.html")

# 工具箱
def open_toolbox(self, index=0, is_hide=True):
Expand Down
1 change: 1 addition & 0 deletions videotrans/mainwin/spwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def bind_action(self):
self.action_dll.triggered.connect(lambda: self.util.open_url('dll'))
self.action_gtrans.triggered.connect(lambda: self.util.open_url('gtrans'))
self.action_cuda.triggered.connect(lambda: self.util.open_url('cuda'))
self.action_online.triggered.connect(lambda: self.util.open_url('online'))
self.action_website.triggered.connect(lambda: self.util.open_url('website'))
self.action_blog.triggered.connect(lambda: self.util.open_url('blog'))
self.statusLabel.clicked.connect(self.util.helparticle)
Expand Down
4 changes: 2 additions & 2 deletions videotrans/set.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ chatgpt_model=gpt-3.5-turbo,gpt-4,gpt-4-turbo-preview,qwen,moonshot-v1-8k

;声画字幕对齐相关#################################
;音频最大加速倍数,默认1.8,即最大加速到 1.8倍速度,配音仍大于原时长,就进行视频慢速,需设置大于1-100的数字,比如1.5,代表最大加速1.5倍,注意如何设置了限制,则字幕声音将无法对齐
audio_rate=1.8
audio_rate=1.5

; 设为大于1的数,代表最大允许慢速多少倍,0或1代表不进行视频慢放
video_rate=0
video_rate=20

;是否移除配音末尾空白,true=移除,false=不移除
remove_silence=true
Expand Down
50 changes: 27 additions & 23 deletions videotrans/task/trans_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ def merge_audio_segments(self, *, queue_tts=None, video_time=0):
# join
offset=0
for i,it in enumerate(queue_tts):
it['raw_duration']=it['end_time']-it['start_time']
if it['raw_duration']==0:
continue
if not os.path.exists(it['filename']) or os.path.getsize(it['filename'])<1:
Expand Down Expand Up @@ -463,7 +464,7 @@ def merge_audio_segments(self, *, queue_tts=None, video_time=0):
if silence_duration > 0:
silence = AudioSegment.silent(duration=silence_duration)
merged_audio += silence
if not config.settings['force_edit_srt']:
if config.settings['force_edit_srt']:
it['startraw']=ms_to_time_string(ms=it['start_time'])
it['endraw']=ms_to_time_string(ms=it['end_time'])
else:
Expand All @@ -473,13 +474,15 @@ def merge_audio_segments(self, *, queue_tts=None, video_time=0):
merged_audio += segment

# 移除尾部静音
if config.settings['remove_silence']:
if config.settings['remove_silence'] or (video_time>0 and merged_audio and (len(merged_audio) > video_time)):
merged_audio=tools.remove_silence_from_end(merged_audio,silence_threshold=-50.0, chunk_size=10,is_start=False)

if video_time > 0 and merged_audio and (len(merged_audio) < video_time):
# 末尾补静音
silence = AudioSegment.silent(duration=video_time - len(merged_audio))
merged_audio += silence


# 创建配音后的文件
try:
wavfile = self.cache_folder + "/target.wav"
Expand All @@ -493,7 +496,7 @@ def merge_audio_segments(self, *, queue_tts=None, video_time=0):
else:
wav2m4a(wavfile, self.targetdir_target_wav)
except Exception as e:
raise Exception(f'[error]merge_audio:{str(e)}')
raise Exception(f'[error]merged_audio:{str(e)}')

return len(merged_audio), queue_tts

Expand Down Expand Up @@ -741,9 +744,7 @@ def _ajust_audio(self, queue_tts):
# 需要延长结束时间,以便字幕 声音对齐
it['end_time'] += add_time
offset += add_time
it['video_add'] = add_time
it['raw_duration']=it['end_time']-it['start_time']
# os.unlink(it['filename'])
it['filename'] = tmp_mp3

# 更改时间戳
Expand Down Expand Up @@ -782,13 +783,18 @@ def _ajust_video(self, queue_tts):
source=self.novoice_mp4,
out=before_dst)
concat_txt_arr.append(before_dst)


# 当前可用时间段
duration=it['end_time']-it['start_time']
audio_length=duration
# 实际配音长度
if os.path.exists(it['filename']) and os.path.getsize(it['filename'])>0:
audio_length=len(AudioSegment.from_file(it['filename'], format="mp3"))
print(f'{duration=}============={audio_length=}')
# 需要延长视频
if 'video_add' in it and it['video_add'] > 0:
if audio_length>duration:
filename_video = self.cache_folder + f'/{i}.mp4'

speed =round( (it['end_time']-it['start_time'])/(it['end_time_source']-it['start_time_source']),2)
speed =round(audio_length/duration,3)
print(f'视频慢速 {speed=}')
if speed<=1:
speed=1
Expand All @@ -798,26 +804,26 @@ def _ajust_video(self, queue_tts):
if speed>config.settings['video_rate']:
speed=config.settings['video_rate']

set_process(f"{config.transobj['video speed down']} {speed}")
set_process(f"{config.transobj['video speed down']}[{i}] {speed=}")
# 截取原始视频
cut_from_video(ss=ms_to_time_string(ms=it['start_time_source']),
to=ms_to_time_string(ms=it['end_time_source']),
cut_from_video(ss=ms_to_time_string(ms=it['start_time']),
to=ms_to_time_string(ms=it['end_time'] if it['end_time'] < last_time else last_time),
source=self.novoice_mp4,
pts= "" if speed<=1 else speed,
out=filename_video)
concat_txt_arr.append(filename_video)
elif it['end_time_source'] > it['start_time_source']:
elif it['end_time'] > it['start_time']:
filename_video = self.cache_folder + f'/{i}.mp4'
concat_txt_arr.append(filename_video)
# 直接截取原始片段,不慢放
cut_from_video(ss=ms_to_time_string(ms=it['start_time_source']),
to=ms_to_time_string(ms=it['end_time_source']),
cut_from_video(ss=ms_to_time_string(ms=it['start_time']),
to=ms_to_time_string(ms=it['end_time'] if it['end_time'] < last_time else last_time),
source=self.novoice_mp4,
out=filename_video)
set_process(f"{config.transobj['video speed down']}")
if queue_tts[-1]['end_time_source'] < last_time:
set_process(f"{config.transobj['video speed down']}[{i}] speed=1")
if queue_tts[-1]['end_time'] < last_time:
last_v = self.cache_folder + "/last_dur.mp4"
cut_from_video(ss=ms_to_time_string(ms=queue_tts[-1]['end_time_source']),
cut_from_video(ss=ms_to_time_string(ms=queue_tts[-1]['end_time']),
source=self.novoice_mp4,
out=last_v)
concat_txt_arr.append(last_v)
Expand Down Expand Up @@ -910,7 +916,7 @@ def exec_tts(self, queue_tts):
def novoicemp4_add_time(self, duration_ms):
if config.current_status != 'ing':
return False
duration_ms=1000 if duration_ms<1000 else duration_ms
duration_ms=100 if duration_ms<100 else duration_ms
set_process(f'{transobj["shipinmoweiyanchang"]} {duration_ms}ms')
if not is_novoice_mp4(self.novoice_mp4, self.noextname):
raise Myexcept("not novoice mp4")
Expand All @@ -929,15 +935,13 @@ def novoicemp4_add_time(self, duration_ms):

clip_time=get_video_duration(self.cache_folder+"/last-clip-novoice.mp4")

#shutil.copy2(self.cache_folder+"/last-clip-novoice.mp4", f'{self.novoice_mp4}.lastclip.mp4')
nums=math.ceil(duration_ms/clip_time)
nums+=int(nums/3)
nums+=math.ceil(nums/3)
concat_multi_mp4(
filelist=[self.cache_folder+"/last-clip-novoice.mp4" for x in range(nums)],
out=self.cache_folder+"/last-clip-novoice-all.mp4"
)

#shutil.copy2(self.cache_folder+"/last-clip-novoice-all.mp4", f'{self.novoice_mp4}.last-clip-novoice-all.mp4')

concat_multi_mp4(
filelist=[f'{self.novoice_mp4}.raw.mp4',self.cache_folder+"/last-clip-novoice-all.mp4"],
Expand Down
14 changes: 10 additions & 4 deletions videotrans/ui/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ def retranslateUi(self, articleform):
a:hover{color:#ff0}
</style></head>
<body style="font-size:9pt; font-weight:400; font-style:normal;">
<h2>
<a href="https://pyvideotrans.com">
最新教程请查看文档网站 pyvideotrans.com 或微信公众号(pyvideotrans)
<div>
<a href="https://www.pyvideotrans.com" style="font-size:18px">
最新教程请查看文档网站 pyvideotrans.com
</a>
</h2>
<br>
<a href="https://tool.pyvideotrans.com/trans.html" style="font-size:14px;color:#aaa;display:block;margin-top:12px">
在线免费视频翻译:使用更简单,无需注册无需登录,点击打开
</a>
</div>
<ul>
Expand Down
8 changes: 7 additions & 1 deletion videotrans/ui/en.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@ def setupUi(self, MainWindow):
self.action_gtrans.setObjectName("action_gtrans")
self.action_cuda = QtGui.QAction(MainWindow)
self.action_cuda.setObjectName("action_cuda")

self.action_online = QtGui.QAction(MainWindow)
self.action_online.setObjectName("action_online")

self.actiontencent_key = QtGui.QAction(MainWindow)
self.actiontencent_key.setObjectName("actiontencent_key")
self.action_about = QtGui.QAction(MainWindow)
Expand Down Expand Up @@ -655,6 +659,8 @@ def setupUi(self, MainWindow):
self.menu_H.addSeparator()
self.menu_H.addAction(self.action_blog)
self.menu_H.addSeparator()
self.menu_H.addAction(self.action_online)
self.menu_H.addSeparator()
self.menu_H.addAction(self.action_models)
self.menu_H.addSeparator()
self.menu_H.addAction(self.action_gtrans)
Expand Down Expand Up @@ -730,7 +736,6 @@ def retranslateUi(self, MainWindow):
self.voice_autorate.setText(config.uilanglist.get("Voice acceleration?"))
self.auto_ajust.setText(config.transobj.get("auto_ajust"))
self.auto_ajust.setToolTip(config.uilanglist.get("shuoming03"))
# self.enable_cuda.setToolTip(config.uilanglist.get("It is necessary to ensure that there is an NVIDIA graphics card and that the CUDA environment is correctly configured, otherwise do not choose"))
self.enable_cuda.setText(config.uilanglist.get("Enable CUDA?"))
self.is_separate.setText(config.uilanglist.get("Preserve background music"))
self.is_separate.setToolTip(config.uilanglist.get("If retained, the required time may be longer, please be patient and wait"))
Expand Down Expand Up @@ -769,6 +774,7 @@ def retranslateUi(self, MainWindow):
self.action_dll.setText(config.uilanglist["Download cuBLASxx.dll"])
self.action_gtrans.setText(config.transobj["miandailigoogle"])
self.action_cuda.setText('CUDA')
self.action_online.setText('在线免费视频翻译' if config.defaulelang=='zh' else 'Web Online VideoTrans')
self.actiontencent_key.setText("腾讯翻译设置" if config.defaulelang=='zh' else "Tencent Key")
self.action_about.setText(config.uilanglist.get("Donating developers"))
self.action_biaozhun.setText(config.uilanglist.get("Standard Function Mode"))
Expand Down

0 comments on commit b9eda0c

Please sign in to comment.