Skip to content

Instantly share code, notes, and snippets.

@Zulko
Zulko / 3D_piano_from_midi.py
Last active April 9, 2024 05:51
Turn a piano MIDI file into a basic 3D animated piano video.
"""
Turn a piano MIDI file into a basic 3D animated piano video.
See the result here:
I am leaving it as a script because it is not tested on enough MIDI files yet.
Zulko 2014
This script is released under a Public Domain (Creative Commons 0) licence.
@Zulko
Zulko / soccer_cuts.py
Last active March 31, 2024 12:03
A python script to automatically summarize soccer videos based on the crowd's reactions
#
# This Python script makes a summary of a football game by cutting
# the video around the 10 % loudest moments, which generally
# include the goals and other important events.
# For more details, see this blog post:
# http://zulko.github.io/blog/2014/07/04/automatic-soccer-highlights-compilations-with-python/
#
# LICENCE: Creative Commons 0 - Public Domain
# I, the author of this script, wave any rights and place this work in the public domain.
#
"""
An alternative text clip for Moviepy, relying on Gizeh instead of ImageMagick
Advantages:
- Super fast (20x faster)
- no need to install imagemagick
- full-vector graphic, no aliasing problems
- Easier font names
Disadvantages:
@Zulko
Zulko / cubes_pyode_vapory.py
Last active December 27, 2023 12:29
3D cubes animation with PyODE and Vapory
"""
Physics simulation with PyODE followed by a (basic) rendering with Vapory
See the result here: http://i.imgur.com/TdhxwGz.gifv
Zulko 2014
This script is placed in the Public Domain (Licence Creative Commons 0)
"""
@Zulko
Zulko / python_mermaid_class_tree.py
Created April 18, 2017 18:04
Automatic Python module class tree generation, using Mermaid for rendering
import inspect
def class_name(cls):
"""Return a string representing the class"""
# NOTE: can be changed to str(class) for more complete class info
return cls.__name__
def classes_tree(module, base_module=None):
if base_module is None:
base_module == module.__name__
@Zulko
Zulko / nx_merge_nodes.py
Last active June 9, 2023 03:23
This is a function to merge several nodes into one in a Networkx graph
# This is a function to merge several nodes into one in a Networkx graph
def merge_nodes(G,nodes, new_node, attr_dict=None, **attr):
"""
Merges the selected `nodes` of the graph G into one `new_node`,
meaning that all the edges that pointed to or from one of these
`nodes` will point to or from the `new_node`.
attr_dict and **attr are defined as in `G.add_node`.
"""
@Zulko
Zulko / rapunzel_moviepy.py
Last active May 1, 2023 21:22
Tangled + MoviePy
"""
This creates the following GIF, where the text appears to be "embedded"
in the video and "disappears" behind rapunzel.
http://i.imgur.com/gxEHfLX.gif
"""
from moviepy.editor import *
import numpy as np
import skimage.morphology as skm
@Zulko
Zulko / makegifs.py
Last active December 27, 2022 18:16 — forked from luser/makegifs.py
Just indications on what you could do, @luser
#!/usr/bin/env python
# Taken from http://zulko.github.io/blog/2015/02/01/extracting-perfectly-looping-gifs-from-videos-with-python-and-moviepy/
import os
import sys
import moviepy.editor as mp
from moviepy.video.tools.cuts import FramesMatches
if len(sys.argv) != 2:
@Zulko
Zulko / moviepy_motion_blur.py
Last active December 10, 2022 07:03
Motion blur in MoviePy.
import numpy as np
def supersample(clip, d, nframes):
""" Replaces each frame at time t by the mean of `nframes` equally spaced frames
taken in the interval [t-d, t+d]. This results in motion blur."""
def fl(gf, t):
tt = np.linspace(t-d, t+d, nframes)
avg = np.mean(1.0*np.array([gf(t_) for t_ in tt]),axis=0)
return avg.astype("uint8")
return clip.fl(fl)
from moviepy.editor import *
from moviepy import *
video = VideoFileClip(r"[MYFILE]").subclip(50,60)
# Make the text. Many more options are available.
txt_clip = ( TextClip("My Holidays 2013",fontsize=70,color='white')
.set_position('center')
.set_duration(10) )