123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- import csv
- import requests
- import subprocess
- import json
- import os
- 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
- 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
- def process_csv(file_path):
- """
- 处理CSV文件
- """
- bitrate_counter = 0
- size_counter = 0
- count = 0
- with open(file_path, 'r') as csvfile:
- reader = csv.DictReader(csvfile)
- for row in reader:
- count += 1
- if count % 10000 == 0:
- print(f"count = :{count}")
- url1 = row['path_264']
- url2 = row['path_265']
- url1 = "http://visionularcdn.yishihui.com/" + url1
- url2 = "http://vcdn.yishihui.com/" + url2
- # 获取视频码率
- 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 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"URL1码率大于URL2的次数: {bitrate_count}")
- print(f"URL1文件大小大于URL2的次数: {size_count}")
|