diff --git a/version.json b/version.json index cca563ee..c997368a 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { - "version": "1.43", - "version_num": 11043 + "version": "1.44", + "version_num": 11044 } diff --git a/videotrans/__init__.py b/videotrans/__init__.py index 45e1f172..4ee952a7 100644 --- a/videotrans/__init__.py +++ b/videotrans/__init__.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- -VERSION="v1.43 pyvideotrans.com" -VERSION_NUM=11043 +VERSION="v1.44 pyvideotrans.com" +VERSION_NUM=11044 \ No newline at end of file diff --git a/videotrans/mainwin/secwin.py b/videotrans/mainwin/secwin.py index b5d7d025..69a6a822 100644 --- a/videotrans/mainwin/secwin.py +++ b/videotrans/mainwin/secwin.py @@ -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): diff --git a/videotrans/mainwin/spwin.py b/videotrans/mainwin/spwin.py index 1c47efa3..cd85892f 100644 --- a/videotrans/mainwin/spwin.py +++ b/videotrans/mainwin/spwin.py @@ -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) diff --git a/videotrans/set.ini b/videotrans/set.ini index 70bfd21c..565481f5 100644 --- a/videotrans/set.ini +++ b/videotrans/set.ini @@ -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 diff --git a/videotrans/task/trans_create.py b/videotrans/task/trans_create.py index 40ead7e8..b6711a84 100644 --- a/videotrans/task/trans_create.py +++ b/videotrans/task/trans_create.py @@ -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: @@ -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: @@ -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" @@ -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 @@ -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 # 更改时间戳 @@ -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 @@ -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) @@ -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") @@ -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"], diff --git a/videotrans/ui/article.py b/videotrans/ui/article.py index 7ee09b41..bd8fadef 100644 --- a/videotrans/ui/article.py +++ b/videotrans/ui/article.py @@ -49,11 +49,17 @@ def retranslateUi(self, articleform): a:hover{color:#ff0}
-