12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 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 % 1000 == 0:
- print(f"count = :{count} bitrate_counter = {bitrate_counter} size_counter = {size_counter}")
- 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 = '/Users/heyu/Downloads/h265.csv' # 替换为你的CSV文件路径
- # 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}")
|