Per title, I'm trying to write code to loop through multiple videos in a folder to extract their frames, then write each video's frames to their own new folder, e.g. video1 to frames_video1, video2 to frames_video2.
This is my code:
subclip_video_path = main_path + "\\subclips"
frames_path = main_path + "\\frames"
#loop through videos in file
for subclips in subclip_video_path:
currentVid = cv2.VideoCapture(subclips)
success, image = currentVid.read()
count = 0
while success:
#create new frames folder for each video
newFrameFolder = ("frames_" + subclips)
os.makedirs(newFrameFolder)
I get this error:
[ERROR:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-k8sx3e60\opencv\modules\videoio\src\cap.cpp (142) cv::VideoCapture::open VIDEOIO(CV_IMAGES): raised OpenCV exception:
OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-k8sx3e60\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): P in function 'cv::icvExtractPattern'
What does this mean? How can I fix this?
for subclips in subclip_video_path:
You need to get the list of your videos:
This means get all the .mp4 extension video files and store it in
sub_clip_video_path
variable.My Result:
Since I'm sure the directory contains two
.mp4
extension files, now I can continue.VideoCapture
for each frame.After you declare
VideoCapture
read all the frames from the current video, then declareVideoCapture
for the next video.while success
this will create an infinite loop.If the first frame grabbed from the video, then the
success
variable returnsTrue
. When you say:You will create infinite amount of folder for the current frame.
Here my result:
I gathered all the videos using
glob
While the current video is being read:
If the current frame successfully grabbed, then declare folder name. If the folder does not exist, create it.
Then declare the image name and save it.