Quellcode durchsuchen

add image display test

ming vor 3 Jahren
Ursprung
Commit
f745e48dde
2 geänderte Dateien mit 38 neuen und 1 gelöschten Zeilen
  1. 19 1
      OpenshotService/openshot_video_generator.py
  2. 19 0
      OpenshotService/util/parser.py

+ 19 - 1
OpenshotService/openshot_video_generator.py

@@ -433,7 +433,6 @@ def parse_script(file_path,gt_list):
             ind_duration = duration * sub_dic['time_ratio']
             new_dic['start'] = dic['start'] + accumulated_duration
             accumulated_duration += ind_duration
-            
             new_dic['content'] = sub_dic['content']
             new_dic['duration'] = ind_duration*0.7
             splitted_dict.append(new_dic)
@@ -599,6 +598,7 @@ def video_gen(name_hash,name,text_content, image_urls,multiLang,avatar):
     t.AddClip(bg_left_clip)
     bg_left.Close()
 
+
     title = openshot.QtImageReader(dir_title+name_hash+".png")
     title.Open()         # Open the reader
     title_clip = video_photo_clip(vid=title, layer=4,location_x=-0.047, location_y=0.801,position=0,end=head_duration+main_timer)
@@ -622,6 +622,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]))
     for subd in sub_dict:
         print(subd)
+    
     generate_subtitle_image_from_dict(name_hash, sub_dict)
 
     #sv_path = dir_subtitle + name_hash + '/' + str(script['index'])+'.png'
@@ -634,6 +635,8 @@ def video_gen(name_hash,name,text_content, image_urls,multiLang,avatar):
     raw_clip = video_photo_clip(vid=raw,layer=2,position=0, end=raw.info.duration)
     t.AddClip(raw_clip)
     
+
+
     sub_img_list = [None] * len(sub_dict)
     sub_clip_list = [None] * len(sub_dict)
     for sub_obj in sub_dict:
@@ -644,6 +647,21 @@ def video_gen(name_hash,name,text_content, image_urls,multiLang,avatar):
         t.AddClip(sub_clip_list[idx])
         sub_img_list[idx].Close()
 
+
+    text_parser tp = parser()
+    img_dict_ls = tp.image_clip_info(sub_dict)
+    #if 'image_idx' in dic:
+    #            new_dic['image_obj'] = {'start':dic['start'],'idx':dic['image_idx']}
+    img_clip_list = [None]*len(text_content)
+    img_list = [None]*len(text_content)
+    for p in listdir(dir_photo+name_hash):
+        img_list[idx] = openshot.FFmpegReader(dir_photo+name_hash+'/'+p)
+        img_list[idx].Open()
+        img_clip_list[idx] = video_photo_clip(vid=img_list[idx],layer=3
+                ,scale_x=0.81,scale_y=0.68,location_y=-0.03,position=img_dict_ls[int(p)+1]['start'],end=img_dict_ls[int(p)+1]['duration'],audio=False)
+        t.AddClip(img_clip_list[idx])
+        img_list[idx].Close()
+
     anchor = openshot.FFmpegReader(dir_anchor+name_hash+"/0.mp4")
     anchor.Open()
     anchor_clip = video_photo_clip(vid=anchor,layer=4,scale_x=0.65,scale_y=0.65,

+ 19 - 0
OpenshotService/util/parser.py

@@ -33,5 +33,24 @@ class parser:
         for p in pair_obj['pair']:
             rep_ls.append(text[p['left']:p['right']+1])
         return rep_ls
+    
+    def image_clip_info(self,dict_in):
+        #if 'image_idx' in dic:
+    #            new_dic['image_obj'] = {'start':dic['start'],'idx':dic['image_idx']}
+        stopPoint = 0 # sec
+        time_info = []
+        img_idx = 1 #start from 1
+        for dic in dict_in:
+            if 'image_obj' in dic:
+                time_info.append({'index':img_idx,'start':dic['start']})
+                img_idx += 1
+            stopPoint = dic['start']+dic['duration']
+        
+        for idx in range(len(time_info)-1):
+            time_info[idx]['duration'] = time_info[idx+1]['start']-time_info[idx]['start']
+        time_info[:-1]['duration'] = stopPoint
+        #index start duration
+        return time_info               
+