# Can't save videos that are cropped

**URL:** <https://forum.opencv.org/t/cant-save-videos-that-are-cropped/11060>\
**Category:** Python\
**Tags:** videoio\
**Created:** [November 21, 2022, 10:46am UTC](https://forum.opencv.org/t/cant-save-videos-that-are-cropped/11060 "2022-11-21T10:46:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joekazama](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@joekazama](https://forum.opencv.org/u/joekazama)\
**Post date:** [November 21, 2022, 10:46am UTC](https://forum.opencv.org/t/cant-save-videos-that-are-cropped/11060/1 "2022-11-21T10:46:06Z")

</div>

Hi all. I am making a screen recorder with added functionality of being able to only record a section of the screen, (cropping realtime).

I’m stumped on why the write() function is not saving.  
this is my code section:

```auto
img = pyautogui.screenshot()
frame = np.array(img)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
cropped = frame[500:1000, 500:1000]  
out.write(cropped)
cv2.imshow('LIVE', cropped)

```

i’ve trouble shooted it down to just the write function I think. imshow() is working fine. screen recorder also works fine without cropping.

thanks for any help

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [November 21, 2022, 12:48pm UTC](https://forum.opencv.org/t/cant-save-videos-that-are-cropped/11060/2 "2022-11-21T12:48:37Z")

</div>

[MRE](https://stackoverflow.com/help/minimal-reproducible-example) is required. `out` is not defined. also watch that you have a `waitKey()` somewhere, or else the imshow window will remain numb.

OpenCV is for computer vision, not for video encoding. look at the `imageio` package or the `PyAV` package.

`VideoWriter` expects you to give it frames that are the exact same size you promised in the constructor.

---

<div class="post-metadata">

**Author:** ![joekazama](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@joekazama](https://forum.opencv.org/u/joekazama)\
**Post date:** [November 22, 2022, 7:54am UTC](https://forum.opencv.org/t/cant-save-videos-that-are-cropped/11060/3 "2022-11-22T07:54:48Z")

</div>

wow that did it. thank you. I just needed to match the dimensions with the cropped dimensions for the numpy array to write out. although it appears it has to be squared dimensions.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [November 22, 2022, 11:23am UTC](https://forum.opencv.org/t/cant-save-videos-that-are-cropped/11060/4 "2022-11-22T11:23:22Z")

</div>

> [@joekazama](#):
>
> it has to be squared dimensions.

it does not. you probably put width and height in the wrong order somewhere. OpenCV wants `(W, H)` tuples for any `cv::Size()` argument, not numpy shape tuples.
