dur
· 1.0 KiB · Text
Raw
#!/usr/bin/env python3
from sys import stderr, argv, exit
import subprocess
from math import floor
def hms(inp):
s,ms = divmod(inp,1)
m,s = divmod(s,60)
h,m = divmod(m,60)
return f"{h:02.0f}:{m:02.0f}:{s:02.0f}.{floor(ms*100):02.0f}"
def get_video_duration(fileloc) :
command = ['ffprobe',
'-v', 'fatal',
'-show_entries', 'stream=duration',
'-of', 'default=noprint_wrappers=1:nokey=1',
fileloc, '-sexagesimal']
ffmpeg = subprocess.Popen(command, stderr=subprocess.PIPE ,stdout = subprocess.PIPE )
out, err = ffmpeg.communicate()
if(err) : print(err)
out = out.decode('utf-8').strip()
return map(float,out.split(":"))
def main():
tot = 0.0
for fn in argv[1:]:
h,m,s = get_video_duration(fn)
tot += h*60*60 + m*60 + s
print(f"{hms(tot)}", end="\r", file=stderr)
print(hms(tot))
return 0
if __name__ == "__main__":
try:
exit(main())
except KeyboardInterrupt:
exit(127)
| 1 | #!/usr/bin/env python3 |
| 2 | from sys import stderr, argv, exit |
| 3 | import subprocess |
| 4 | from math import floor |
| 5 | |
| 6 | def hms(inp): |
| 7 | s,ms = divmod(inp,1) |
| 8 | m,s = divmod(s,60) |
| 9 | h,m = divmod(m,60) |
| 10 | return f"{h:02.0f}:{m:02.0f}:{s:02.0f}.{floor(ms*100):02.0f}" |
| 11 | |
| 12 | def get_video_duration(fileloc) : |
| 13 | command = ['ffprobe', |
| 14 | '-v', 'fatal', |
| 15 | '-show_entries', 'stream=duration', |
| 16 | '-of', 'default=noprint_wrappers=1:nokey=1', |
| 17 | fileloc, '-sexagesimal'] |
| 18 | ffmpeg = subprocess.Popen(command, stderr=subprocess.PIPE ,stdout = subprocess.PIPE ) |
| 19 | out, err = ffmpeg.communicate() |
| 20 | if(err) : print(err) |
| 21 | out = out.decode('utf-8').strip() |
| 22 | return map(float,out.split(":")) |
| 23 | |
| 24 | def main(): |
| 25 | tot = 0.0 |
| 26 | for fn in argv[1:]: |
| 27 | h,m,s = get_video_duration(fn) |
| 28 | tot += h*60*60 + m*60 + s |
| 29 | print(f"{hms(tot)}", end="\r", file=stderr) |
| 30 | print(hms(tot)) |
| 31 | return 0 |
| 32 | |
| 33 | if __name__ == "__main__": |
| 34 | try: |
| 35 | exit(main()) |
| 36 | except KeyboardInterrupt: |
| 37 | exit(127) |