zhangyong 11 months ago
parent
commit
8bb504c8a2
2 changed files with 13 additions and 11 deletions
  1. 11 8
      common/ffmpeg.py
  2. 2 3
      video_rewriting/video_prep.py

+ 11 - 8
common/ffmpeg.py

@@ -2,7 +2,6 @@
 import subprocess
 import time
 
-from common import Common
 
 
 class FFmpeg():
@@ -76,12 +75,17 @@ class FFmpeg():
     """
     @classmethod
     def get_w_h_size(cls, new_video_path):
-        # 获取视频的原始宽高信息
-        ffprobe_cmd = f"ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 {new_video_path}"
-        ffprobe_process = subprocess.Popen(ffprobe_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
-        output, _ = ffprobe_process.communicate()
-        height, width = map(int, output.decode().strip().split(','))
-        return width, height
+        try:
+            # 获取视频的原始宽高信息
+            ffprobe_cmd = f"ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 {new_video_path}"
+            ffprobe_process = subprocess.Popen(ffprobe_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
+            output, _ = ffprobe_process.communicate()
+            output_decoded = output.decode().strip()
+            split_output = [value for value in output_decoded.split(',') if value.strip()]
+            height, width = map(int, split_output)
+            return width, height
+        except ValueError as e:
+            return 1920, 1080
 
     """
     视频裁剪
@@ -228,7 +232,6 @@ class FFmpeg():
         concatenate_videos_url = video_path_url + 'concatenate_videos.mp4'
         # 获取视频的原始宽高信息
         width, height = cls.get_w_h_size(video_list[0])
-        Common.logger("log").info(f"视频宽高{width,height}")
         # 拼接视频
         VIDEO_COUNTER = 0
         FF_INPUT = ""

+ 2 - 3
video_rewriting/video_prep.py

@@ -167,9 +167,8 @@ class getVideo:
                                 Common.logger("log").info(f"{task_mark}下的视频{url},获取mp3成功")
                                 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}下的视频{url},生成片尾视频失败")
+                                    Common.logger("log").info(f"{task_mark}下的视频{url},生成片尾视频成功")
                                     break
-                                Common.logger("log").info(f"{task_mark}下的视频{url},生成片尾视频成功")
                                 time.sleep(1)
                             if not os.path.isfile(pw_path):
                                 Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务用户{url}下的视频{v_id},生成片尾视频失败,请关注',
@@ -177,7 +176,7 @@ class getVideo:
                                 cls.remove_files(video_path_url)
                                 continue
                             pw_video_list = [new_video_path, pw_path]
-                            Common.logger("log").info(f"{task_mark}下的视频{url},视频与片尾开始拼接{pw_video_list}")
+                            Common.logger("log").info(f"{task_mark}下的视频{url},视频与片尾开始拼接")
                             video_path = FFmpeg.concatenate_videos(pw_video_list, video_path_url)  # 视频与片尾拼接到一起
                             Common.logger("log").info(f"{task_mark}下的视频{url},视频与片尾拼接成功")
                             time.sleep(1)