Files
opencv-MIRROR/modules/videoio/test
Savya Sanchi Sharma eb1cdcb506 Merge pull request #30064 from SavyaSanchi-Sharma:vidwrite
videoio: encoder controls for VideoWriter (bitrate, CRF, preset, GOP, pixel format) - #30064

Resolves [Issue#8961](https://github.com/opencv/opencv/issues/8961)

Until now, the only way to control encoder quality from VideoWriter was to write a GStreamer pipeline string by hand. This PR adds open-time properties that work with both the FFmpeg and GStreamer backends:

- VIDEOWRITER_PROP_BITRATE sets the target bitrate in bits per second.
- VIDEOWRITER_PROP_CRF sets the constant rate factor. It overrides bitrate if both are given.
- VIDEOWRITER_PROP_PRESET takes a value from the new VideoWriterPresets enum, ULTRAFAST through PLACEBO, using the x264/x265 preset names.
- VIDEOWRITER_PROP_GOP_SIZE sets the maximum interval between key frames.
- VIDEOWRITER_PROP_COLOR_SPACE used to be GStreamer-only and now works with FFmpeg too. It takes a fourcc, the same encoding as CAP_PROP_CODEC_PIXEL_FORMAT.

Tests are in test_ffmpeg.cpp and test_gstreamer.cpp. They check that CRF and bitrate change the output size, that GOP and preset values come back from get(), that the pixel format matches the capture property, that an unsupported property makes open() fail, and that nothing changes when no properties are set.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-10-01 12:29:37 +03:00
..
2021-04-10 18:03:01 +00:00
2025-07-28 10:04:17 +03:00
2026-06-05 20:07:44 +05:30