|
@@ -6,7 +6,7 @@ import subprocess
|
|
import sys
|
|
import sys
|
|
import time
|
|
import time
|
|
import urllib.parse
|
|
import urllib.parse
|
|
-import re
|
|
|
|
|
|
+import cv2
|
|
|
|
|
|
import requests
|
|
import requests
|
|
from datetime import datetime
|
|
from datetime import datetime
|
|
@@ -151,29 +151,25 @@ class AgcVidoe():
|
|
@classmethod
|
|
@classmethod
|
|
def get_audio_duration(cls, video_url):
|
|
def get_audio_duration(cls, video_url):
|
|
try:
|
|
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
|
|
|
|
|
|
+ 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:
|
|
except Exception as e:
|
|
print("Error:", e)
|
|
print("Error:", e)
|
|
return None
|
|
return None
|
|
|
|
|
|
|
|
|
|
- # # 获取视频文件的时长(秒)
|
|
|
|
- # @classmethod
|
|
|
|
- # def get_video_duration(cls, video_file):
|
|
|
|
- # result = subprocess.run(
|
|
|
|
- # ["ffprobe", "-v", "error", "-show_entries", "format=duration",
|
|
|
|
- # "-of", "default=noprint_wrappers=1:nokey=1", video_file],
|
|
|
|
- # capture_output=True, text=True)
|
|
|
|
- # return float(result.stdout)
|
|
|
|
|
|
+ # 获取视频文件的时长(秒)
|
|
|
|
+ @classmethod
|
|
|
|
+ def get_video_duration(cls, video_file):
|
|
|
|
+ result = subprocess.run(
|
|
|
|
+ ["ffprobe", "-v", "error", "-show_entries", "format=duration",
|
|
|
|
+ "-of", "default=noprint_wrappers=1:nokey=1", video_file],
|
|
|
|
+ capture_output=True, text=True)
|
|
|
|
+ return float(result.stdout)
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def clear_mp4_files(cls, folder_path):
|
|
def clear_mp4_files(cls, folder_path):
|