Last active
November 15, 2022 00:00
-
-
Save gotev/b89648006752813d93b4993ee453e37d to your computer and use it in GitHub Desktop.
List mp4 files in a folder and get duration for each file and total duration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import re | |
import pathlib | |
import ffmpeg | |
import time | |
files = pathlib.Path('.').glob('*.mp4') | |
files = sorted(files, key=lambda x: float(re.findall("(\d+)", os.path.basename(x))[0])) | |
totalDuration = 0 | |
for file in files: | |
info = ffmpeg.probe(file) | |
durationSeconds = round(float(info['format']['duration'])) | |
totalDuration += durationSeconds | |
duration = time.strftime('%H:%M:%S', time.gmtime(durationSeconds)) | |
print(str(file) + ' -> ' + duration) | |
print('Total Duration: ' + time.strftime('%H:%M:%S', time.gmtime(totalDuration))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment