42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
import cv2
|
|
import os
|
|
|
|
def extract_frames_from_video(video_path, output_folder, frame_interval=30):
|
|
os.makedirs(output_folder, exist_ok=True)
|
|
|
|
video_capture = cv2.VideoCapture(video_path)
|
|
|
|
if not video_capture.isOpened():
|
|
print(f"Error: Could not open video {video_path}")
|
|
return
|
|
|
|
frame_count = 0
|
|
saved_count = 0
|
|
|
|
while True:
|
|
success, frame = video_capture.read()
|
|
|
|
if not success:
|
|
print("Finished extracting frames.")
|
|
break
|
|
|
|
if frame_count % frame_interval == 0:
|
|
frame_file_path = os.path.join(output_folder, f"frame_{saved_count:04d}.png")
|
|
cv2.imwrite(frame_file_path, frame)
|
|
print(f"Saved {frame_file_path}")
|
|
saved_count += 1
|
|
|
|
frame_count += 1
|
|
|
|
video_capture.release()
|
|
|
|
def main():
|
|
video_path = "/Users/vlacosmi/Downloads/drone-detect/capture_6_dec/fhd50fps/nvcamtest_6833_s00_00001.mp4"
|
|
output_folder = "video-frames"
|
|
frame_interval = 1
|
|
|
|
extract_frames_from_video(video_path, output_folder, frame_interval)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|