Skip to content

Instantly share code, notes, and snippets.

@farzadhallaji
Created July 17, 2023 19:23
Show Gist options
  • Save farzadhallaji/bbea1c35d969170f9c0fbfbf499d9742 to your computer and use it in GitHub Desktop.
Save farzadhallaji/bbea1c35d969170f9c0fbfbf499d9742 to your computer and use it in GitHub Desktop.
Total duration of all videos
import os
from moviepy.editor import VideoFileClip
folder_path = '/home/ri/Desktop/TFL/ahmadian' # Replace with the path to your folder
total_duration = 0
for file in os.listdir(folder_path):
if file.endswith('.webm'): # Adjust the file extension if necessary
file_path = os.path.join(folder_path, file)
video = VideoFileClip(file_path)
duration = video.duration
total_duration += duration
video.close()
print("Total duration of all videos:", total_duration)
total_duration_minutes = total_duration / 60
print("Total duration of all videos (in minutes):", total_duration_minutes)
total_duration_hours = total_duration / 3600
print("Total duration of all videos (in hours):", total_duration_hours)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment