Creating a video editing tool in python (part 1 of many)

paulplanchon_ profile image PaulPlanchon ・4 min read

In advance sorry for my bad writting skill, I'm french and still learning shakespeare's language

The software I will introduce you to is still in active development, its cannot be used properly. I'm still developping it. I just want to share to you my idea

I have always been a video lover : watch them, enjoy them, create them... I'm also a curiosity driven person. So when, a few month back, I challenge myself to create a video editing software in Python, two of my universes collided.

This challenge is driven by the curiosity of discovering a new way of using code to create things. But it was also a way to help me understand how 3blue1brown's manim software work. In fact, I always been fasinated by 3B1B work. I think is pure and elegant, and when I knew that all the video are created in python I lost my mind. So I spend some time trying understand the software. And started writing my own rendering software adding to it my own ideas.

My software is inspired by 3B1B software, I tried to make the software closer to "real software" like premiere pro. Manim just follow the flow of the code to render. But i tried to implement a timeline based rendering system.

The rendering software

The main idea of VidTex (the name of the software I'm creating video+LaTeX / video+technologie) is that the user write the movie and then VidTex do the render, nothing is real-time. To use the software you have to create a folder containning at least one file movie_main.py. This file contains all the scene the movie is composed of. A scene is composed of animations.

When you start the render, VidTex open the file movie_main.py and extract the movie scene (using importlib). The user had written all the movie in a function called prepare. In this function the user call for all the scene the movie use and tell VidTex when they have to be render in the movie. For example, the following code tell VidTex that the movie has only one scene that last for 60 frames (the frame-rate is set in a configuration file).

def prepare(self):
    self.add_to_timeline(FirstScene, 0, 60, dtype="frames")

The FirstScene object is a Scene, as the movie, you have to prepare the scene : instead of adding scene to the timeline you add animations. So a prepare function of a scene would look like that :

def prepare(self):
    self.add_to_timeline(Animation1(anim_args**), 0, 60, z-index=-2)
    self.add_to_timeline(Animation2(anim_args**), 10, 55)
    self.add_to_timeline(Animation3(anim_args**), 2, 30, z-index=1)

When you trigger the render process, VidTex will look for the Movie class and try to render the first frame (sorted by start time, if no scene at t, frame t is black).

Understanding the timeline based render

When VidTex start the render process, it will call the timeline and ask for all the scene which need to be shown at frame t. Kinda recursivly, all the scene called will do their render at frame scene["start_time"] - t. Each animation has a buffer, all the animation buffer are added to create the scene frame buffer, which is at the end added to the main frame buffer to create the frame. Adding to the buffer is ruled by the z-index of the scene / animation (the bigger the z-index the closer you are).

This is how should should understand how the movie scene and animation structure work.

The time line is similear to a "normal" video editing program. There is a representation :

So at the time the cursor is at, the farest animation is animation 2 from scene 1. If there is a non transparent animation, for exemple in scene 3, animation 2 from scene 1 will not been shown. VidTex's timeline works the same as premier pro, after effect's timeline. You just have to write it in code.

Why VidTex ?

As I said earlier, its a way for me to collide two of my passions. But its also a tool programers need. You want to be able to create movie of your simulation for example. The fact that an animation is isolate from the rest of the movie means that you could run physics simulation in an animation and render it with VidTex. But will rendering the physic simulation you could add a text overlay, or explain using an other video whats going on. Nobodies want to deal with FFMPEG pipeline all the time to create simple videos.

For the futur

For the moment VidTex can only do render of very basic animation (called primitive). I'm still working on the code a lot. But the idea is to have some basic animation and a animation manager from which you could be able to download animation from the web and add them to your movie.

I will try to keep you updated about VidTex, if you are interested by reading the buggy and not very clean code of VidTex you can here.

Posted on by:

paulplanchon_ profile



student in mathematics and CS in France. loving IA and art in programming. trying to do cool stuff.


markdown guide