Installation¶
In [2]:
!pip3 install -q moviepy
Use moviepy to Manipulate Videos¶
Download a short video.
In [3]:
!wget --no-check-certificate https://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_5mb.mp4 -O bunny.mp4
In [6]:
import numpy as np
from PIL import Image
import cv2
from moviepy.editor import VideoFileClip
Extract and check the first frame.
In [7]:
vidcap = cv2.VideoCapture("bunny.mp4")
In [8]:
success, arr = vidcap.read()
In [9]:
arr
Out[9]:
In [11]:
arr.shape
Out[11]:
The numpy array is the BGR
(instead of RGB
) representation of the image,
which means that you have to flip the last dimension of the numpy array
so that it can loaded using the Pillow library correctly.
In [10]:
Image.fromarray(np.flip(arr, 2))
Out[10]: