擅长:python、mysql、java
<p>您可以为此使用外部命令<a href="https://ffmpeg.org/ffprobe.html" rel="nofollow noreferrer">^{<cd1>}</a>。具体来说,从FFmpeg Wiki运行<a href="https://trac.ffmpeg.org/wiki/FFprobeTips#Formatcontainerduration" rel="nofollow noreferrer">this bash command</a>:</p>
<pre><code>import subprocess
def get_length(filename):
result = subprocess.run(["ffprobe", "-v", "error", "-show_entries",
"format=duration", "-of",
"default=noprint_wrappers=1:nokey=1", filename],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
return float(result.stdout)
</code></pre>