[更新:] 是的,这是可能的,现在大约 20 个月后。请参阅下面的 Update3![/更新]
这真的不可能吗?我所能找到的只是调用 FFmpeg(或其他软件)的变体。我当前的解决方案如下所示,但为了可移植性,我真正想要的是一个纯 Python 的解决方案,它不需要用户安装额外的软件。
毕竟,我可以使用 PyQt 的 Phonon 轻松播放视频,但我不能简单地获取视频的尺寸或持续时间之类的信息?
我的解决方案使用 ffmpy ( http://ffmpy.readthedocs.io/en/latest/ffmpy.html ),它是 FFmpeg 和 FFprobe ( http://trac.ffmpeg.org/wiki/FFprobeTips )的包装器。比其他产品更流畅,但它仍然需要额外的 FFmpeg 安装。
import ffmpy, subprocess, json
ffprobe = ffmpy.FFprobe(global_options="-loglevel quiet -sexagesimal -of json -show_entries stream=width,height,duration -show_entries format=duration -select_streams v:0", inputs={"myvideo.mp4": None})
print("ffprobe.cmd:", ffprobe.cmd) # printout the resulting ffprobe shell command
stdout, stderr = ffprobe.run(stderr=subprocess.PIPE, stdout=subprocess.PIPE)
# std* is byte sequence, but json in Python 3.5.2 requires str
ff0string = str(stdout,'utf-8')
ffinfo = json.loads(ff0string)
print(json.dumps(ffinfo, indent=4)) …Run Code Online (Sandbox Code Playgroud)