python 获取 video metadata

利用 python 获取 video 的原信息
更新于: 2025-04-01 20:21:40

核心代码

import json
from pymediainfo import MediaInfo


def get_video_metadata(video_path):
    media_info = MediaInfo.parse(video_path)
    return media_info.to_data()


metadata = get_video_metadata("v1.mp4")

# save meta to json
with open("v1.json", "w") as f:
    json.dump(metadata, f, indent=2)