Problem with saving High Quality or Lossless video

I want to save HQ or lossless video using VideoWriter().
Can someone provide the solution?
I succeeded in using some codecs with fourcc(), for example H264, but there is noticeable loss in quality and I don’t know how to adjust compression options…
I am coding in C++ for Windows, if matters.
So far, I found two ways:

  1. Save each frame as PNG and assemble them later with other software.
  2. fourcc(‘R’, ‘G’, ‘B’, ‘A’) option - too big file in the result.

Thank you in advance!

what kinda video material? camera data (any noise at all), or synthetic data (lots of uniformly colored area)?


H.264 (avc1 fourcc) can be lossless, with the right parameters. x264 anyway.

there are some always-lossless codecs out there but they will do as well or worse than PNG for individual images.

Thanks for reply!
The second one - synthetic data (lots of uniformly colored area).
Tried to play with .set(VIDEOWRITER_PROP_QUALITY, some number) for different codecs (including X264) - found no effect on the final file size… I tried 100, 5, 1, 0.1 – no difference. Am I doing something wrong?

use something like QT Animation (fourcc “rle ”) then. I don’t know if that can be requested properly through OpenCV’s VideoWriter.

and if you use any H.264, take care that the conversion process doesn’t do any chroma subsampling, and see if it can stay RGB instead of YUV.

then it’s probably not implemented.

use ffmpeg’s libraries directly then.

1 Like

It doesn’t sound easy to me :slight_smile: Should I compile OpenCV libs by myself? Can you give me links to some tutorials, if any?