擅长:python、mysql、java
<p>无需遍历<code>FFprobe</code>的输出。有<a href="https://trac.ffmpeg.org/wiki/FFprobeTips#Formatcontainerduration" rel="nofollow noreferrer">one simple command</a>只返回输入文件的持续时间:</p>
<pre><code>ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 <input_video>
</code></pre>
<p>您可以使用以下方法来获取持续时间:</p>
<pre><code>def get_length(input_video):
result = subprocess.run(['ffprobe', '-v', 'error', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', input_video], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return float(result.stdout)
</code></pre>