Automate Video Editing with Python
Automate the editing of explainer videos to create shorts with text-to-speech comments for the training of warehouse operators.
Looking for a way to automate your training videos and make them more engaging for your warehouse operators?
I have 100 videos to prepare with simple editing. How can I use Python to automate the process?
In this article, we’ll show you how to use the Python library Moviepy to edit explainer videos.
This tool can automatically cut them into short clips, remove background music and add text-to-speech comments.
💌 New articles straight in your inbox for free: Newsletter
📘 Boost your Productivity with Data Analytics: Productivity Cheat Sheet
Scenario
You are an operational manager in the logistics department of an international fashion retailer.
In order to support the onboarding of new operators and administrative staff you would like to prepare training videos.
Your colleague has shared with you an explainer video (video by the author) introducing all the processes of warehouse receiving.
To animate your sessions, you want to cut this video into short clips explaining each of the processes.
I. How to edit videos with Python?
1. Training Material
In this video, you have a complete presentation of several processes involved in the reception of products in a Warehouse.
Therefore, you would like to use this video that is listing the different processes as training support for your onboarding sessions:
- Total Duration: 00:03:18
- 18 sections including the intro and outro
- Background music but no background voice
2. Objective
You want to cut the video, remove the background music and create shorts with audio comments.
The idea is to build an automated workflow using Python that will
- Load the original video
- Remove the background music
- Cut the video into several shots that focus on different processes
- Add audio comments generated with a Text-to-speech solution
3. Solution to Automate Video Editing with Python
To automate the editing of explainer videos and create shorts with text-to-speech comments for training purposes, we recommend using the Python library Moviepy.
In the next sections, we will explore a three-step workflow that involves loading the original video, removing the background music, cutting the video into several shots, and adding audio comments generated with a Text-to-speech solution.
For more details on the Moviepy library, please refer to the official documentation.
If you want also to automate graphic design, there is another tutorial for you
II. Implementation
1. Step 1: Loading the video
We start by loading the .mp4 file of the original video that you can find on my YouTube channel (Link).
2. Step 2: Cut the video
As you want to focus on some specific processes, you will not use the entire video.
Therefore, we need to find a method to cut the video at specific times to generate short clips that will be used to show a specific process.
Function: Convert to seconds
💡 Insights
We’ll need this function later when we’ll start to cut the video.
Action: Cut the video
📹 Result
💡 Insights
You have a short video clip with the background music cut from the original video at the right timestamps.
3. Step 3: Remove the sound
You would like to play videos without sound, so you want to take your shorts and remove the sound.
📹 Result
💡 Insights
You can also apply a fraction of the volume using .volumex(fraction) that can be lower than 1(reduction) or higher than 1 (increase)
4. Step 4: Combine two shorts
You have cut two videos and you would like to play them successively? There is a Moviepy function for this,
📹 Result
5. Step 5: Stack the videos
You would like to show several processes simultaneously? You can stack the videos on the same screen.
📹 Result
6. Step 6: Add some lag
It can be done if you want to stack the videos but with a lag of 5 seconds between each video. (I have no idea why someone would do that, but why not!)
📹 Result
7. Final Step: Add Text-To-Speech Comments
We have generated comments using a Text-to-speech API. Can we add them to the video?
The answer is yes!
📹 Result
💡 Insights
Google TTS (free tier) is very bad! Do you know a better one at a reasonable price?
💡 Follow me on Medium for more articles related to 🏭 Supply Chain Analytics, 🌳 Sustainability and 🕜 Productivity.
III. Conclusion
Automating video editing with Python can be a powerful tool for creating training materials and explainer videos.
With Moviepy, you can easily cut, combine, and add text-to-speech comments to your videos, all with just a few lines of code.
And while it may not have all the bells and whistles of professional editing software, it gets the job done and saves you time and effort.
So why not give it a try and see how it can streamline your video production process?
Moreover, I have shared with you only a fraction of what the library can do. I strongly suggest having a look at the documentation for more insights.
You are ready to design training materials or start your fully automated Tiktok Channel.
Discover another Python library to automate the design of miniatures, illustrations or any graphic work in this article
About Me
Let’s connect on Linkedin and Twitter, I am a Supply Chain Engineer using data analytics to improve logistics operations and reduce costs.
If you are interested in Data Analytics and Supply Chain, have a look at my website
I am sharing other video tutorials on automating manual tasks like PowerPoint, Graphic Design or Business Planning in a dedicated YouTube channel,
💡 Follow me on Medium for more articles related to 🏭 Supply Chain Analytics, 🌳 Sustainability and 🕜 Productivity.