Ask Your Question

Revision history [back]

Here is an example using frames rather than time; hope this helps.

import numpy as np
import cv2

total_frames=0 # Counts frames executed
state = 1 #controls which video to play

# 3 video captures can be set up
cap1=cv2.VideoCapture("video1.mpeg") # First 10 frames
cap2=cv2.VideoCapture("video2.mpeg") # Runs till the end
cap3=cv2.VideoCapture("video3.mpeg") # Runs till the end

while(True):
   # Check which state it shuold be in and when to swap
   if state == 1:
      ret, frame = cap1.read()
      if total_frames > 10: # After so many frames swap to 2
         state = 2
   if state == 2:
      ret, frame = cap2.read()
      if ret == False: # End of video 2 swap to 3
         state = 3
   if state == 3:
      ret, frame = cap3.read()
      if ret == False: # End of video 3 break
         break

  # Increment counter
  total_frames = total_frames + 1    
  # Perform some conversion to time if you like
  #seconds = total_frames*(1/fps)      

   # Display the resulting frame
   cv2.imshow('frame',frame )
   if cv2.waitKey(1) & 0xFF == ord('q'):
       break