Repository: opencv
Issue: `cv2.VideoWriter` fails to write file silently
Labels: category: videoio

##### System information (version)
- OpenCV => 4.5.5
- Operating System / Platform => Gentoo Linux
- Compiler => GCC 11.2.1


##### Detailed description

The `writer1.write(np.random.randint(0, 255, (nx, ny, 3)).astype("uint8"))` call fails to write a file and does so without raising an error.
The file will get written if opencv is built with optional `ffmpeg` support, yet nonetheless it seems strange that when it fails it does so and keeps going.
Lastly, would it be possible to have it write a file without requiring ffmpeg support? 

##### Steps to reproduce

```bash
chymera@decohost ~ $ cat lulu.py
def video_files(tmp_path):
    video_paths = []
    import cv2
    import numpy as np
    import os

    video_path = f"{tmp_path}/video_files"
    os.mkdir(video_path)
    for no in range(2):
        movie_file1 = f"{video_path}/test1_{no}.avi"
        movie_file2 = f"{video_path}/test2_{no}.avi"
        (nf, nx, ny) = (5, 10, 20)
        writer1 = cv2.VideoWriter(
            filename=str(movie_file1),
            apiPreference=None,
            fourcc=cv2.VideoWriter_fourcc(*"DIVX"),
            fps=25,
            frameSize=(ny, nx),
            params=None,
        )
        writer2 = cv2.VideoWriter(
            filename=str(movie_file2),
            apiPreference=None,
            fourcc=cv2.VideoWriter_fourcc(*"DIVX"),
            fps=25,
            frameSize=(ny, nx),
            params=None,
        )
        for k in range(nf):
            writer1.write(np.random.randint(0, 255, (nx, ny, 3)).astype("uint8"))
            writer2.write(np.random.randint(0, 255, (nx, ny, 3)).astype("uint8"))
        writer1.release()
        writer2.release()
        video_paths.append((movie_file1, movie_file2))
    return video_paths
chymera@decohost ~ $ python -c "import lulu; lulu.video_files('/tmp')"
[ INFO:0@0.004] global /var/tmp/portage/media-libs/opencv-4.5.5-r1/work/opencv-4.5.5/modules/videoio/src/videoio_registry.cpp (223) VideoBackendRegistry VIDEOIO: Enabled backends(7, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); V4L2(970); CV_IMAGES(960); CV_MJPEG(950); UEYE(940)
[ INFO:0@0.004] global /var/tmp/portage/media-libs/opencv-4.5.5-r1/work/opencv-4.5.5/modules/videoio/src/backend_plugin.cpp (369) getPluginCandidates VideoIO plugin (FFMPEG): glob is 'libopencv_videoio_ffmpeg*.so', 1 location(s)
[ INFO:0@0.009] global /var/tmp/portage/media-libs/opencv-4.5.5-r1/work/opencv-4.5.5/modules/videoio/src/backend_plugin.cpp (379) getPluginCandidates     - /usr/lib64: 0
[ INFO:0@0.009] global /var/tmp/portage/media-libs/opencv-4.5.5-r1/work/opencv-4.5.5/modules/videoio/src/backend_plugin.cpp (383) getPluginCandidates Found 0 plugin(s) for FFMPEG
[ INFO:0@0.010] global /var/tmp/portage/media-libs/opencv-4.5.5-r1/work/opencv-4.5.5/modules/videoio/src/backend_plugin.cpp (369) getPluginCandidates VideoIO plugin (GSTREAMER): glob is 'libopencv_videoio_gstreamer*.so', 1 location(s)
[ INFO:0@0.014] global /var/tmp/portage/media-libs/opencv-4.5.5-r1/work/opencv-4.5.5/modules/videoio/src/backend_plugin.cpp (379) getPluginCandidates     - /usr/lib64: 0
[ INFO:0@0.014] global /var/tmp/portage/media-libs/opencv-4.5.5-r1/work/opencv-4.5.5/modules/videoio/src/backend_plugin.cpp (383) getPluginCandidates Found 0 plugin(s) for GSTREAMER
[ INFO:0@0.014] global /var/tmp/portage/media-libs/opencv-4.5.5-r1/work/opencv-4.5.5/modules/videoio/src/backend_plugin.cpp (369) getPluginCandidates VideoIO plugin (INTEL_MFX): glob is 'libopencv_videoio_intel_mfx*.so', 1 location(s)
[ INFO:0@0.018] global /var/tmp/portage/media-libs/opencv-4.5.5-r1/work/opencv-4.5.5/modules/videoio/src/backend_plugin.cpp (379) getPluginCandidates     - /usr/lib64: 0
[ INFO:0@0.018] global /var/tmp/portage/media-libs/opencv-4.5.5-r1/work/opencv-4.5.5/modules/videoio/src/backend_plugin.cpp (383) getPluginCandidates Found 0 plugin(s) for INTEL_MFX
[ INFO:0@0.018] global /var/tmp/portage/media-libs/opencv-4.5.5-r1/work/opencv-4.5.5/modules/videoio/src/cap_images.cpp (282) icvExtractPattern Pattern: /tmp/video_files/test%01d_0.avi @ 1
[ INFO:0@0.018] global /var/tmp/portage/media-libs/opencv-4.5.5-r1/work/opencv-4.5.5/modules/videoio/src/cap_images.cpp (282) icvExtractPattern Pattern: /tmp/video_files/test%01d_0.avi @ 2
[ INFO:0@0.018] global /var/tmp/portage/media-libs/opencv-4.5.5-r1/work/opencv-4.5.5/modules/videoio/src/cap_images.cpp (282) icvExtractPattern Pattern: /tmp/video_files/test%01d_1.avi @ 1
[ INFO:0@0.018] global /var/tmp/portage/media-libs/opencv-4.5.5-r1/work/opencv-4.5.5/modules/videoio/src/cap_images.cpp (282) icvExtractPattern Pattern: /tmp/video_files/test%01d_1.avi @ 2
chymera@decohost ~ $ ls /tmp/video_files/
```

##### Issue submission checklist

 - [x] I report the issue, it's not a question
   <!--
   OpenCV team works with forum.opencv.org, Stack Overflow and other communities
   to discuss problems. Tickets with questions without a real issue statement will be
   closed.
   -->
 - [x] I checked the problem with documentation, FAQ, open issues,
       forum.opencv.org, Stack Overflow, etc and have not found any solution
   <!--
   Places to check:
   * OpenCV documentation: https://docs.opencv.org
   * FAQ page: https://github.com/opencv/opencv/wiki/FAQ
   * OpenCV forum: https://forum.opencv.org
   * OpenCV issue tracker: https://github.com/opencv/opencv/issues?q=is%3Aissue
   * Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
   -->
 - [x] I updated to the latest OpenCV version and the issue is still there
   <!--
   master branch for OpenCV 4.x and 3.4 branch for OpenCV 3.x releases.
   OpenCV team supports only the latest release for each branch.
   The ticket is closed if the problem is not reproduced with the modern version.
   -->
 - [x] There is reproducer code and related data files: videos, images, onnx, etc
   <!--
   The best reproducer -- test case for OpenCV that we can add to the library.
   Recommendations for media files and binary files:
   * Try to reproduce the issue with images and videos in opencv_extra repository
     to reduce attachment size
   * Use PNG for images, if you report some CV related bug, but not image reader
     issue
   * Attach the image as an archive to the ticket, if you report some reader issue.
     Image hosting services compress images and it breaks the repro code.
   * Provide ONNX file for some public model or ONNX file with random weights,
     if you report ONNX parsing or handling issue. Architecture details diagram
     from netron tool can be very useful too. See https://lutzroeder.github.io/netron/
   -->