Ask Your Question
0

Video Resizing and saving it as .avi

asked 2017-04-25 14:32:24 -0600

nsbendre gravatar image

How do I resize a video?? The original resolution of a video is 123x456 and I want to resize the video and save it in format of width =320 and height = 240. Below is the code for the same.

import numpy as np

import cv2

cap = cv2.VideoCapture('walking.avi')

print (cap.get(3), 'x', cap.get(4))

cap_w = cap.set(3,320)

cap_h = cap.set(4,240)

print (cap_w, 'x', cap_h)

height = 240

width = 320

fourcc = cv2.VideoWriter_fourcc(*'XVID')

out = cv2.VideoWriter('cap_output.avi',fourcc, 20.0, (320,240))

cap.release()

cv2.destroyAllWindows()

The print output I get is:

768.0 x 576.0

False x False

Thank you.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2017-04-26 00:42:47 -0600

berak gravatar image

you cannot resize the video using Videocapture.set() (this might only work for webcams).

please use cv2.resize():

>>> help(cv2.resize)
Help on built-in function resize:

resize(...)
    resize(src, dsize[, dst[, fx[, fy[, interpolation]]]]) -> dst

like:

ret, frame = cap.read()
if ret: # else it means the movie is over !
     res = cv2.resize(frame, (320,240))
     out.write(res)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-04-25 14:32:24 -0600

Seen: 8,980 times

Last updated: Apr 26 '17