RafaelJan
RafaelJan

Reputation: 3608

Read frame by frame and create video using cv2 in python

I want to read frame by frame from existing video, and create new video from these frames.

In my real project I want to change each frame before making the new video but for simplicity's sake of this question I just want to create new video from the same frames without any change.

Upvotes: 0

Views: 798

Answers (1)

RafaelJan
RafaelJan

Reputation: 3608

This code is working for me:

import cv2
vidcap = cv2.VideoCapture('input_video.mp4')
vidwrite = cv2.VideoWriter('output_video.mp4', cv2.VideoWriter_fourcc(*'MP4V'), 30, (1920,1080))
success,image = vidcap.read()
while success:
  vidwrite.write(image) # write frame into video
  success,image = vidcap.read() # read frame from video
vidwrite.release()
cv2.destroyAllWindows()

The strange thing is that the output video is twice bigger than the input video

Upvotes: 1

Related Questions