title: How to save frames with cv2.imwrite from multiple videos in different folders?
body: <p>Okay so I searched a lot on the internet and I came across various methods to extract frames out of videos, but none of them seemed to work for multiple videos. So I came up with my own solution to it. But the status as of now is that I am able to extract frames out of one video and save it in a folder by its name. But the code is not working for the second video. Following is the error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "c:\Users\hp\Videos\multi.py", line 21, in &lt;module&gt;
      cv2.imwrite(os.path.join(location , "frame%d.jpg"  % counter), frame)
  cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp:715: error: (-215:Assertion failed) !_img.empty() in function 'cv::imwrite'
  </code></pre>
  
  <p>Here is my full code</p>
  
  <pre><code>import os 
  import cv2 
  
  def createFolder(directory):
      try:
          if not os.path.exists(directory):
              os.makedirs(directory)
      except OSError:
          print ('Error: Creating directory. ' +  directory)
  
  listing = os.listdir('C:/Users/hp/Videos/TwoVideos')
  counter = 0
  for vid in listing:
      createFolder('./data/'+vid)
      vedeo = "C:/Users/hp/Videos/TwoVideos/"+vid
      ret = 1
      cap = cv2.VideoCapture(vedeo)
      while ret: 
          ret, frame = cap.read()
          location = './data/'+vid
          cv2.imwrite(os.path.join(location , "frame%d.jpg"  % counter), frame)
          # cv2.imwrite("frame%d.jpg" % counter, frame) 
          counter = counter + 1 
  </code></pre>