Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Video Resizing and saving it as .avi

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.