Conversion of a movie to a series of images

Conversion of a movie which is a kind of mp4 or avi to a series of images

A movie dataset is one of the unimaginable dataset to analyse, so this time, we try to convert a movie to a series of images.


  • opencv-python
In [1]:
import cv2
import os

Load Dataset

In this tutorial, we will use the First-Person Social Interactions Dataset
Alireza Fathi, Jessica K. Hodgins, James M. Rehg, Social Interactions: A First-Person Perspective, IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR), 2012.
In this time, we'll take a too much time to calculate if we use all of the data, so we'll use 19th data of Michael, Day2 only.
In [2]:
filename = "Michael_Day2_019.avi"

Conversion and Write

In [3]:
video = cv2.VideoCapture(filename)
save_dir = "save_dir"
if not os.path.exists(save_dir):
frame_count = int(video.get(7))
for i in range(frame_count):
    _, frame =
    cv2.imwrite(save_dir+"/"+str(i)+".png", frame)

After a while, we can get the sequence of data in save_dir.