Is VideoWriter using compression while saving video? [OpenCV 4]

Yes, VideoWriter compresses the video. As a matter of fact, it uses some lower-level libraries to do the compression (ffmpeg).
However compression is a very computationally intensive task, especially if it’s done on the CPU. So you can acquire 25 frames per second, but you can encode only ~15fps. As the acquisition waits for the previous frame to be written, the frame rate drops.
BMP doesn’t use any compression, it just dumps the data on the disk, which is fast. JPG compression is also much faster than DIVX, so it can also keep up with the input flow.
You can try to use a faster codec (MJPG, maybe H264) or use directly some other library that does the video encoding on the GPU.

[Edit] BTW, some details on advanced video encoding (the MPEG-4 type codecs): it tries to eliminate as much redundant data as possible to reduce the file size. As the frames are similar to the previous and next frames, several images images are used to encode/decode the frame. It also tries to guess where are the interesting parts in the movie (what are you watching), and that part is encoded in better quality, the rest in worse quality. So as you can see, there is a lot going on in the encoding.
MJPG creates a video as a series of JPG images, so it should be much faster - but the visual quality is no match for the MPEG-4 techniques. That said, if you save the video for later processing, the perceptual compression of MPEG-4 is as much of an advantage.

1 Like