Skip to content

Commit 61b8530

Browse files
committed
extracting frames from video - fix a bug where some frames were not saved because of filename containing colons
1 parent 91329c9 commit 61b8530

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

python-for-multimedia/extract-frames-from-video/extract_frames_moviepy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def format_timedelta(td):
1313
try:
1414
result, ms = result.split(".")
1515
except ValueError:
16-
return result + ".00".replace(":", "-")
16+
return (result + ".00").replace(":", "-")
1717
ms = int(ms)
1818
ms = round(ms / 1e4)
1919
return f"{result}.{ms:02}".replace(":", "-")
@@ -35,7 +35,7 @@ def main(video_file):
3535
# iterate over each possible frame
3636
for current_duration in np.arange(0, video_clip.duration, step):
3737
# format the file name and save it
38-
frame_duration_formatted = format_timedelta(timedelta(seconds=current_duration)).replace(":", "-")
38+
frame_duration_formatted = format_timedelta(timedelta(seconds=current_duration))
3939
frame_filename = os.path.join(filename, f"frame{frame_duration_formatted}.jpg")
4040
# save the frame with the current duration
4141
video_clip.save_frame(frame_filename, current_duration)

python-for-multimedia/extract-frames-from-video/extract_frames_opencv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def format_timedelta(td):
1313
try:
1414
result, ms = result.split(".")
1515
except ValueError:
16-
return result + ".00".replace(":", "-")
16+
return (result + ".00").replace(":", "-")
1717
ms = int(ms)
1818
ms = round(ms / 1e4)
1919
return f"{result}.{ms:02}".replace(":", "-")

0 commit comments

Comments
 (0)