Python 2.7 mediainfo --inform 输出完整信息而不是一个字符串
Posted
技术标签:
【中文标题】Python 2.7 mediainfo --inform 输出完整信息而不是一个字符串【英文标题】:Python 2.7 mediainfo --inform outputs full info rather than one string 【发布时间】:2016-02-08 21:40:45 【问题描述】:在 powershell 中使用以下内容会产生 01:22:02:03
的预期输出:
MediaInfo --Language=raw --Full --Inform="Video;%Duration/String4%" filename
我的以下 python 2.7 脚本始终提供包含每条元数据的完整 mediainfo 输出,而不仅仅是我指定的持续时间字符串。我尝试转义分号,但没有效果。我做错了什么?
import sys
import subprocess
filename = sys.argv[1]
test = subprocess.check_output(['MediaInfo', '--Language=raw', '--Full', '--inform="Video;%Duration/String4%"', filename])
print test
【问题讨论】:
【参考方案1】:去掉--Inform
参数中的双引号。我可以用这段代码重现你的问题:
import subprocess
args = [
'mediainfo',
'--Language=raw',
'--Full',
'--inform="Video;%Duration/String4%"',
'tests/reference.mp4'
]
bad_output = subprocess.check_output(args)
line_count_bad = len(bad_output.splitlines())
args[3] = args[3].replace('"', '')
good_output = subprocess.check_output(args)
line_count_good = len(good_output.splitlines())
print(line_count_bad, line_count_good, sep='\t')
print(good_output)
输出是:
204 1
b'00:00:07:08\n'
【讨论】:
以上是关于Python 2.7 mediainfo --inform 输出完整信息而不是一个字符串的主要内容,如果未能解决你的问题,请参考以下文章
[python]安装wxpython的时候报错 “no installation of python 2.7 found in registy”
python version 2.7 required,which was not found in the registry
python version 2.7 required,which was not found in the registry
python version 2.7 required,which was not found in the registry
python version 2.7 required,which was not found in the registry
python version 2.7 required,which was not found in the registry