4b. Explanation of Code Segments
- Scanning the Directory:
for file in os.listdir('.'): if any(file.endswith(ext) for ext in video_extensions): try: video = mp.VideoFileClip(file) duration = video.duration video_durations.append(duration) video.close() except Exception as e: print(f"Error processing {file}: {e}")
- Checks if a file is a video, loads it, gets its duration, and closes it to free resources.
- The
try-except
block helps handle errors for files that can’t be processed.