-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy3.py
36 lines (27 loc) · 971 Bytes
/
py3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import subprocess
import os
def getLength(filename):
result = subprocess.Popen(["ffprobe", filename],stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
duration=""
for x in result.stdout.readlines():
if "Duration" in x:
duration =x[12:23]
break
return duration
def str2sec(strtime):
if(len(strtime)>0):
print(strtime)
list1=strtime.split(":")
print(list1)
h,m,s = strtime.split(":")
return (int(h)*3600+int(m)*60+int(round(float(s))))
else:
return 0
path = os.path.dirname(os.path.realpath(__file__))
files = os.listdir(path)
i = 1
for file in files:
i = i+1
strduration = str(getLength(file))
durationsec= str2sec(strduration)
print(file+" --- "+str(durationsec))