ming %!s(int64=3) %!d(string=hai) anos
pai
achega
18f77b5557
Modificáronse 1 ficheiros con 6 adicións e 1 borrados
  1. 6 1
      OpenshotService/openshot_video_generator.py

+ 6 - 1
OpenshotService/openshot_video_generator.py

@@ -264,8 +264,12 @@ def parse_script(file_path,gt_list):
         if len(dic['content'])>13:
             times = math.ceil(len(dic['content'])/13)
             time_ratio = []
+            left_words = len(dic['content'])%13
             for t in range(times):
-                time_ratio[t] = len(dic['content'][t*13:t*13+13])/13 * dic['duration']
+                if t != (times-1):
+                    time_ratio[t] = 1 * dic['duration']/times
+                else:
+                    time_ratio[t] = left_words/13 * dic['duration'] / times
             for t in range(times):
                 if time_ratio[t]>0.22:#about less than 3 words
                     new_dic = {}
@@ -443,6 +447,7 @@ def video_gen(name_hash,name,text_content, image_urls,multiLang,avatar):
     
     sub_dict = parse_script(tmp_video_dir+name_hash+"script.txt",split_by_pun(text_content[0]))
     generate_subtitle_image_from_dict(name_hash, sub_dict)
+    print(sub_dict)
     #sv_path = dir_subtitle + name_hash + '/' + str(script['index'])+'.png'
 
     t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)