2

I have opened a Video using CV2, made some changes using cv2.rectangle.

Now, when I do cv2.imshow('frame',frame), it plays the video.

Instead of this, I want to save the video somewhere, in the original size and frame rate.

John Doe
  • 169
  • 1
  • 8
  • [this](https://stackoverflow.com/questions/14440400/creating-a-video-using-opencv-2-4-0-in-python) may be relevant. – AcaNg Jul 26 '19 at 09:12

1 Answers1

5

You can save video frame by frame. Based on example on docs:

Open Cv video capture


import numpy as np
import cv2

cap = cv2.VideoCapture(0)

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,0)

        # write the flipped frame
        out.write(frame)

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

# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()

s3nh
  • 546
  • 2
  • 11