# .write() function, video problem

**URL:** <https://forum.opencv.org/t/write-function-video-problem/4317>\
**Category:** Python\
**Tags:** videoio\
**Created:** [July 13, 2021, 11:59am UTC](https://forum.opencv.org/t/write-function-video-problem/4317 "2021-07-13T11:59:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Psych](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Psych](https://forum.opencv.org/u/Psych)\
**Post date:** [July 13, 2021, 11:59am UTC](https://forum.opencv.org/t/write-function-video-problem/4317/1 "2021-07-13T11:59:20Z")

</div>

Hello,

I am trying to write a video with the .write() function of cv2 and the frames of the video written don’t match with the frame I enter in the function.

It could be a problem of compression or bytes based.

I tried to apply the function np.uint8() on my matrix and change the format of the video but nothing works.

Thanks for your help.

Here’s my script :

```auto
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import math
import cv2
import ffmpeg
from PIL import Image

theta = math.radians(0)

size = 255

def rotation (x, y, theta): 
    x_rot = x*np.cos(theta) + y*np.sin(theta)
    y_rot = -x*np.sin(theta) + y*np.cos(theta)
    return(x_rot, y_rot)

def gabor(x, y, t, sf, sigma_x, sigma_y, w, phase) :
    carrier = np.cos(2*np.pi*sf*rotation(x, y, theta)[0] - w*t + phase)
    gaussian_window = np.exp(-0.5*((rotation(x, y, theta)[0]/sigma_x)**2 + (rotation(x, y, theta)[1]/sigma_y)**2 ))
    return carrier*gaussian_window

M = np.zeros((size, size))

def image (t) : 
    x=-(size/2) # initialization in x
    for i in range (size):
        y=-(size/2) # initialization in y
        x = x + 1
    
        for j in range (size):
            y = y + 1
            M[i,j] = gabor(x, y, t, 0.02, 30, 30, 2*np.pi, np.pi/1) 
    return M

N_frame = 20
N = size
    

fourcc = cv2.VideoWriter_fourcc('X','V','I','D')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (N,N), 0)

i = 0
for i in range (N_frame - 1) :
    t = i*0.1
    frame = image(t)
out.release()

```

---

<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:** [July 13, 2021, 2:14pm UTC](https://forum.opencv.org/t/write-function-video-problem/4317/2 "2021-07-13T14:14:00Z")

</div>

do you understand the meaning of “lossy compression”? XVID is a lossy codec.

please demonstrate what you consider “don’t match”
