Python 获得视频的播放时长

没什么好说的,直接上原代码!

1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/env python
# coding=utf-8
import os
import sys
def getLength(input_video):
cmd = 'ffprobe -i %s -show_entries format=duration -v quiet -of csv="p=0"' % input_video
output =os.popen(cmd,'r')
output = output.read()
output = float(output)/60
return output
print getLength(sys.argv[1])