需要一个python3编写的使用mediainfo统计视频大小info信息并写入excel的脚本
以下是一个使用Python 3和mediainfo来统计视频大小信息并将其写入Excel的脚本。在运行脚本之前,请确保已经安装了mediainfo和openpyxl库。
import os
import openpyxl
import subprocess
# 获取视频文件列表
video_files = [f for f in os.listdir('.') if os.path.isfile(f) and f.endswith(('.mp4', '.mkv', '.avi'))]
# 创建Excel文件并设置表头
wb = openpyxl.Workbook()
ws = wb.active
ws.title = 'Video Info'
ws.cell(row=1, column=1, value='File Name')
ws.cell(row=1, column=2, value='File Size (bytes)')
ws.cell(row=1, column=3, value='Duration (seconds)')
# 遍历视频文件并获取信息
for i, video_file in enumerate(video_files):
print(f'Processing {video_file} ({i+1}/{len(video_files)})')
result = subprocess.run(['mediainfo', '--Output=General;%FileSize%,%Duration%', video_file], capture_output=True, text=True)
file_size, duration = result.stdout.strip().split(',')
ws.cell(row=i+2, column=1, value=video_file)
ws.cell(row=i+2, column=2, value=int(file_size))
ws.cell(row=i+2, column=3, value=float(duration) / 1000)
# 保存Excel文件
wb.save('video_info.xlsx')
print('Done.')
该脚本将在当前目录中查找所有MP4、MKV和AVI文件,并使用mediainfo获取文件大小和持续时间。然后,它将这些信息写入名为“video_info.xlsx”的Excel文件中。每个视频文件的名称、文件大小和持续时间将写入一行。请注意,持续时间以秒为单位,并从毫秒转换为浮点数。
原文地址: https://www.cveoy.top/t/topic/93d 著作权归作者所有。请勿转载和采集!