How to create multiple VideoCapture Obejcts
<p>I wanted to create multiple VideoCapture Objects for stitching video from multiple cameras to a single video mashup.</p>

<p>for example: I have path for three videos that I wanted to be read using Video Capture object shown below to get the frames from individual videos,so they can be used for writing.</p>

<p>Expected:For N number of video paths</p>

<pre><code>   cap0=cv2.VideoCapture(path1)
   cap1=cv2.VideoCapture(path2)
   cap2=cv2.VideoCapture(path3)
   .
   . 
   capn=cv2.VideoCapture(path4)
</code></pre>

<p>similarly I also wanted to create frame objects to read frames like</p>

<pre><code>ret,frame0=cap0.read()
ret,frame1=cap1.read()
.
.
ret,frameN=capn.read()
</code></pre>

<p>I tried using for loop on the lists where the paths are stored but every time only one path is read and frames are stored for that particular video only.I have seen in many forums it is possible to create multiple capture objects in C++ but not in python in dynamic scenario where number of videos are not known before hand.
This is my code until now</p>

<pre><code>frames=[]
for path in videoList:
    indices=[]
    cap = cv2.VideoCapture(path)

    while(cap.isOpened()):
        ret,frame=cap.read()
        if not ret:
           break
        indices.append(cap.get(1))
    frames.append(indices)
    cap.release()
    cv2.destroyAllWindows()
</code></pre>

<p>I'm not a python pgogrammer, but probably the solution is something like:</p>

<pre><code>frames=[]
caps=[]
for path in videoList:
    indices=[]
    caps.append (cv2.VideoCapture(path) )

for cap in caps:
    frames=[]
    if(cap.isOpened()):
        ret,frame=cap.read()
        frames.append(frame)
    else
        // no frame for this device could be captured. What to do?

// now "frames" holds your captured images.
</code></pre>

python opencv video video-capture video-processing