supeng 1 mesiac pred
rodič
commit
618b7578af
1 zmenil súbory, kde vykonal 75 pridanie a 26 odobranie
  1. 75 26
      bitrate.py

+ 75 - 26
bitrate.py

@@ -1,36 +1,85 @@
+import csv
+import requests
 import subprocess
 import json
+import os
 
 
-def get_video_info(video_path):
-    # 使用 ffprobe 获取视频信息
-    command = [
-        'ffprobe',
-        '-v', 'error',
-        '-select_streams', 'v:0',
-        '-show_entries', 'format=size,bit_rate',
-        '-of', 'json',
-        video_path
-    ]
-    result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
+def get_video_bitrate(url):
+    """
+    获取视频的码率(比特率)
+    """
+    try:
+        # 使用FFmpeg获取视频信息
+        command = [
+            'ffprobe',
+            '-v', 'quiet',
+            '-select_streams', 'v:0',
+            '-show_entries', 'stream=bit_rate',
+            '-of', 'json',
+            url
+        ]
+        result = subprocess.run(command, capture_output=True, text=True)
+        video_info = json.loads(result.stdout)
+        bitrate = int(video_info['streams'][0].get('bit_rate', 0))
+        return bitrate
+    except Exception as e:
+        print(f"获取视频码率失败: {url}, 错误: {e}")
+        return 0
 
-    if result.returncode != 0:
-        print(f"Error: {result.stderr}")
-        return None
 
-    # 解析 JSON 输出
-    video_info = json.loads(result.stdout)
-    return video_info['format']
+def get_file_size(url):
+    """
+    获取文件大小
+    """
+    try:
+        response = requests.head(url, allow_redirects=True)
+        if response.status_code == 200:
+            file_size = int(response.headers.get('Content-Length', 0))
+            return file_size
+        else:
+            print(f"获取文件大小失败: {url}, 状态码: {response.status_code}")
+            return 0
+    except Exception as e:
+        print(f"获取文件大小失败: {url}, 错误: {e}")
+        return 0
 
 
-if __name__ == "__main__":
-    # video_path = 'path/to/your/video.mp4'
-    video_path = 'http://rescdn.yishihui.com/longvideo/multitranscodeh265/crawler_local/video/prod/20250301/088c1f984789aa3ef65aa7e41018237f7446740420250301194002586558054-2SD.mp4'
-    info = get_video_info(video_path)
+def process_csv(file_path):
+    """
+    处理CSV文件
+    """
+    bitrate_counter = 0
+    size_counter = 0
+
+    with open(file_path, 'r') as csvfile:
+        reader = csv.DictReader(csvfile)
+        for row in reader:
+            url1 = row['path_264']
+            url2 = row['path_265']
+
+            # 获取视频码率
+            bitrate1 = get_video_bitrate(url1)
+            bitrate2 = get_video_bitrate(url2)
+
+            # 比较码率
+            if bitrate1 > bitrate2:
+                bitrate_counter += 1
+
+            # 获取文件大小
+            size1 = get_file_size(url1)
+            size2 = get_file_size(url2)
 
-    if info:
-        size = int(info['size'])
-        bit_rate = int(info['bit_rate'])
+            # 比较文件大小
+            if size1 > size2:
+                size_counter += 1
+
+    return bitrate_counter, size_counter
+
+
+if __name__ == "__main__":
+    csv_file_path = '/root/h265.csv'  # 替换为你的CSV文件路径
+    bitrate_count, size_count = process_csv(csv_file_path)
 
-        print(f"File Size: {size / (1024 * 1024):.2f} MB")
-        print(f"Bit Rate: {bit_rate / 1000:.2f} kbps")
+    print(f"URL1码率大于URL2的次数: {bitrate_count}")
+    print(f"URL1文件大小大于URL2的次数: {size_count}")