Automating Long Video Splitting into Short Clips Using Python

Jan 19, 2026
Python
Advertisement
Article Top Ad (728x90)
Automating Long Video Splitting into Short Clips Using Python

Overview

Welcome to the blog!

In today’s digital world, AI-powered automation has completely transformed the way content is created and managed. Many repetitive tasks that once required manual effort can now be handled automatically by setting up a proper automation workflow. Once the system is configured, the rest of the work runs smoothly with minimal human involvement.

However, most advanced automation tools available online are paid, and not everyone is able to afford these subscriptions. I personally faced this issue, which motivated me to start building my own local automation solutions using Python. Python is open-source, beginner-friendly, and extremely powerful—making it a perfect choice for automation projects.

Why Video Automation Matters Today

Short-form video content dominates platforms like Instagram Reels, Facebook Reels, and YouTube Shorts. You may have seen many pages that upload short anime, cartoon, or funny clips and still manage to gain thousands or even millions of followers. The secret lies in consistency and automation.

Manually cutting long videos into short clips is time-consuming. This is where Python-based video automation becomes extremely useful.

What This Automation Does

In this project, we create a simple automation system that:
  • Takes one long video

  • Automatically splits it into equal-length parts

  • Saves each part as a separate video file
  • Makes the clips ready for social media upload

This is especially useful if you want to repurpose long videos into short, engaging content without using expensive tools.

Project Structure and Version-Based Approach

This automation project is designed using a version-based development approach:

  • Version 1: Basic automation to split a video into multiple parts

  • Future versions: Advanced features will be added based on real-world needs

Each version will be clean, beginner-friendly, and well-structured. The complete source code will be provided below and will also be available on GitHub, where updates will be managed version by version—from beginner to advanced level.

How to Get Started

To begin, create a Python file on your system named:
video-cutting.py

After creating the file, copy and paste the code below into it.
This code handles the core logic of splitting a long video into smaller clips automatically.


Python Code: Automatic Video Splitting Logic

import os
from moviepy.video.io.VideoFileClip import VideoFileClip

# =========================
# SETTINGS
# =========================
input_video ="anime.mp4"   # path of video
part_duration =20         # seconds
output_folder ="video_parts"
# =========================

os.makedirs(output_folder, exist_ok=True)

video = VideoFileClip(input_video)
video_duration =int(video.duration)

part_number =1

for start inrange(0, video_duration, part_duration):
    end =min(start + part_duration, video_duration)

    part = video.subclipped(start, end)

    output_path = os.path.join(output_folder, f"{part_number}.mp4")

    part.write_videofile(
        output_path,
        codec="libx264",
        audio_codec="aac"
    )

    print(f"✅ Part {part_number} created")
    part_number +=1

video.close()
print("🎉 All video parts successfully created!")

Code Setup and Working Explanation

Before understanding how the Python code works internally, it is important to properly set up the environment. The following steps explain how to prepare the system and run the script successfully.

Step 1: Install Python

First, make sure Python is installed on your system.
  • Python version 3.10 or higher is recommended

  • You can verify the installation by running:
python --version
If Python is not installed, download it from the official Python website and complete the installation.

Step 2: Install MoviePy Library

This script uses the MoviePy library to handle video processing. Install MoviePy using pip:
pip install moviepy
Once installed, MoviePy provides all the tools needed to load, cut, and export video files.

Step 3: Prepare the Project Folder

Create a new folder for the project and place the following files inside it:
  • The Python script file (for example: video-cutting.py)

  • The video file you want to split (for example: anime.mp4)

Keeping both files in the same folder makes the setup simple and avoids path-related issues.

Step 4: Configure the Script Settings

At the top of the script, you will find a settings section.
This is where users can customize the behavior of the code.

  • Set the input_video variable to the video file name or path

  • Set the part_duration value to define how long each video part should be (in seconds)

  • Set the output_folder name where all video parts will be saved

These settings allow users to control the output without modifying the main logic.

Step 5: Run the Script

Open a terminal or command prompt inside the project folder and run:
python video-cutting.py
As the script runs, it will start cutting the video and saving each part in the output folder.

How the Code Works Internally

The script begins by importing the required modules for file handling and video processing.
It then creates the output folder if it does not already exist, ensuring that the generated video parts are stored in an organized way.

Next, the video file is loaded, and its total duration is calculated. A loop moves through the video timeline in fixed time intervals defined by the user.

During each loop iteration, a small portion of the video is extracted using MoviePy’s subclipped() method. This extracted clip is saved as an MP4 file using standard video and audio codecs for compatibility.

The script continues this process until the entire video has been processed. Finally, the video file is closed properly, and a success message is displayed.

Watch the Complete Setup and Usage Video Tutorial

To help users understand this Python video splitting script more clearly, we have created a simple step-by-step video tutorial. In this video, we explain:
  • How to set up Python on your system
  • How to install the MoviePy library
  • How to configure the script settings
  • How to run the video splitting code
  • How the code works internally
This video is beginner-friendly and designed to make the setup and usage process easy to follow.
 


Get the Source Code Using Git Clone

You can directly get the complete source code using Git. This is the recommended way, as it allows you to quickly copy the project to your system and receive future updates easily. Run the following command in your terminal or command prompt:
git clone https://github.com/bavliyavanraj/Video-Cutting-Script.git
Once the cloning process is complete, you will have the full project on your system and can start using or modifying the code immediately.

View the Code Directly on GitHub

If you prefer to explore the code online before downloading it, you can view the complete project directly on GitHub. Visit the repository using the link below to:
  • Read the source code online
  • Understand the project structure
  • Check updates or improvements
  • Download the code as a ZIP file

GitHub Repository:

=> https://github.com/bavliyavanraj/Video-Cutting-Script

Version-Based Folder Structure

We use a version-based folder system to manage improvements and updates in a clean and professional way. Each major improvement or update is placed in a new folder instead of modifying the old one. This ensures stability and transparency for users.

Example Folder Structure

V1/
│── video-cutting.py
│── README.md
V2/
│── (Improved version of the script)
│── README.md

How Versioning Works in This Project

  • V1 represents the initial stable version of the project

  • V2 will contain the next improved version of the code

  • Future updates will be added as V3, V4, and so on

Every version folder includes:
  • The complete Python script for that version
  • A matching README file explaining that specific version
This method allows users to:
  • Use a stable version without breaking changes
  • Compare improvements between versions
  • Learn how the project evolves over time

Why We Use This Versioning Approach

By creating a new folder for each improvement, we ensure:
  • Better code stability
  • Clear project history
  • Easy rollback to older versions
  • Beginner-friendly learning experience
Users can confidently choose the version that best fits their needs.

Continuous Improvements on GitHub

This project is actively maintained. As we improve performance, add features, or simplify the code, new version folders will be added to the GitHub repository. Users are encouraged to check the repository regularly for updates and improvements.

Final Notes

This tutorial, along with the video explanation and GitHub source code, is created to make video splitting with Python as simple as possible. Whether you are a beginner or already familiar with Python, this setup allows you to start working with the code quickly and confidently.

What Should We Write About Next?

We regularly publish beginner-friendly tutorials on Python, automation, and practical programming solutions.

If you have any suggestions for the next blog topic, please share them in the comment section below.
Your ideas help us create content that is more useful and relevant for you.

Sponsored Content
In-Content Ad (300x250)
Python Blog Verified
Written by

Admin

IoT Expert
Verified Author
Advertisement
Ad Banner
(300x250)
Advertisement
Ad Banner (728x90)

User Reviews & Comments

Share your experience with this Blog. Your feedback helps our community make informed decisions!

0 reviews

Share Your Experience

Help others by sharing your thoughts about this Blog.

0/1000 characters

No Reviews Yet

Be the first to share your experience with this Blog!

Related Blogs

Explore more Blogs in the same language

No Related Blogs

Check out other languages for more blogs.

Advertisement
Ad Banner (728x90)
Advertisement
Footer Ad (728x90)