0

i tried to change the resolution of a video file from 854x480 to a lower resolution of 640x480 using cv2 with the motive of reducing size,but while the original file is 3.2MB, the converted file is 8.3MB. I have also maintained the same video format. I'm new to video processing. Why is this happning and how can i modify the following code to get better results?

Thank you in advance!

here is the code i used:

    import cv2
    import numpy as np

    cap = cv2.VideoCapture(r'C:\Users\CSC\Desktop\SmartDesert\1.mp4')

    fourcc = cv2.VideoWriter_fourcc(*'mp4v')
    out = cv2.VideoWriter(r'C:\Users\CSC\Desktop\SmartDesert\1_Output.mp4', fourcc, 25, (640, 480))

    while True:
        ret, frame = cap.read()
        if ret == True:
            b = cv2.resize(frame, (640, 480), fx=0, fy=0, interpolation=cv2.INTER_CUBIC)
            out.write(b)
        else:
            break

    cap.release()
    out.release()
    cv2.destroyAllWindows()

1 Answers1

0

According to Wikipedia, mp4 is just a digital multimedia container format. It means mp4 provides a method of bundling an audio stream and video stream under one roof, i.e. an .mp4 file. During the bundling process, audio and video undergo compression codecs that ultimately gets converted to an output file.

An .mp4 container supports various video codecs. The one you used to write the video is mp4v. mp4v are raw mpeg-4 video streams, thus this might increase the size of video albeit resizing.

Trying another codec might help. Read this for the various codecs that can be used with .mp4

Cheers!

Aman2909
  • 1
  • 1