zhangyong 1 年之前
父節點
當前提交
fdc179100f
共有 1 個文件被更改,包括 18 次插入9 次删除
  1. 18 9
      video_agc/agc_video_method.py

+ 18 - 9
video_agc/agc_video_method.py

@@ -6,6 +6,7 @@ import subprocess
 import sys
 import time
 import urllib.parse
+import re
 
 import requests
 from datetime import datetime
@@ -149,15 +150,20 @@ class AgcVidoe():
     # 获取视频时长
     @classmethod
     def get_audio_duration(cls, video_url):
-        ffprobe_cmd = [
-            "ffprobe",
-            "-i", video_url,
-            "-show_entries", "format=duration",
-            "-v", "quiet",
-            "-of", "csv=p=0"
-        ]
-        output = subprocess.check_output(ffprobe_cmd).decode("utf-8").strip()
-        return float(output)
+        try:
+            result = subprocess.run(['ffmpeg', '-i', video_url], stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+                                    universal_newlines=True)
+            output = result.stderr
+            match = re.search(r"Duration: (\d{2}):(\d{2}):(\d{2})\.\d+", output)
+            if match:
+                hours, minutes, seconds = map(int, match.groups())
+                total_seconds = hours * 3600 + minutes * 60 + seconds
+                return float(total_seconds)
+            else:
+                return None
+        except Exception as e:
+            print("Error:", e)
+            return None
 
 
     #  获取视频文件的时长(秒)
@@ -404,6 +410,9 @@ class AgcVidoe():
                 Common.logger("video").info(f"{mark}的{platform}渠道获取需要拼接的音频成功")
                 # 获取音频秒数
                 audio_duration = cls.get_audio_duration(audio_video)
+                if audio_duration == None:
+                    Common.logger("video").info(f"{mark}的{platform}渠道音频{audio_video}秒数为0")
+                    return ""
                 Common.logger("video").info(f"{mark}的{platform}渠道获取需要拼接的音频秒数为:{audio_duration}")
                 video_files = cls.concatenate_videos(videos, audio_duration, audio_video, platform, s_path, v_path, mark, v_oss_path)
                 if video_files == "":