Repository: opencv
Issue: videoio tests causing out of memory error on x86 - Alpine Linux
Labels: priority: low,category: videoio

<!--
If you have a question rather than reporting a bug please go to http://answers.opencv.org where you get much faster responses.
If you need further assistance please read [How To Contribute](https://github.com/opencv/opencv/wiki/How_to_contribute).

Please:

* Read the documentation to test with the latest developer build.
* Check if other person has already created the same issue to avoid duplicates. You can comment on it if there already is an issue.
* Try to be as detailed as possible in your report.
* Report only one problem per created issue.


This is a template helping you to create an issue which can be processed as quickly as possible. This is the bug reporting section for the OpenCV library.
-->

##### System information (version)
<!-- Example
- OpenCV => 3.1
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2015
-->

- OpenCV => 4.2.0
- Operating System / Platform => x86 32b, Alpine Linux
```
>>> Host system information (arch: x86, release: edge) <<<
- Number of Cores: 48
- Memory: 62.6387 Gb
- Free space: 57.4G
```
- Compiler => GCC 9.2.0

##### Detailed description
This is appearing in the test log:

```
10: [----------] 11 tests from videoio/videoio_ffmpeg
10: [ RUN      ] videoio/videoio_ffmpeg.write_big/0, where GetParam() = ("", "avi", 4096x4096)
10: [       OK ] videoio/videoio_ffmpeg.write_big/0 (2013 ms)
10: [ RUN      ] videoio/videoio_ffmpeg.write_big/1, where GetParam() = ("DX50", "avi", 4096x4096)
10: [       OK ] videoio/videoio_ffmpeg.write_big/1 (4965 ms)
10: [ RUN      ] videoio/videoio_ffmpeg.write_big/2, where GetParam() = ("FLV1", "avi", 4096x4096)
10: [       OK ] videoio/videoio_ffmpeg.write_big/2 (4956 ms)
10: [ RUN      ] videoio/videoio_ffmpeg.write_big/3, where GetParam() = ("H261", "avi", 352x288)
10: [       OK ] videoio/videoio_ffmpeg.write_big/3 (31 ms)
10: [ RUN      ] videoio/videoio_ffmpeg.write_big/4, where GetParam() = ("H263", "avi", 704x576)
10: [       OK ] videoio/videoio_ffmpeg.write_big/4 (124 ms)
10: [ RUN      ] videoio/videoio_ffmpeg.write_big/5, where GetParam() = ("I420", "avi", 4096x4096)
10: [       OK ] videoio/videoio_ffmpeg.write_big/5 (3060 ms)
10: [ RUN      ] videoio/videoio_ffmpeg.write_big/6, where GetParam() = ("MJPG", "avi", 4096x4096)
10: [       OK ] videoio/videoio_ffmpeg.write_big/6 (14058 ms)
10: [ RUN      ] videoio/videoio_ffmpeg.write_big/7, where GetParam() = ("mp4v", "avi", 4096x4096)
10: [       OK ] videoio/videoio_ffmpeg.write_big/7 (4945 ms)
10: [ RUN      ] videoio/videoio_ffmpeg.write_big/8, where GetParam() = ("MPEG", "avi", 720x576)
10: [       OK ] videoio/videoio_ffmpeg.write_big/8 (202 ms)
10: [ RUN      ] videoio/videoio_ffmpeg.write_big/9, where GetParam() = ("XVID", "avi", 4096x4096)
10: [       OK ] videoio/videoio_ffmpeg.write_big/9 (4946 ms)
10: [ RUN      ] videoio/videoio_ffmpeg.write_big/10, where GetParam() = ("H264", "mp4", 4096x2160)
10: OpenCV: FFMPEG: tag 0x34363248/'H264' is not supported with codec id 27 and format 'mp4 / MP4 (MPEG-4 Part 14)'
10: OpenCV: FFMPEG: fallback to use tag 0x31637661/'avc1'
10: x264 [error]: malloc of size 22996992 failed
10: Could not open codec 'libx264': Unspecified error
10: [     SKIP ] H264/mp4 codec is not supported - SKIP
10: [       OK ] videoio/videoio_ffmpeg.write_big/10 (270 ms)
10: [----------] 11 tests from videoio/videoio_ffmpeg (39570 ms total)
10: 
10: [----------] 3 tests from videoio_container
10: [ RUN      ] videoio_container.read/0, where GetParam() = (FFMPEG, "video/big_buck_bunny", "h264", "h264", "h264", "I420")
10: Checking extracted video stream: /tmp/__opencv_temp.bDNmnD.test_container_stream.h264 (size: 459111 bytes)
10: [h264 @ 0x5945a7f0] get_buffer() failed
10: [h264 @ 0x5945a7f0] thread_get_buffer() failed
10: [h264 @ 0x5945a7f0] decode_slice_header error
10: [h264 @ 0x5945a7f0] no frame!
10: [h264 @ 0x59472810] Error splitting the input into NAL units.
10: [h264 @ 0x5948a830] Error splitting the input into NAL units.
10: [h264 @ 0x594a2850] Error splitting the input into NAL units.
10: [h264 @ 0x594ba870] Error splitting the input into NAL units.
10: [h264 @ 0x594d2890] Error splitting the input into NAL units.
10: [h264 @ 0x594ea8b0] Error splitting the input into NAL units.
10: [h264 @ 0x595028d0] Error splitting the input into NAL units.
10: [h264 @ 0x5951a8f0] Error splitting the input into NAL units.
10: [h264 @ 0x59532910] Error splitting the input into NAL units.
10: [h264 @ 0x5954a930] Error splitting the input into NAL units.
10: [h264 @ 0x59562950] Error splitting the input into NAL units.
10: [h264 @ 0x5957a970] Error splitting the input into NAL units.
10: [h264 @ 0x59592990] Error splitting the input into NAL units.
10: [h264 @ 0x595aa9b0] Error splitting the input into NAL units.
10: [h264 @ 0x595c29d0] Error splitting the input into NAL units.
10: [h264 @ 0x595da9f0] Error splitting the input into NAL units.
10: [h264 @ 0x595f2a10] Error splitting the input into NAL units.
10: [h264 @ 0x5960aa30] Error splitting the input into NAL units.
10: [h264 @ 0x59622a50] Error splitting the input into NAL units.
10: [h264 @ 0x5963aa70] Error splitting the input into NAL units.
10: [h264 @ 0x59652a90] Error splitting the input into NAL units.
10: [h264 @ 0x5966aab0] Error splitting the input into NAL units.
10: [h264 @ 0x59682ad0] Error splitting the input into NAL units.
10: [h264 @ 0x5969aaf0] Error splitting the input into NAL units.
10: [h264 @ 0x596b2b10] Error splitting the input into NAL units.
10: [h264 @ 0x596cab30] Error splitting the input into NAL units.
10: [h264 @ 0x596e2b50] Error splitting the input into NAL units.
10: [h264 @ 0x596fab70] Error splitting the input into NAL units.
10: [h264 @ 0x59712b90] Error splitting the input into NAL units.
10: [h264 @ 0x5972abb0] Error splitting the input into NAL units.
10: [h264 @ 0x59742bd0] Error splitting the input into NAL units.
10: [h264 @ 0x5975abf0] Error splitting the input into NAL units.
10: [h264 @ 0x59772c10] Error splitting the input into NAL units.
10: [h264 @ 0x5978ac30] Error splitting the input into NAL units.
10: [h264 @ 0x597a2c50] Error splitting the input into NAL units.
10: [h264 @ 0x597bac70] Error splitting the input into NAL units.
10: [h264 @ 0x597d2c90] Error splitting the input into NAL units.
10: [h264 @ 0x597eacb0] Error splitting the input into NAL units.
10: [h264 @ 0x59802cd0] Error splitting the input into NAL units.
10: [h264 @ 0x5981acf0] Error splitting the input into NAL units.
10: [h264 @ 0x59832d10] Error splitting the input into NAL units.
10: [h264 @ 0x5984ad30] Error splitting the input into NAL units.
10: [h264 @ 0x59366570] get_buffer() failed
10: [h264 @ 0x59366570] thread_get_buffer() failed
10: [h264 @ 0x59366570] decode_slice_header error
10: [h264 @ 0x59366570] no frame!
10: [h264 @ 0x58ece440] get_buffer() failed
10: [h264 @ 0x58ece440] thread_get_buffer() failed
10: [h264 @ 0x58ece440] decode_slice_header error
10: [h264 @ 0x58ece440] no frame!
10: ../modules/videoio/test/test_ffmpeg.cpp:161: Failure
10: Value of: capActual.read(actual)
10:   Actual: false
10: Expected: true
10: 1
10: [  FAILED  ] videoio_container.read/0, where GetParam() = (FFMPEG, "video/big_buck_bunny", "h264", "h264", "h264", "I420") (106 ms)
10: [ RUN      ] videoio_container.read/1, where GetParam() = (FFMPEG, "video/big_buck_bunny", "h265", "h265", "hevc", "I420")
10: Checking extracted video stream: /tmp/__opencv_temp.cFAIbJ.test_container_stream.h265 (size: 183260 bytes)
10: ../modules/videoio/test/test_ffmpeg.cpp:161: Failure
10: Value of: capActual.read(actual)
10:   Actual: false
10: Expected: true
10: 1
10: [  FAILED  ] videoio_container.read/1, where GetParam() = (FFMPEG, "video/big_buck_bunny", "h265", "h265", "hevc", "I420") (152 ms)
10: [ RUN      ] videoio_container.read/2, where GetParam() = (FFMPEG, "video/big_buck_bunny", "mjpg.avi", "mjpg", "MJPG", "I420")
10: Checking extracted video stream: /tmp/__opencv_temp.OHEiiK.test_container_stream.mjpg (size: 1757521 bytes)
10: [       OK ] videoio_container.read/2 (813 ms)
10: [----------] 3 tests from videoio_container (1071 ms total)
10: 
10: [----------] 11 tests from videoio/videoio_gstreamer
10: [ RUN      ] videoio/videoio_gstreamer.read_write/0, where GetParam() = ("video/x-raw, format=BGR", 640x480, 640x480, 4)
10: [ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
10: unknown file: Failure
10: C++ exception with description "OpenCV(4.2.0) ../modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 1237776 bytes in function 'OutOfMemoryError'
10: " thrown in the test body.
10: [  FAILED  ] videoio/videoio_gstreamer.read_write/0, where GetParam() = ("video/x-raw, format=BGR", 640x480, 640x480, 4) (21 ms)
10: [ RUN      ] videoio/videoio_gstreamer.read_write/1, where GetParam() = ("video/x-raw, format=GRAY8", 640x480, 640x480, 8)
10: [ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
10: unknown file: Failure
10: C++ exception with description "OpenCV(4.2.0) ../modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 1237776 bytes in function 'OutOfMemoryError'
10: " thrown in the test body.
10: [  FAILED  ] videoio/videoio_gstreamer.read_write/1, where GetParam() = ("video/x-raw, format=GRAY8", 640x480, 640x480, 8) (18 ms)
10: [ RUN      ] videoio/videoio_gstreamer.read_write/2, where GetParam() = ("video/x-raw, format=UYVY", 640x480, 640x480, 107)
10: [ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
10: unknown file: Failure
10: C++ exception with description "OpenCV(4.2.0) ../modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 1237776 bytes in function 'OutOfMemoryError'
10: " thrown in the test body.
10: [  FAILED  ] videoio/videoio_gstreamer.read_write/2, where GetParam() = ("video/x-raw, format=UYVY", 640x480, 640x480, 107) (18 ms)
10: [ RUN      ] videoio/videoio_gstreamer.read_write/3, where GetParam() = ("video/x-raw, format=YUY2", 640x480, 640x480, 115)
10: [ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
10: unknown file: Failure
10: C++ exception with description "OpenCV(4.2.0) ../modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 1237776 bytes in function 'OutOfMemoryError'
10: " thrown in the test body.
10: [  FAILED  ] videoio/videoio_gstreamer.read_write/3, where GetParam() = ("video/x-raw, format=YUY2", 640x480, 640x480, 115) (17 ms)
10: [ RUN      ] videoio/videoio_gstreamer.read_write/4, where GetParam() = ("video/x-raw, format=YVYU", 640x480, 640x480, 117)
10: [ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
10: unknown file: Failure
10: C++ exception with description "OpenCV(4.2.0) ../modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 1237776 bytes in function 'OutOfMemoryError'
10: " thrown in the test body.
10: [  FAILED  ] videoio/videoio_gstreamer.read_write/4, where GetParam() = ("video/x-raw, format=YVYU", 640x480, 640x480, 117) (23 ms)
10: [ RUN      ] videoio/videoio_gstreamer.read_write/5, where GetParam() = ("video/x-raw, format=NV12", 640x480, 640x720, 90)
10: [ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
10: unknown file: Failure
10: C++ exception with description "OpenCV(4.2.0) ../modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 1237776 bytes in function 'OutOfMemoryError'
10: " thrown in the test body.
10: [  FAILED  ] videoio/videoio_gstreamer.read_write/5, where GetParam() = ("video/x-raw, format=NV12", 640x480, 640x720, 90) (17 ms)
10: [ RUN      ] videoio/videoio_gstreamer.read_write/6, where GetParam() = ("video/x-raw, format=NV21", 640x480, 640x720, 92)
10: [ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
10: unknown file: Failure
10: C++ exception with description "OpenCV(4.2.0) ../modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 1237776 bytes in function 'OutOfMemoryError'
10: " thrown in the test body.
10: [  FAILED  ] videoio/videoio_gstreamer.read_write/6, where GetParam() = ("video/x-raw, format=NV21", 640x480, 640x720, 92) (17 ms)
10: [ RUN      ] videoio/videoio_gstreamer.read_write/7, where GetParam() = ("video/x-raw, format=YV12", 640x480, 640x720, 98)
10: [ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
10: unknown file: Failure
10: C++ exception with description "OpenCV(4.2.0) ../modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 1237776 bytes in function 'OutOfMemoryError'
10: " thrown in the test body.
10: [  FAILED  ] videoio/videoio_gstreamer.read_write/7, where GetParam() = ("video/x-raw, format=YV12", 640x480, 640x720, 98) (18 ms)
10: [ RUN      ] videoio/videoio_gstreamer.read_write/8, where GetParam() = ("video/x-raw, format=I420", 640x480, 640x720, 100)
10: [ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
10: unknown file: Failure
10: C++ exception with description "OpenCV(4.2.0) ../modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 1237776 bytes in function 'OutOfMemoryError'
10: " thrown in the test body.
10: [  FAILED  ] videoio/videoio_gstreamer.read_write/8, where GetParam() = ("video/x-raw, format=I420", 640x480, 640x720, 100) (18 ms)
10: [ RUN      ] videoio/videoio_gstreamer.read_write/9, where GetParam() = ("video/x-bayer", 640x480, 640x480, 48)
10: [ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
10: unknown file: Failure
10: C++ exception with description "OpenCV(4.2.0) ../modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 1237776 bytes in function 'OutOfMemoryError'
10: " thrown in the test body.
10: [  FAILED  ] videoio/videoio_gstreamer.read_write/9, where GetParam() = ("video/x-bayer", 640x480, 640x480, 48) (16 ms)
10: [ RUN      ] videoio/videoio_gstreamer.read_write/10, where GetParam() = ("jpegenc ! image/jpeg", 640x480, 640x480, 4)
10: [ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
10/15 Test #10: opencv_test_videoio ..............***Exception: SegFault 62.85 sec
```
Could it be that the ffmpeg test `videoio/videoio_ffmpeg.write_big` is hitting an error and then not freeing its memory, causing the rest of the test to hit out of memory errors?

Full build log, as always: 
[job3.log](https://github.com/opencv/opencv/files/4111102/job3.log)

Should the write big test perhaps be skipped on 32b architecture?

##### Steps to reproduce

Compile with tests, ffmpeg and gstreamer on 32b x86 Alpine Linux machine. (I only have access to CI build infrastructure)