Created
February 4, 2019 18:40
-
-
Save enric1994/66a5288630094f6907257e2704a2cd2f to your computer and use it in GitHub Desktop.
Extract frames from video and write file names in a file. Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
output_folder = 'output' | |
output_file = 'frame.txt' | |
video_name = 'video.mp4' | |
import os | |
if not os.path.exists(output_folder): | |
os.makedirs(output_folder) | |
print("Extracting frames...") | |
vidcap = cv2.VideoCapture(video_name) | |
success,image = vidcap.read() | |
count = 0 | |
with open(output_file, 'a') as file: | |
while success: | |
cv2.imwrite("%s/%s-%d.jpeg" % (output_folder, video_name, count), image) | |
file.write("%s-%d.jpeg \n" % (video_name, count)) | |
success,image = vidcap.read() | |
print('Frame: %d' % count) | |
count += 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment