Skip to content

Instantly share code, notes, and snippets.

@enric1994
Created February 4, 2019 18:40
Show Gist options
  • Save enric1994/66a5288630094f6907257e2704a2cd2f to your computer and use it in GitHub Desktop.
Save enric1994/66a5288630094f6907257e2704a2cd2f to your computer and use it in GitHub Desktop.
Extract frames from video and write file names in a file. Python
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