Bläddra i källkod

fix loop error

ming 3 år sedan
förälder
incheckning
d479f294aa
2 ändrade filer med 25 tillägg och 39 borttagningar
  1. 23 28
      OpenshotService/openshot_video_generator.py
  2. 2 11
      api/main.py

+ 23 - 28
OpenshotService/openshot_video_generator.py

@@ -40,7 +40,7 @@ dir_subtitle = 'subtitle/'
 dir_anchor = 'anchor_raw/'
 tmp_video_dir = 'tmp_video/'
 video_sub_folder = 'ai_anchor_video/'
-mode ='run'
+
 dir_list = [dir_sound,dir_photo,dir_text,dir_video,dir_title,dir_subtitle,dir_anchor,tmp_video_dir]
 
 def notify_group(msg):
@@ -173,6 +173,7 @@ def file_prepare(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
     #make title as image
     txt2image_title(name, dir_title+name_hash+".png",lang)
 
+
 def file_prepare_long(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
     make_dir(name_hash)
     img_num = 1
@@ -713,11 +714,11 @@ def anchor_video_v2(name_hash,name,text_content, image_urls,multiLang,avatar):
     print(multiLang)
     file_prepare(name, name_hash, text_content,image_urls,multiLang)
     sub_list=generate_subtitle_image(name_hash,text_content)
-    if mode!='test':
-        for fname in range(len(text_content)):
-            call_anchor(name_hash+"/"+str(fname),avatar)
-            print('step finish')
-        print('called............................................')
+    
+    for fname in range(len(text_content)):
+        call_anchor(name_hash+"/"+str(fname),avatar)
+        print('step finish')
+    print('called............................................')
 
     ck=cKey(0,254,0,270)
     ck_anchor=cKey(0,255,1,320)
@@ -755,33 +756,30 @@ def anchor_video_v2(name_hash,name,text_content, image_urls,multiLang,avatar):
     
     idx = 0
     for p in listdir(dir_photo+name_hash):
-        audio_list[idx] = openshot.FFmpegReader(dir_sound+name_hash+"/"+str(idx)+".mp3")
-        audio_list[idx].Open()
-        clip_duration = audio_list[idx].info.duration
-        audio_clip_list[idx] = openshot.Clip(audio_list[idx])
-        audio_clip_list[idx].Position(main_timer)
-        audio_clip_list[idx].End(clip_duration)
-        t.AddClip(audio_clip_list[idx])
-        if mode != 'test': 
-            anchor_list[idx] = openshot.FFmpegReader(dir_anchor+name_hash+"/"+str(idx)+".mp4")
-            #clip_duration = anchor_list[idx].info.duration
-            #anchor_list[idx].Open()
-            #anchor_clip_list[idx] = video_photo_clip(vid=anchor_list[idx],layer=4,scale_x=0.65,scale_y=0.65,
-            #        location_x=0.35,location_y=0.25,position=main_timer, end=clip_duration,ck=ck_anchor,audio=False)
-           # t.AddClip(anchor_clip_list[idx])
+        
+        anchor_list[idx] = openshot.FFmpegReader(dir_anchor+name_hash+"/"+str(idx)+".mp4")
+        clip_duration = anchor_list[idx].info.duration
+        anchor_list[idx].Open()
+        anchor_clip_list[idx] = video_photo_clip(vid=anchor_list[idx],layer=4,scale_x=0.65,scale_y=0.65,
+                location_x=0.35,location_y=0.25,position=main_timer, end=clip_duration,ck=ck_anchor,audio=False)
+        t.AddClip(anchor_clip_list[idx])
 
         img_list[idx] = openshot.FFmpegReader(dir_photo+name_hash+'/'+p)
         img_list[idx].Open()
         photo_clip_list[idx] = video_photo_clip(vid=img_list[idx],layer=3
-                ,scale_x=0.8,scale_y=0.684,location_y=-0.03,position=main_timer,end=clip_duration,audio=False)
+                ,scale_x=0.8,scale_y=0.704,location_y=-0.03,position=main_timer,end=clip_duration,audio=False)
         t.AddClip(photo_clip_list[idx])
         img_list[idx].Close()
 
-        
+        audio_list[idx] = openshot.FFmpegReader(dir_sound+name_hash+"/"+str(idx)+".mp3")
+        audio_list[idx].Open()
+        audio_clip_list[idx] = openshot.Clip(audio_list[idx])
+        audio_clip_list[idx].Position(main_timer)
+        audio_clip_list[idx].End(clip_duration)
+        t.AddClip(audio_clip_list[idx])
 
         img_list[idx].Close()
-        if mode != 'test': 
-            anchor_list[idx].Close()
+        anchor_list[idx].Close()
         audio_list[idx].Close()
             
         sub_img_list[idx] = [None] * len(sub_list[idx])
@@ -837,10 +835,7 @@ def anchor_video_v2(name_hash,name,text_content, image_urls,multiLang,avatar):
     t.AddClip(title_clip)
 
     ####start building
-    if mode == 'test':
-        w = openshot.FFmpegWriter("./out.mp4")
-    else:
-        w = openshot.FFmpegWriter(tmp_video_dir+name_hash+".mp4")
+    w = openshot.FFmpegWriter(tmp_video_dir+name_hash+".mp4")
     w.SetAudioOptions(True, "aac", 44100, 2, openshot.LAYOUT_STEREO, 3000000)
     w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 1280, 720,
         openshot.Fraction(1, 1), False, False, 3000000)

+ 2 - 11
api/main.py

@@ -622,7 +622,6 @@ def gen_video_long_queue(name_hash,name,text_content, image_urls,avatar,multiLan
             notify_group('長影片錯誤-測試')
         db['video_queue'].delete(id=top1['id'])
         db.query('UPDATE video_queue_status SET status = 0')
-
 def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,video_id,user_id):
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
     time_stamp = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S")
@@ -635,16 +634,9 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,vid
         img_urls_seperate_by_dot += iurl+","
     img_urls_seperate_by_dot = img_urls_seperate_by_dot[:-1]
     
-   
+    db['video_queue'].insert({'name_hash':name_hash,'name':name,'text_content':txt_content_seperate_by_dot,'image_urls':img_urls_seperate_by_dot,'multiLang':multiLang,'avatar':avatar,'timestamp':time_stamp})
     while True:
-        if mode=='test':
-            top1= {'name_hash':name_hash,'name':name,'text_content':txt_content_seperate_by_dot,'image_urls':img_urls_seperate_by_dot,'multiLang':multiLang,'avatar':avatar,'timestamp':time_stamp}
-            c = rpyc.connect("localhost", 8858)
-            remote_svc = c.root
-            my_answer = remote_svc.call_video(top1['name_hash'],top1['name'],top1['text_content'].split(','), top1['image_urls'].split(','),top1['multiLang'],top1['avatar']) # method call
-            
-            break
-        db['video_queue'].insert({'name_hash':name_hash,'name':name,'text_content':txt_content_seperate_by_dot,'image_urls':img_urls_seperate_by_dot,'multiLang':multiLang,'avatar':avatar,'timestamp':time_stamp})
+        
         if first(db.query('SELECT * FROM video_queue_status'))['status'] == 1:#only one row in this table, which is the id 1 one
             print('another process running, leave loop')#1 means already running
             break
@@ -682,7 +674,6 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,vid
                 db.query('UPDATE users SET left_time ='+str(left_time)+' WHERE id='+str(user_id)+';')
                 notify_group(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
                 #notify_line_user(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4", line_token)
-            
         except Exception as e:
             logging.error(traceback.format_exc())
             print('video generation error')