Skip to content

Instantly share code, notes, and snippets.

@sayakpaul
Created December 28, 2019 11: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 sayakpaul/1c22a7037ca33fb3af82fd04aa82ea0e to your computer and use it in GitHub Desktop.
Save sayakpaul/1c22a7037ca33fb3af82fd04aa82ea0e to your computer and use it in GitHub Desktop.
single_digits = [i for i in range(10)]
def extract_frames(df, output_dir):
if not os.path.exists(output_dir):
os.mkdir(output_dir)
for i in tqdm(range(df.shape[0])):
count = 0
videoFile = df['video_name'][i]
videoPath = os.path.join("Videos", "UCF-101", videoFile)
# print(videoFile, videoPath)
cap = cv2.VideoCapture(videoPath) # capturing the video from the given path
while True:
(grabbed, frame) = cap.read()
if not grabbed:
break
if count == 60:
break
# This is to ensure the order of the frames
if count in single_digits:
frameName = videoFile.split("/")[1].split(" ")[0] + "_0%d.jpg" % count
else:
frameName = videoFile.split("/")[1].split(" ")[0] + "_%d.jpg" % count
framePath = os.path.join(output_dir, frameName)
cv2.imwrite(framePath, frame)
count+=1
cap.release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment