ming 3 роки тому
батько
коміт
da08ee3cfa

+ 27 - 22
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,7 +173,6 @@ 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
@@ -714,11 +713,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)
-    
-    for fname in range(len(text_content)):
-        call_anchor(name_hash+"/"+str(fname),avatar)
-        print('step finish')
-    print('called............................................')
+    if mode!='test':
+        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)
@@ -756,13 +755,20 @@ def anchor_video_v2(name_hash,name,text_content, image_urls,multiLang,avatar):
     
     idx = 0
     for p in listdir(dir_photo+name_hash):
-        
-        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])
+        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])
 
         img_list[idx] = openshot.FFmpegReader(dir_photo+name_hash+'/'+p)
         img_list[idx].Open()
@@ -771,15 +777,11 @@ def anchor_video_v2(name_hash,name,text_content, image_urls,multiLang,avatar):
         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()
-        anchor_list[idx].Close()
+        if mode != 'test': 
+            anchor_list[idx].Close()
         audio_list[idx].Close()
             
         sub_img_list[idx] = [None] * len(sub_list[idx])
@@ -835,7 +837,10 @@ def anchor_video_v2(name_hash,name,text_content, image_urls,multiLang,avatar):
     t.AddClip(title_clip)
 
     ####start building
-    w = openshot.FFmpegWriter(tmp_video_dir+name_hash+".mp4")
+    if mode == 'test':
+        w = openshot.FFmpegWriter("./out.mp4")
+    else:
+        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)

BIN
api/__pycache__/gSlide.cpython-38.pyc


BIN
api/__pycache__/mailer.cpython-38.pyc


BIN
api/__pycache__/main.cpython-39.pyc


BIN
api/__pycache__/models.cpython-38.pyc


+ 11 - 3
api/main.py

@@ -48,7 +48,7 @@ pymysql.install_as_MySQLdb()
 
 app = FastAPI()
 
-
+mode = 'run'
 app.add_middleware(
     CORSMiddleware,
     allow_origins=["*"],
@@ -635,9 +635,16 @@ 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
@@ -675,6 +682,7 @@ 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')

BIN
api/util/__pycache__/user.cpython-38.pyc