K
K
kilrea2020-02-02 20:10:41
Python
kilrea, 2020-02-02 20:10:41

How to set bitrate in opencv?

I'm piecing together multiple videos using opencv. Everything turns out fine, but the size of the output file is 300-400 mb, and the total size of the input files is no more than 30 mb. I looked at the metadata of the output video, the bitrate is 30000 kb / s. You can change the bitrate with ffmpeg:

ffmpeg -i end.mp4 -b:v 500k -b:a 500k output_video.mp4


but I would like to immediately record a file with the desired bitrate during gluing. Gluing code:

video_index = 0
cap = VideoCapture(videofiles[0])

fourcc = cv2.VideoWriter_fourcc(*'MJPG')
out = cv2.VideoWriter('result.avi', fourcc, fps, (w,h))

while(cap.isOpened()):
  ret, frame = cap.read()
  if frame is None:
    print ('Обработали видео', videofiles[video_index])
    video_index += 1
    if video_index >= len(videofiles):
      break
    cap = VideoCapture(videofiles[ video_index ])
    ret, frame = cap.read()
  out.write(frame)
  if waitKey(1) & 0xFF == ord('q'):
    break

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


Is it possible to immediately specify the bitrate in opencv VideoWriter?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kilrea, 2020-02-02
@kilrea

I changed the codec to *'DIVX' and the output file is normal size. Issue resolved

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question