yoel
yoel

Reputation: 1

How to fix problem with save a video frame by frame

The problem is that I try to save a video file I get a one frame each time from another function (I check this is not the same frame...), the video created but only with one frame. I run with a loop outside the class Video_utility and send frame to the function save_and_display_video.

import cv2

class Video_utility:
    def __init__(self, name_video, format_video, display, fps, size):
        self.name_video = name_video
        self.format_video = format_video
        self.display = display
        self.fps = fps
        self.size = size
        self.stream_frame = None
        self.flag_update = True
        self.display = True
        self.fourcc = cv2.VideoWriter_fourcc(*'XVID')
        self.out = cv2.VideoWriter(name_video, self.fourcc, fps, self.size)
        self.i = 0

    def save_and_display_video(self, frame):
        frame = cv2.resize(frame,(self.size))
        self.out.write(frame)
        self.out.release()
        cv2.destroyAllWindows()

Upvotes: 0

Views: 68

Answers (1)

Peteris
Peteris

Reputation: 3325

Don't close the file after every frame

You have self.out.release() at your save_and_display_video() function.

You'd need to do that only after you've received the whole video.

Upvotes: 1

Related Questions