Skip to content

Instantly share code, notes, and snippets.

@VincenzoLaSpesa
Created October 7, 2022 10:48
Show Gist options
  • Select an option

  • Save VincenzoLaSpesa/8de635e28d1b47584db20bf14d53bbbe to your computer and use it in GitHub Desktop.

Select an option

Save VincenzoLaSpesa/8de635e28d1b47584db20bf14d53bbbe to your computer and use it in GitHub Desktop.
Merge images to a slideshow saved as a video, in python
from moviepy.editor import *
from pathlib import Path
from subprocess import check_output
import os
import argparse
import json
def run(cmd, echo=True, shell=True, printOutput = True) -> str:
""" Runs a command, returns the output """
if echo:
print(cmd)
output = check_output(cmd, shell=shell).decode("utf-8")
if printOutput:
print(output)
return output
img_clips = []
#accessing path of each image
imgs = (
"Superfrog.png","Superfrog2.png","Superfrog.png"
)
img_clips.append(ImageClip(imgs[0]).set_duration(0.5))
img_clips.append(ImageClip(imgs[1]).set_duration(1))
img_clips.append(ImageClip(imgs[0]).set_duration(0.5))
#concatenating slides
video_slides = concatenate_videoclips(img_clips, method='compose')
#exporting final video
video_slides.write_videofile("output_video.mp4", fps=10)
run('ffmpeg -i output_video.mp4 -vf "fps=10,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment