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

+ 15 - 13
video_agc/agc_video_method.py

@@ -6,7 +6,6 @@ import subprocess
 import sys
 import time
 import urllib.parse
-import cv2
 
 import requests
 from datetime import datetime
@@ -150,16 +149,15 @@ class AgcVidoe():
     # 获取视频时长
     @classmethod
     def get_audio_duration(cls, video_url):
-        try:
-            cap = cv2.VideoCapture(video_url)
-            frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
-            fps = int(cap.get(cv2.CAP_PROP_FPS))
-            duration = frame_count / fps
-            cap.release()
-            return float(duration)
-        except Exception as e:
-            print("Error:", e)
-            return None
+        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)
 
 
     #  获取视频文件的时长(秒)
@@ -188,7 +186,7 @@ class AgcVidoe():
     @classmethod
     def concat_videos_with_subtitles(cls, videos, audio_duration, platform, mark):
         # 计算视频文件列表总时长
-        total_video_duration = sum(cls.get_audio_duration(video_file[3]) for video_file in videos)
+        total_video_duration = sum(cls.get_video_duration(video_file[3]) for video_file in videos)
         if platform == "koubo":
             # 视频时长大于音频时长
             if total_video_duration > audio_duration:
@@ -239,7 +237,11 @@ class AgcVidoe():
         s_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/srt/"
         # oss 目录
         v_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/oss/"
+        # oss
+        o_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/new/"
 
+        if not os.path.exists(o_path_url):
+            os.makedirs(o_path_url)
         if not os.path.exists(video_path_url):
             os.makedirs(video_path_url)
         if not os.path.exists(s_path_url):
@@ -250,7 +252,7 @@ class AgcVidoe():
         s_path = s_path_url + mark + ".srt"
         # 最终生成视频地址
         v_path = v_path_url + mark + ".mp4"
-        v_oss_path = v_path_url + mark + "oss.mp4"
+        v_oss_path = o_path_url + mark + ".mp4"
         if os.path.isfile(v_oss_path):
             os.remove(v_oss_path)
         if os.path.isfile(v_path):