Animate multiple still images with Python

Overview

Introducing how to make a slideshow-like video by connecting "photos taken every day from the same place". Use the Python library MoviePy.

Operation check environment

Advance preparation

$ pip install moviepy
input
├── IMG_0000.jpg
├── IMG_0001.jpg
├── IMG_0002.jpg
├── ...

Whole source

create_slideshow.py


#!/usr/bin/env python3.6
# -*- coding: utf-8 -*-

import glob
from moviepy.editor import *

if __name__ == '__main__':

    #The extension under the input directory is.Get jpg file name list all at once
    file_list = glob.glob(r'input/*.jpg')
    #Sort the file name list in ascending order
    file_list.sort()

    #Processing to store still image information that is the basis for creating a slide show
    clips = [] 
    for m in file_list:
        clip = ImageClip(m).set_duration('00:00:00.50')
        clip = clip.resize(newsize=(640,480))
        clips.append(clip)

    #Processing to create a moving image of a slide show
    concat_clip = concatenate_videoclips(clips, method="compose")
    concat_clip.write_videofile(r"output.mp4", 
                                fps=24,
                                write_logfile=True,
                                )

Commentary

Processing to store still image information that is the basis for creating a slide show

    clips = [] 
    for m in file_list:
        clip = ImageClip(m).set_duration('00:00:00.50')
        clip = clip.resize(newsize=(640,480))
        clips.append(clip)

Processing to create a moving image of a slide show

    concat_clip = concatenate_videoclips(clips, method="compose")
    concat_clip.write_videofile(r"output.mp4", 
                                fps=24,
                                write_logfile=True,
                                )

text:output.mp4.log


ffmpeg version 4.2.2-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8 (Debian 8.3.0-6)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, rawvideo, from 'pipe:':
  Duration: N/A, start: 0.000000, bitrate: 176947 kb/s
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 640x480, 176947 kb/s, 24 tbr, 24 tbn, 24 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
[libx264 @ 0x6856ac0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x6856ac0] profile High, level 3.0, 4:2:0, 8-bit
[libx264 @ 0x6856ac0] 264 - core 159 r2991 1771b55 - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 640x480, q=-1--1, 24 fps, 12288 tbn, 24 tbc
    Metadata:
      encoder         : Lavc58.54.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=   85 fps=0.0 q=28.0 size=       0kB time=00:00:01.33 bitrate=   0.3kbits/s speed=2.58x    
frame=  148 fps=145 q=28.0 size=     512kB time=00:00:03.95 bitrate=1059.7kbits/s speed=3.89x    
frame=  205 fps=130 q=28.0 size=     768kB time=00:00:06.33 bitrate= 993.4kbits/s speed=   4x
...

Recommended Posts

Animate multiple still images with Python
Post multiple Twitter images with python
Bordering images with python Part 1
Animate multiple graphs with matplotlib
Number recognition in images with Python
Load gif images with Python + OpenCV
[Python] Collect images easily with icrawler!
Multiple integrals with Python and Sympy
[Python] Creating multiple windows with Tkinter
Working with DICOM images in Python
Amplify images for machine learning with python
Capturing images with Pupil, python and OpenCV
Process multiple lists with for in Python
[Python] Read images with OpenCV (for beginners)
Question: Multiple integrals with python don't work
Add Gaussian noise to images with python2.7
Importing and exporting GeoTiff images with Python
Manage multiple Python versions with update-alternatives (Ubuntu)
Read text in images with python OCR
Upload images to Google Drive with Python
Statistics with python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Animate with matplotlib
Excel with Python
Microcomputer with Python
Cast with python
Generating solid color images with python | Kaggle icon
Cannot upload multiple images from form with FastAPI
[Python] How to draw multiple graphs with Matplotlib
Manage Python multiple version environment with Pythonz, virtualenv
[Python] Takes representative values ​​of multiple images [Numpy]
Use multiple versions of python environment with pyenv
Developed and verified with multiple python versions with direnv
Bulk download images from specific URLs with python
[Python] Dealing with multiple call errors in ray.init
Manage multiple context managers together with Python contextlib.ExitStack
Convert multiple proto files at once with python
[Python] Mention to multiple people with Slack API
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Multiple selections with Jupyter
Scraping with Python (preparation)
Automatically paste images into PowerPoint materials with python + α
Try scraping with Python.
Learning Python with ChemTHEATER 03
Sequential search with Python
Get media timeline images and videos with Python + Tweepy
"Object-oriented" learning with python
Bulk download images from specific site URLs with python
Run Python with VBA