Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ def extract_frames(video_path: str, output_folder: str, interval: int):
None
"""
# Your code starts here...

# load video
video = cv2.VideoCapture(video_path)

# get fps and total # of frames
fps = video.get(cv2.CAP_PROP_FPS)
total_frames = video.get(cv2.CAP_PROP_FRAME_COUNT)

# create folder to save the frames if not exist
os.makedirs(output_folder, exist_ok=True)

count, success = 0, True
while success:
success, image = video.read() # read a frame
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add some error handling here. If it is not successful, the image could be corrupt and you would be saving bad data. Something to keep in mind

if (count % (fps * interval) == 0): # save the frame once every interval seconds
cv2.imwrite(f"{output_folder}/frame{count}.jpg", image)
count += 1

video.release()

pass


Expand All @@ -30,6 +50,18 @@ def extract_audio(video_path: str, output_path: str):
None
"""
# Your code starts here...

# create directory to save the audio if not exist
os.makedirs(os.path.dirname(output_path), exist_ok=True)


(
ffmpeg
.input(video_path)
.output(output_path, format='wav')
.run()
)

pass


Expand Down