以下是一个使用Python 3编写的脚本,可以使用mediainfo统计视频info并将其写入Excel文件中:

import os
import subprocess
import openpyxl

# 安装openpyxl模块
# pip install openpyxl

# 安装mediainfo命令行工具
# sudo apt-get install mediainfo

# 需要处理的视频文件夹
video_folder = "/path/to/video/folder"

# 输出Excel文件名
excel_file = "video_info.xlsx"

# 创建Excel文件
wb = openpyxl.Workbook()
ws = wb.active
ws.title = "Video Info"

# 设置表头
headers = ["文件名", "格式", "分辨率", "码率", "帧率", "时长"]
for col, header in enumerate(headers, start=1):
    ws.cell(row=1, column=col, value=header)

# 获取视频文件列表
video_files = [os.path.join(video_folder, f) for f in os.listdir(video_folder) if f.endswith(".mp4")]

# 遍历所有视频文件,获取视频信息并写入Excel文件
for row, video_file in enumerate(video_files, start=2):
    # 获取文件名
    file_name = os.path.basename(video_file)

    # 使用mediainfo获取视频信息
    result = subprocess.run(["mediainfo", "--Inform=Video;%Format%|%Width%x%Height%|%BitRate/String%|%FrameRate%|%Duration/String3%", video_file], stdout=subprocess.PIPE)
    output = result.stdout.decode().strip()

    # 解析输出结果
    format, resolution, bitrate, framerate, duration = output.split("|")

    # 写入Excel文件
    ws.cell(row=row, column=1, value=file_name)
    ws.cell(row=row, column=2, value=format)
    ws.cell(row=row, column=3, value=resolution)
    ws.cell(row=row, column=4, value=bitrate)
    ws.cell(row=row, column=5, value=framerate)
    ws.cell(row=row, column=6, value=duration)

# 保存Excel文件
wb.save(excel_file)
print(f"视频信息已保存到 {excel_file}")

使用方法:

  1. 将上述代码保存为一个名为video_info.py的文件
  2. video_folder变量设置为需要处理的视频文件夹的路径
  3. excel_file变量设置为输出Excel文件的路径和文件名
  4. 在终端中运行python3 video_info.py命令
  5. 等待脚本执行完成后,可以在指定的Excel文件中查看视频信息
需要一个python3编写的使用mediainfo统计视频info并写入excel的脚本

原文地址: https://www.cveoy.top/t/topic/91W 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录