Repository: opencv
Issue: Throw error in VideoWriter.write() if dimensions of frame to append don't match
Labels: category: videoio,RFC

<!--
If you have a question rather than reporting a bug please go to https://forum.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).

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 => 4.2
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2017
-->

- OpenCV => 4.5.0-dev
- Operating System / Platform => Windows 64 Bit
- Compiler => Python 3.9.0 [MSC v.1927 64 bit (AMD64)]

##### Detailed description

I have now struggled with this in two independent projects. I was processing video files and changing width and height of the frames. Then I wrote them to a new video with VideoWriter.write(). The code never threw an error, however, only an empty video file came out. I spent hours of code checking before I found out that the frame I was appending to the new video had one pixel less in width and height.
Hence, my suggestion: Could you let VideoWriter.write() throw an error if the dimensions of the frame to append don't match the video you want to create? I saw in some forums that other people had the same problem. I think it will help us a lot debugging our code :)

##### Steps to reproduce

```
import cv2
import numpy as np
# Create image to append
img_to_append = np.zeros([99,99,3])
# Open VideoWriter
out1 = cv2.VideoWriter('test1.avi', cv2.VideoWriter_fourcc('M','J','P','G'), 2, (99,99))
out2 = cv2.VideoWriter('test2.avi', cv2.VideoWriter_fourcc('M','J','P','G'), 2, (100,100))
# Append frame 100 times (neither throws an error!, but out1 becomes an actual video and out2 does not)
for i in range(0,100):
    out1.write(img_to_append)
    out2.write(img_to_append)

# Release videos
out1.release()
out2.release()

```

<!-- to add code example fence it with triple backticks and optional file extension
    ```.cpp
    // C++ code example
    ```
 or attach as .txt or .zip file
-->

##### Issue submission checklist

 - [ ] 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 question without real issue statement will be
   closed.
   -->
 - [ ] I checked the problem with documentation, FAQ, open issues,
       forum.opencv.org, Stack Overflow, etc and have not found 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
   -->
 - [ ] I updated to 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 latest release for each branch.
   The ticket is closed, if the problem is not reproduced with modern version.
   -->
 - [ ] 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 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 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/
   -->