@@ -100,6 +100,8 @@ def __init__(self, vd_path, sub_area=None):
100100 self .vsf_subtitle = os .path .join (self .subtitle_output_dir , 'raw_vsf.srt' )
101101 # 提取的原始字幕文本存储路径
102102 self .raw_subtitle_path = os .path .join (self .subtitle_output_dir , 'raw.txt' )
103+ # 定义输出字幕文件路径
104+ self .subtitle_output_path = os .path .splitext (self .video_path )[0 ] + '.srt'
103105 # 自定义ocr对象
104106 self .ocr = None
105107 # 总处理进度
@@ -199,15 +201,15 @@ def run(self):
199201 # 如果未使用vsf提取字幕,则使用常规字幕生成方法
200202 self .generate_subtitle_file ()
201203 if config .wordSegmentation .value :
202- reformat .execute (os . path . join ( os . path . splitext ( self .video_path )[ 0 ] + '.srt' ) , config .language .value )
204+ reformat .execute (self .subtitle_output_path , config .language .value )
203205 self .append_output (tr ['Main' ]['FinishGenerateSub' ], f"{ round (time .time () - start_time , 2 )} s" )
204206 self .update_progress (ocr = 100 , frame_extract = 100 )
205207 self .isFinished = True
206208 # 删除缓存文件
207209 self .empty_cache ()
208210 self .lock .release ()
209211 if config .generateTxt .value :
210- self .srt2txt (os . path . join ( os . path . splitext ( self .video_path )[ 0 ] + '.srt' ) )
212+ self .srt2txt (self .subtitle_output_path )
211213
212214 def capture_frame_with_subtitle_area (self ):
213215 """
@@ -632,10 +634,9 @@ def generate_subtitle_file(self):
632634 """
633635 if not self .use_vsf :
634636 subtitle_content = self ._remove_duplicate_subtitle ()
635- srt_filename = os .path .join (os .path .splitext (self .video_path )[0 ] + '.srt' )
636637 # 保存持续时间不足1秒的字幕行,用于后续处理
637638 post_process_subtitle = []
638- with open (srt_filename , mode = 'w' , encoding = 'utf-8' ) as f :
639+ with open (self . subtitle_output_path , mode = 'w' , encoding = 'utf-8' ) as f :
639640 for index , content in enumerate (subtitle_content ):
640641 line_code = index + 1
641642 frame_start = self ._frame_to_timecode (int (content [0 ]))
@@ -648,7 +649,7 @@ def generate_subtitle_file(self):
648649 frame_content = content [2 ]
649650 subtitle_line = f'{ line_code } \n { frame_start } --> { frame_end } \n { frame_content } \n '
650651 f .write (subtitle_line )
651- self .append_output (f"[NO-VSF]{ tr ['Main' ]['SubLocation' ]} { srt_filename } " )
652+ self .append_output (f"[NO-VSF]{ tr ['Main' ]['SubLocation' ]} { self . subtitle_output_path } " )
652653 # 返回持续时间低于1s的字幕行
653654 return post_process_subtitle
654655
@@ -681,9 +682,8 @@ def generate_subtitle_file_vsf(self):
681682 final_subtitles .append (sub )
682683 continue
683684
684- srt_filename = os .path .join (os .path .splitext (self .video_path )[0 ] + '.srt' )
685- pysrt .SubRipFile (final_subtitles ).save (srt_filename , encoding = 'utf-8' )
686- self .append_output (f"[VSF]{ tr ['Main' ]['SubLocation' ]} { srt_filename } " )
685+ pysrt .SubRipFile (final_subtitles ).save (self .subtitle_output_path , encoding = 'utf-8' )
686+ self .append_output (f"[VSF]{ tr ['Main' ]['SubLocation' ]} { self .subtitle_output_path } " )
687687
688688 def _detect_watermark_area (self ):
689689 """
@@ -1047,6 +1047,8 @@ def get_ocr_progress():
10471047 'HARDWARD_ACCELERATOR' : self .hardware_accelerator ,
10481048 }
10491049 process , task_queue , progress_queue = subtitle_ocr .async_start (self .video_path , self .raw_subtitle_path , self .sub_area , options )
1050+ ProcessManager .instance ().add_process (process )
1051+ self .manage_process (process .pid )
10501052 self .subtitle_ocr_task_queue = task_queue
10511053 self .subtitle_ocr_progress_queue = progress_queue
10521054 # 开启线程负责更新OCR进度
0 commit comments