我试图通过从python脚本运行以下行来获取媒体文件的持续时间:
test_file = 'path_to_file.mp4'
ffmpeg_get_mediafile_length = ["ffmpeg", "-i", test_file, '2>&1 | grep "Duration"']
output = subprocess.Popen(ffmpeg_get_mediafile_length,
stdout = subprocess.PIPE
).stdout.read()
print output # this gives None
matches = re_length.search(output)
print matches
下面是我得到的ffmpeg
日志和我得到的错误:
您可以尝试ffprobe,它可以输出JSON,并且不需要grep和regexp结果-但是返回的持续时间以秒为单位:
退货:
^{pr2}$2>&1 | grep Duration
是shell重定向。你只能用一个外壳。在那么,最短的就是生成一个shell脚本并设置
shell=True
:或者,不需要更改其他代码行:
^{pr2}$相关问题 更多 >
编程相关推荐