0

for saving video from rtsp link, I used cv2,

out = cv2.VideoWriter('vid.mp4',
                              cv2.VideoWriter_fourcc('m', 'p', '4', 'v'),
                              video.get(5), (int(video.get(3)), int(video.get(4))))

This code works, but saving 10 second video, it occupies about 3 MB of space which is very high.

the .avi format is also in same size, how to reduce the space of the video file without resizing the frame shape and how to achieve this while writing frames to the cv2.VideoWriter?

thanks

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Vishak Raj
  • 141
  • 1
  • 1
  • 8
  • OpenCV is for computer vision, not for receiving and saving video. wrong library. use ffmpeg instead. -- do you understand that your current approach causes a complete **re-encode** of the video? that's because you use the wrong library. – Christoph Rackwitz Aug 23 '22 at 18:42
  • @ChristophRackwitz, is it possible to do in cv2? – Vishak Raj Aug 24 '22 at 08:53
  • OpenCV is **not a video compression/handling library**. it can't do **stream copy**, but you should want that. if you require to stick with OpenCV, you will get a re-encode. if you don't like the data rate, experiment with `VIDEOWRITER_PROP_QUALITY` but that may only have an effect for specific situations, not yours – Christoph Rackwitz Aug 24 '22 at 08:55
  • @VishakRaj You may use FFmpeg (command line interface) instead of using `cv2.VideoWriter`. Take a look at my [following answer](https://stackoverflow.com/a/61281547/4926757). Use larger value of `-crf` argument for saving space. Try `libx264` codec in case `libx265` is too computational intensive. – Rotem Aug 24 '22 at 20:27

0 Answers0