擅长:python、mysql、java
<p>您可以尝试ffprobe,它可以输出JSON,并且不需要grep和regexp结果-但是返回的持续时间以秒为单位:</p>
<pre><code>import shlex
import subprocess
import json
filePath = '/home/f3k/Downloads/tr5.mp4'
command = shlex.split('/usr/bin/ffprobe -v quiet -print_format json -show_format -show_streams')
command.append(filePath)
proc = subprocess.Popen(command, stdout = subprocess.PIPE)
stdout, _ = proc.communicate()
output = json.loads(stdout)
print (output['format']['duration'])
</code></pre>
<p>退货:</p>
^{pr2}$