title: Video Stitching of overlapped videos
body: <p>Hello I have multiple videos which overlap at some time and want to stitch these videos to get a single video stream. </p>
  
  <p>for example below are three videos where video 1 and video 2 overlap at some time<a href="https://i.stack.imgur.com/M64I0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M64I0.png" alt="enter image description here"></a></p>
  
  <p>Now I wanted the final o/p to be</p>
  
  <p><a href="https://i.stack.imgur.com/FySbv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FySbv.png" alt="enter image description here"></a></p>
  
  <p>Where initially video 1 frames are read and written to the video writer object until there is an overlap. Once there is an overlap the view switches from video 1 or video 2 based on some decisions(which is not my question). Once the overlap ends the frames from video 2 are read and written as the video 1 frames are completed. And finally when they are no frames left from video 2, frames from video 3 are read and written.</p>
  
  <p>My question is how to read and write the overlapped videos as i wanted to have the frames from video or video 2 for the overlapped period. The problem I am facing is how to identify the overlap while reading and writing the frames without checking the video content.</p>
  
  <p>I am finding the overlapped time by analyzing the time stamps and also getting the video indices for which there is an overlap. So, how can I use this information to read and write frames for overlapped videos. Below is the on how I am getting the information which will be used for writing</p>
  
  <pre><code> def dict_cam(key,values):
      return {key[i]:values[i] for i in range (len(key))}
  
   users=dict_cam(indices,intervals) # Creates dictionary with videos indices as keys(indices) with their start and end time as their values(intervals).
  
   overlapping = [ [i,j,x,y] for i,x in users.iteritems() for j,y in users.iteritems() if x is not y and x[1]&gt;y[0] and x[0]&lt;y[0] ] # For identifying overlapping.
  
  
   for x in overlapping
  
     camera=[x[0]]
     camera.append(x[1])
     begin=x[2][0]
     end=x[2][1]
     begg=x[3][0]
     ens=x[3][1]
     if begin &lt; begg and begg&lt;end:
         overlap.append(begg)
     if ens &lt; end:
         overend.append(ens)
    else:
        overend.append(end)
  
  
  over_rang=overlap + overend
  </code></pre>
  
  <p>Where, camera is a list of video indices where there is an overlap, and over_rang is a list which contains the duration of the overlap.</p>
  
  <p>Before starting video writing I am sorting all the video indices with their start time.</p>
  
  <p>I do not want to analyze the video content rather use the information about the overlapped time and the indices where there is a overlap</p>