Ver código fonte

引导可选择逻辑+ 片尾视频修复

zhangyong 11 meses atrás
pai
commit
409977aefb
4 arquivos alterados com 54 adições e 32 exclusões
  1. 27 14
      common/feishu_form.py
  2. 6 4
      common/ffmpeg.py
  3. 1 1
      common/piaoquan_utils.py
  4. 20 13
      video_rewriting/video_prep.py

+ 27 - 14
common/feishu_form.py

@@ -23,8 +23,8 @@ class Material():
             feishu_id = row[3]
             feishu_sheet = row[4]
             pw_sheet = row[5]
-
-            number = {"mark": mark, "name": name, "feishu_id": feishu_id, "feishu_sheet": feishu_sheet, "pw_sheet": pw_sheet}
+            pz_sheet = row[6]
+            number = {"mark": mark, "name": name, "feishu_id": feishu_id, "feishu_sheet": feishu_sheet, "pw_sheet": pw_sheet, "pz_sheet": pz_sheet}
             if mark:
                 list.append(number)
             else:
@@ -83,23 +83,36 @@ class Material():
         return processed_list
 
     """
-    获取对应负责人下的片尾+固定字幕
+    获取对应片尾+srt
     """
     @classmethod
-    def get_pwsrt_data(cls, feishu_id, feishu_sheet):
+    def get_pwsrt_data(cls, feishu_id, feishu_sheet, video_ending):
         data = Feishu.get_values_batch(feishu_id, feishu_sheet)
-        list = []
-        zm_list = []
+
         for row in data[1:]:
-            pw_id = row[0]
-            pw_srt = row[1]
-            zm_video = row[2]
+            pw_mark = row[0]
+            pw_id = row[1]
+            pw_srt = row[2]
             if pw_id != 'None' and pw_id != '' and pw_id != None:
-                number = {"pw_id": pw_id, "pw_srt": pw_srt}
-                list.append(number)
-            if zm_video != 'None' and zm_video != '' and zm_video != None:
-                zm_list.append(zm_video)
-        return list, zm_list
+                if pw_mark == video_ending:
+                    number = {"pw_id": pw_id, "pw_srt": pw_srt}
+                    return number
+        return ''
+
+    """
+    获取对应固定字幕
+    """
+    @classmethod
+    def get_pzsrt_data(cls, feishu_id, feishu_sheet, video_share_name):
+        data = Feishu.get_values_batch(feishu_id, feishu_sheet)
+
+        for row in data[1:]:
+            pz_mark = row[0]
+            pz_zm = row[1]
+            if pz_zm != 'None' and pz_zm != '' and pz_zm != None:
+                if pz_mark == video_share_name:
+                    return pz_zm
+        return ''
 
 
 

+ 6 - 4
common/ffmpeg.py

@@ -118,6 +118,8 @@ class FFmpeg():
         # 获取视频时长
         total_duration = cls.get_video_duration(new_video_path)
         duration = int(total_duration) - int(gg_duration_total)
+        if int(total_duration) < int(gg_duration_total):
+            duration = int(total_duration)
         ffmpeg_cmd = [
             "ffmpeg",
             "-i", new_video_path,
@@ -141,7 +143,6 @@ class FFmpeg():
         :return:
         """
         # 获取视频的原始宽高信息
-        width, height = cls.get_w_h_size(new_video_path)
         jpg_url = video_path_url + str(pw_random_id) + 'png.jpg'
         # 获取视频时长
         total_duration = cls.get_video_duration(new_video_path)
@@ -149,7 +150,7 @@ class FFmpeg():
         # 获取视频最后一秒,生成.jpg
         subprocess.run(
             ['ffmpeg', '-ss', str(time_offset), '-i', new_video_path, '-t', str(total_duration), '-vf', 'fps=1', "-y", jpg_url])
-        return jpg_url, height
+        return jpg_url
 
     """
     获取视频音频
@@ -173,7 +174,7 @@ class FFmpeg():
      生成片尾视频
     """
     @classmethod
-    def pw_video(cls, jpg_url, video_path_url, pw_url, pw_srt, pw_random_id, pw_mp3_path, height):
+    def pw_video(cls, jpg_url, video_path_url, pw_url, pw_srt, pw_random_id, pw_mp3_path):
         # 添加音频到图片
         """
         jpg_url 图片地址
@@ -194,6 +195,7 @@ class FFmpeg():
         pw_duration = cls.get_video_duration(pw_url)
         time.sleep(2)
         # 添加字幕 wqy-zenhei  Hiragino Sans GB
+        height = 1080
         margin_v = int(height) // 8  # 可根据需要调整字幕和背景之间的距离
         subtitle_cmd = f"subtitles={pw_srt_path}:force_style='Fontsize=14,Fontname=wqy-zenhei,Outline=0,PrimaryColour=&H000000,SecondaryColour=&H000000,Bold=1,MarginV={margin_v}'"
         bg_position_offset = (int(height) - margin_v) / 1.75
@@ -210,7 +212,7 @@ class FFmpeg():
             '-c:a', 'aac',  # 音频编码格式
             '-strict', 'experimental',  # 使用实验性编码器
             '-shortest',  # 确保输出视频的长度与音频一致
-            '-vf', f"{background_cmd},{subtitle_cmd}",  # 视频过滤器,设置分辨率和其他过滤器
+            '-vf', f"scale=1080x1920,{background_cmd},{subtitle_cmd}",  # 视频过滤器,设置分辨率和其他过滤器
             pw_url_path  # 输出的视频文件路径
         ]
         subprocess.run(ffmpeg_cmd)

+ 1 - 1
common/piaoquan_utils.py

@@ -81,7 +81,7 @@ class PQ:
                     new_title = data["content"]["title"]
                 else:
                     if '/' in title:
-                        titles = title.split('/')
+                        titles = [t for t in title.split('/') if t and t != "None"]
                     else:
                         titles = [title]
                     new_title = random.choice(titles)

+ 20 - 13
video_rewriting/video_prep.py

@@ -67,6 +67,7 @@ class getVideo:
         feishu_id = data["feishu_id"]
         feishu_sheet = data["feishu_sheet"]
         pw_sheet = data["pw_sheet"]
+        pz_sheet = data["pz_sheet"]
 
         task_data = Material.get_task_data(feishu_id, feishu_sheet)
         if len(task_data) == 0:
@@ -84,6 +85,21 @@ class getVideo:
             video_ending = task["video_ending"]
             crop_total = task["crop_total"]
             gg_duration_total = task["gg_duration_total"]
+            if video_share and video_share != 'None':
+                video_share_list = video_share.split('/')
+                video_share_mark = video_share_list[0]
+                video_share_name = video_share_list[1]
+                zm = Material.get_pzsrt_data(feishu_id, pz_sheet, video_share_name)  # 获取srt
+                if zm == '':
+                    Feishu.bot(mark, '机器自动改造消息通知', f'{task_marks}任务下片中标示填写错误,请关注!!!!', name)
+            if video_ending and video_ending != 'None':
+                pw_list = Material.get_pwsrt_data(feishu_id, pw_sheet, video_ending)  # 获取srt
+                if pw_list:
+                    pw_id = pw_list["pw_id"]
+                    pw_srt = pw_list["pw_srt"]
+                    pw_url = PQ.get_pw_url(pw_id)
+                else:
+                    Feishu.bot(mark, '机器自动改造消息通知', f'{task_marks}任务下片尾标示错误,请关注!!!!', name)
             if ',' in new_id:
                 n_id = new_id.split(',')
             else:
@@ -98,9 +114,6 @@ class getVideo:
             try:
                 count = 0  # 初始化计数器
                 for id in task_id:
-                    pw_list, zm_list = Material.get_pwsrt_data(feishu_id, pw_sheet)  # 获取srt
-                    zm = random.choice(zm_list)  # 随机选择 视频中字幕
-                    pws = random.choice(pw_list)  # 随机选择 片尾srt+音频
                     Common.logger("log").info(f"{task_mark}下的ID{id} 开始获取视频")
                     time.sleep(1)
                     if old_id and old_id != 'None':
@@ -131,14 +144,8 @@ class getVideo:
                         if gg_duration_total and gg_duration_total != 'None':  # 判断是否需要指定视频时长
                             new_video_path = FFmpeg.video_ggduration(new_video_path, video_path_url, pw_random_id, gg_duration_total)
                         if video_ending and video_ending != 'None':
-                            pw_id = pws["pw_id"]
-                            pw_srt = pws["pw_srt"]
-                            pw_url = PQ.get_pw_url(pw_id)
-
-                            jpg_path = None
-                            pw_path = None
                             for attempt in range(3):
-                                jpg_path, height = FFmpeg.video_png(new_video_path, video_path_url, pw_random_id)  # 生成视频最后一帧jpg
+                                jpg_path = FFmpeg.video_png(new_video_path, video_path_url, pw_random_id)  # 生成视频最后一帧jpg
                                 if os.path.isfile(jpg_path):
                                     Common.logger("log").info(f"{task_mark}下的视频ID{id},生成视频最后一帧成功")
                                     break
@@ -149,7 +156,7 @@ class getVideo:
                                 continue
                             for attempt in range(3):
                                 pw_mp3_path = FFmpeg.get_video_mp3(pw_url, video_path_url, pw_random_id)
-                                pw_path = FFmpeg.pw_video(jpg_path, video_path_url, pw_url, pw_srt, pw_random_id, pw_mp3_path, height)  # 生成片尾视频
+                                pw_path = FFmpeg.pw_video(jpg_path, video_path_url, pw_url, pw_srt, pw_random_id, pw_mp3_path)  # 生成片尾视频
                                 if os.path.isfile(pw_path):
                                     Common.logger("log").info(f"{task_mark}下的视频ID{id},生成片尾视频成功")
                                     break
@@ -163,12 +170,12 @@ class getVideo:
                             video_path = FFmpeg.concatenate_videos(pw_video_list, video_path_url)  # 视频与片尾拼接到一起
                             time.sleep(1)
                             if video_share and video_share != 'None':
-                                new_video_path = FFmpeg.single_video(video_path, video_share, video_path_url, zm)
+                                new_video_path = FFmpeg.single_video(video_path, video_share_mark, video_path_url, zm)
                             else:
                                 new_video_path = video_path
                         else:
                             if video_share and video_share != 'None':
-                                new_video_path = FFmpeg.single_video(new_video_path, video_share, video_path_url, zm)
+                                new_video_path = FFmpeg.single_video(new_video_path, video_share_mark, video_path_url, zm)
                         time.sleep(1)
                         oss_id = cls.random_id()
                         oss_object_key = Oss.stitching_sync_upload_oss(new_video_path, oss_id)  # 视频发送OSS