Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Combine several videos in the same window (Python)

Hello,

is it possible to combine several videos either vertical or horizontal into the same window or output file? The videos have the number of frames and format.

I tried using np.concentrate but this causes problems with the dimensions of the arrays.

Many thanks in advance

Combine several videos in the same window (Python)

Hello,

is it possible to combine several videos either vertical or horizontal into the same window or output file? The videos have the number of frames and format.

I tried using np.concentrate but this causes problems with the dimensions of the arrays.

Many thanks in advance

Edit: This is how it can be done - maybe there is a more elegant way but it works fine for me

import cv2 import numpy as np

cap = cv2.VideoCapture('Video3.avi',0) cap1 = cv2.VideoCapture('Video4.avi',0)

while(cap.isOpened()):

ret, frame = cap.read()
ret1, frame1 = cap1.read()
if ret == True: 

    both = np.concatenate((frame, frame1), axis=1)


    cv2.imshow('Frame', both)
    out.write(frame)


    if cv2.waitKey(1) & 0xFF == ord('q'):
        break


else: 
    break

cap.release() out.release()

cv2.waitKey(0) cv2.destroyAllWindows()

Combine several videos in the same window (Python)

Hello,

is it possible to combine several videos either vertical or horizontal into the same window or output file? The videos have the number of frames and format.

I tried using np.concentrate but this causes problems with the dimensions of the arrays.

Many thanks in advance

Edit: This is how it can be done - maybe there is a more elegant way but it works fine for me

import cv2
import numpy as np

np cap = cv2.VideoCapture('Video3.avi',0) cap1 = cv2.VideoCapture('Video4.avi',0)

while(cap.isOpened()):

cv2.VideoCapture('Video4.avi',0)
while(cap.isOpened()):
ret, frame = cap.read()
 ret1, frame1 = cap1.read()
 if ret == True:
 both = np.concatenate((frame, frame1), axis=1)
 cv2.imshow('Frame', both)
 out.write(frame)
  if cv2.waitKey(1) & 0xFF == ord('q'):
 break
 else:
 break

cap.release()
out.release()
cv2.waitKey(0)
cv2.destroyAllWindows()

cap.release() out.release()

cv2.waitKey(0) cv2.destroyAllWindows()

Combine several videos in the same window (Python)

Hello,

is it possible to combine several videos either vertical or horizontal into the same window or output file? The videos have the number of frames and format.

I tried using np.concentrate but this causes problems with the dimensions of the arrays.

Many thanks in advance

Edit: This is how it can be done - maybe there is a more elegant way but it works fine for me

import cv2
import numpy as np

cap = cv2.VideoCapture('Video3.avi',0)
cap1 = cv2.VideoCapture('Video4.avi',0)

while(cap.isOpened()):

    ret, frame = cap.read()
    ret1, frame1 = cap1.read()
    if ret == True: 

        both = np.concatenate((frame, frame1), axis=1)


        cv2.imshow('Frame', both)
        out.write(frame)


        if cv2.waitKey(1) & 0xFF == ord('q'):
            break


    else: 
        break

cap.release()
out.release()


cv2.waitKey(0)
cv2.destroyAllWindows()

Edit2: Thank you very much. Another question came up now:

The function

out = cv2.VideoWriter('output.avi', cv2.VideoWriter_fourcc(*'XVID'), cap.get(cv2.CAP_PROP_FPS), (frameWidth,frameHeight))

out.write(both)

is not able to write the video anymore. The function has no problem writing just one source like:

    out.write(frame)
    out.write(frame1)

but not both. Is there a solution?