I am trying to extract frames from video, i am using this code:
import cv2
vidcap = cv2.VideoCapture('video_01.mp4')
success,image = vidcap.read()
count = 0
success = True
while success:
success,image = vidcap.read()
print('Read a new frame: ', success)
cv2.imwrite("frame%d.jpg" % count, image) # save frame as JPEG file
count += 1
This returns
Read a new frame: False
Ihave followed various posts about this in SO. I installed ffmepg, av but nothing works.
I am running it on windows, installed opencv via Anaconda.
What is workaround for this? Thanks for help
I also tried
import cv2
import numpy as np
import os
# Playing video from file:
cap = cv2.VideoCapture('example.mp4')
try:
if not os.path.exists('data'):
os.makedirs('data')
except OSError:
print ('Error: Creating directory of data')
currentFrame = 0
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Saves image of the current frame in jpg file
name = './data/frame' + str(currentFrame) + '.jpg'
print ('Creating...' + name)
cv2.imwrite(name, frame)
# To stop duplicate images
currentFrame += 1
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
However this saves empty images