0

enter image description here

import cv2
from moviepy.video.io.VideoFileClip import VideoFileClip

def process_image(img):
    out = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    return out

video_output = 'output_videos/Entry_02.mp4'
video_input = VideoFileClip('input_videos/Entry_02.mp4')
processed_video = video_input.fl_image(process_image)
%time processed_video.write_videofile(video_output, audio=False)

Exploring VideoFileClip from moviepy to do some video processing, not sure why it generated duplicate multiple frames (3x3) in the output video.

user1569341
  • 333
  • 1
  • 6
  • 17

1 Answers1

0

Apparently, write_videofile expects a RGB image (3 channels) instead of the gray scale image that cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) returns. You should get the desired grayscale image by copying out to all channels.

def process_image(img):
    image_height = img.shape[0]
    image_width = img.shape[1]
    out = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    img = np.zeros((3, image_height, image_width))
    img[0] = out
    img[1] = out
    img[2] = out
    return np.moveaxis(img, 0, -1)
Christian Vorhemus
  • 2,396
  • 1
  • 17
  • 29