Explorar o código

恢复 片中字幕

zhangyong hai 8 meses
pai
achega
1c928e4506
Modificáronse 2 ficheiros con 11 adicións e 18 borrados
  1. 9 16
      common/ffmpeg.py
  2. 2 2
      video_rewriting/video_processor.py

+ 9 - 16
common/ffmpeg.py

@@ -293,14 +293,13 @@ class FFmpeg():
         subprocess.run(ffmpeg_cmd)
         return concatenate_videos_url
 
-
     """
     单个视频拼接
     """
     @classmethod
-    def single_video(cls, new_video_path, video_path_url):
+    def single_video(cls, new_video_path, video_path_url, zm):
         single_video_url = video_path_url + 'single_video.mp4'
-        # single_video_srt = video_path_url + 'single_video.srt'
+        single_video_srt = video_path_url + 'single_video.srt'
         # 获取时长
         duration = cls.get_video_duration(new_video_path)
         start_time = cls.seconds_to_srt_time(0)
@@ -308,21 +307,15 @@ class FFmpeg():
         single_video_txt = video_path_url + 'single_video.txt'
         with open(single_video_txt, 'w') as f:
             f.write(f"file '{new_video_path}'\n")
-        # with open(single_video_srt, 'w') as f:
-        #     f.write(f"1\n{start_time} --> {end_time}\n\u2764\uFE0F{zm}\n\n")
-        # width, height = cls.get_w_h_size(new_video_path)
         height = 1080
         box_height = int(int(height) / 4)  # 框的高度为视频高度的四分之一
-
-        background_cmd = f"drawbox=y=ih-{70 + box_height}-{int(box_height / 20)}:color=yellow@1.0:width=iw:height={box_height}:t=fill"
-
-        # if video_share == '有':
-        #     # 添加字幕 wqy-zenhei  Hiragino Sans GB
-        #     subtitle_cmd = f"subtitles={single_video_srt}:force_style='Fontsize=14,Fontname=wqy-zenhei,Outline=0,PrimaryColour=&H000000,SecondaryColour=&H000000,Bold=1,MarginV=20'"
-        #     draw = f"{background_cmd},{subtitle_cmd}"
-        # else:
-        subtitle_cmd = f"force_style='Fontsize=14,Fontname=wqy-zenhei,Outline=2,PrimaryColour=&H00FFFF,SecondaryColour=&H000000,Bold=1,MarginV=20'"
-        # subtitle_cmd = f"subtitles={single_video_srt}:force_style='Fontsize=14,Fontname=wqy-zenhei,Outline=2,PrimaryColour=&H00FFFF,SecondaryColour=&H000000,Bold=1,MarginV=20'"
+        # background_cmd = f"drawbox=y=ih-{70 + box_height}-{int(box_height / 20)}:color=yellow@1.0:width=iw:height={box_height}:t=fill"
+        if zm:
+            with open(single_video_srt, 'w') as f:
+                f.write(f"1\n{start_time} --> {end_time}\n\u2764\uFE0F{zm}\n\n")
+            subtitle_cmd = f"subtitles={single_video_srt}:force_style='Fontsize=14,Fontname=wqy-zenhei,Outline=2,PrimaryColour=&H00FFFF,SecondaryColour=&H000000,Bold=1,MarginV=20'"
+        else:
+            subtitle_cmd = f"force_style='Fontsize=14,Fontname=wqy-zenhei,Outline=2,PrimaryColour=&H00FFFF,SecondaryColour=&H000000,Bold=1,MarginV=20'"
         draw = f"{subtitle_cmd}"
         # 多线程数
         num_threads = 5

+ 2 - 2
video_rewriting/video_processor.py

@@ -83,7 +83,7 @@ class VideoProcessor:
         crop_total = task["crop_total"]
         gg_duration_total = task["gg_duration_total"]
         video_path_url = cls.create_folders(mark, str(task_mark))
-        # zm = Material.get_pzsrt_data("summary", "500Oe0", video_share)
+        zm = Material.get_pzsrt_data("summary", "500Oe0", video_share)
         # if not zm:
         #     Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务下片中标示填写错误,请关注!!!!', name)
         #     return
@@ -126,7 +126,7 @@ class VideoProcessor:
                         else:
                             if video_share and video_share != 'None':
                                 # new_video_path = FFmpeg.single_video(new_video_path, video_path_url, zm)
-                                new_video_path = FFmpeg.single_video(new_video_path, video_path_url)
+                                new_video_path = FFmpeg.single_video(new_video_path, video_path_url, zm)
 
                         if not os.path.isfile(new_video_path):
                             Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务用户{url}下的视频{v_id},视频改造失败,请关注', name)