以下是一个Python3编写的,可以统计视频大小、时长、比特率、fps、宽度、高度等信息并写入excel的脚本:

import os
import subprocess
import openpyxl

# 获取视频信息
def get_video_info(video_path):
    cmd = 'ffprobe -v error -select_streams v:0 -show_entries stream=width,height,duration,bit_rate,r_frame_rate -of csv=p=0 ' + '"' + video_path + '"'
    output = subprocess.check_output(cmd, shell=True)
    info = output.decode().strip().split(',')
    width = info[0]
    height = info[1]
    duration = info[2]
    bitrate = info[3]
    fps = eval(info[4])
    return width, height, duration, bitrate, fps

# 获取文件大小
def get_file_size(video_path):
    size = os.path.getsize(video_path)
    return size

# 写入excel
def write_to_excel(video_path, width, height, duration, bitrate, fps, size, excel_path):
    wb = openpyxl.load_workbook(excel_path)
    ws = wb.active
    ws.append([video_path, width, height, duration, bitrate, fps, size])
    wb.save(excel_path)

if __name__ == '__main__':
    video_path = 'test.mp4'
    excel_path = 'video_info.xlsx'

    width, height, duration, bitrate, fps = get_video_info(video_path)
    size = get_file_size(video_path)

    write_to_excel(video_path, width, height, duration, bitrate, fps, size, excel_path)

你需要修改video_pathexcel_path变量来指定视频文件路径和Excel文件路径。执行脚本后,它将统计视频的相关信息,并将其写入Excel文件。

我需要一个python3编写的统计视频大小、时长、比特率、fps、宽度、高度等信息并写入excel的脚本

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

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