viggie
viggie

Reputation: 183

Create a video from another video by taking some frames only but without writing them onto a file

I have a little weird problem here!

I have a video in a file. I want to extract some frames out of this video and make a video out of this and then use it to display( Note: I do not want to use imshow() for this ). And I want to do this without writing this into a file.

Algorithm:
1. Read the video from file
2. extract the frames
3. make a video out of these frames(save it as a variable; do not write it into a file)
4. Use this variable which holds the new video for displaying

Any suggestions would be of great help!

Upvotes: 0

Views: 109

Answers (1)

w-m
w-m

Reputation: 11232

Create a cap = cv2.VideoCapture(file_name). Get the width and height of your movie with

h = cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)
w = cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)

Create a numpy array

frames = np.zeros((h, w, 3, number_of_frames), np.uint8)

and save the frames you want to keep to this array:

error, frame = cap.read()
frames[:,:,:,i] = frame

If you don't know how many frames you have beforehand, just concatenate them in a Python list.

Then, display your frames.

Upvotes: 1

Related Questions