2

I am generating a video from a set of images using cv2.VideoWriter(filename,fourcc,fps,size)

I want to use a particular bitrate for my output videos to reduce the file sizes. I am trying to mimic a ffmpeg command which generated videos with smaller sizes. One prominent difference I noticed is the bitrate. Resolution, codec, video length are all similar.

How do I change the bitrate when I generate videos using opencv in python?

3
  • OpenCV is computer vision library and cv2.VideoWriter is oriented toward convenience over flexibility. There are many similar questions (use Google). It's probably possible to control the bitrate using GStreamer backend. I recommend you to use other Python package for encoding the video. For using FFmpeg directly, you may take a look at my following answer.
    – Rotem
    Commented Mar 20, 2023 at 21:44
  • @Rotem I am able to work with FFmpeg directly but I am looking at ways to do this in Python. I am able to use cv.VIDEOWRITER_PROP_QUALITY to reduce quality of video which seems to reduce the bitrate although I am looking to explicity change bitrate as one can do using -b:v flag when using FFmpeg in shell.
    – darthV
    Commented Mar 22, 2023 at 20:18
  • Try skvideo.io.FFmpegWriter as in the following post. If you must use OpenCV, I think it's possible using GStreamer backend (note that the default opencv-python package is not built with GStreamer backend, and GStreamer syntax is complicated). If you find an option using OpenCV and FFmpeg backend please let me know.
    – Rotem
    Commented Mar 22, 2023 at 21:27

0

Browse other questions tagged or ask your own question.