Skip to content

Instantly share code, notes, and snippets.

@apalevich
Last active February 9, 2021 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apalevich/aa9ae89e7d34e44d87a3ed13141d6fce to your computer and use it in GitHub Desktop.
Save apalevich/aa9ae89e7d34e44d87a3ed13141d6fce to your computer and use it in GitHub Desktop.
Screenshots from videofile
Для Mac OS X
0) Делаешь папку на рабочем столе (например, WP)
1) Открываешь Terminal
2) Вводишь команду while :;do screencapture ~/Desktop/WP/$(date +%y%m%d%H%M%S).png;sleep 20;done
3) В sleep 20 можешь заменить интервал на любой другой (в секундах)
4) Нажимаешь (Enter), запускаешь видео на полный экран. Программа просто делает скриншоты, как ты понял
5) Когда видео кончится, в терминале надо нажать Ctrl+C (не Cmd!)
import cv2
import time
import os
def video_to_frames(input_loc, output_loc):
"""Function to extract frames from input video file
and save them as separate frames in an output directory.
Args:
input_loc: Input video file.
output_loc: Output directory to save the frames.
Returns:
None
"""
try:
os.mkdir(output_loc)
except OSError:
pass
# Log the time
time_start = time.time()
# Start capturing the feed
cap = cv2.VideoCapture(input_loc)
# Find the number of frames
video_length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) - 1
print ("Number of frames: ", video_length)
count = 1
print ("Converting video..\n")
# Start converting the video
while cap.isOpened():
# Extract the frame
ret, frame = cap.read()
# Write the results back to output location.
cv2.imwrite(output_loc + "/%#05d.jpg" % (count+1), frame)
count = count + 1
# If there are no more frames left
if (count > (video_length-1)):
# Log the time again
time_end = time.time()
# Release the feed
cap.release()
# Print stats
print ("Done extracting frames.\n%d frames extracted" % count)
print ("It took %d seconds forconversion." % (time_end-time_start))
break
if __name__=="__main__":
input_loc = 'video2.webm'
output_loc = 'wp'
video_to_frames(input_loc, output_loc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment