Save animation matplotlib deos not save all frames

I am processing a video. my code is wroking perfectly until calling save function which save only about 100 frames. Based on the documentation of save, we have to indicate the save_cout number. By indicating this number the saved video *.mp4 does not contains stream!!

import cv2
from matplotlib import patches, lines
from matplotlib.patches import Polygon
import matplotlib.pyplot as plt
plt.rcParams['animation.ffmpeg_path'] = '/usr/bin/ffmpeg'
import random
import numpy as np
from matplotlib.animation import FuncAnimation
from matplotlib.animation import FFMpegWriter
writer = FFMpegWriter(fps=30, bitrate=1800)
path_video ="*.mp4"
cap =cv2.VideoCapture(path_video)
if cap.isOpened():
    fig,ax =plt.subplots(1, figsize=(16,16))
    def grab_frame(cap):
        ret, frame =
        return frame

    def process(frame, ax):
        n = np.random.randint(5, 10, size=1)
        rects = []
        for i in range(n[0]):
            rects.append(np.random.randint(0, 800, size=4))
        height, width = frame.shape[:2]
        ax.set_ylim(height, -50)
        ax.set_xlim(-50, width)
        output_image = frame.astype(np.uint32).copy()
        N = rects.shape[0]
        for i in range(N):
            y1, x1, y2, x2 = rects[i]
            patch = patches.Rectangle((x1, y1), x2 - x1, y2 - y1, linewidth=2,
                                  alpha=0.5, linestyle="dashed",
                                  edgecolor="red", facecolor='none')

    def update(i):
        # for each frame we want to plot some rectangle on it.
        process(frame=grab_frame(cap), ax=ax)

    ani = FuncAnimation(fig, update, save_cout=1000)"beng_result.mp4", writer=writer)
    print("check video path")