red and white square illustration

Video Renamer

This script allows you to rename and edit metadata in .mp4 video files, in bulk.


Optimising videos for ranking for specific keywords on YouTube requires various elements to be configured for best effect. The video file name should include the keyword, as well as the file meta data. If you’re creating videos in bulk, this can be a time-consuming task. But this script takes the pain away!


You will need to install the “moviepy” and “mutagen” libraries.

pip install moviepy
pip install mutagen

How to use it

  1. Save the script below in the folder of your choice.
  2. Create a new folder called “Videos”, and save all the videos that you want to optimise there.
  3. Open the script in Notepad++, and replace the “INSERT YOUR KEYWORD HERE” sections with your own keyword(s). You can optionally add additional tags in the tags section (TAG1, TAG2 etc, separated by commas).
  4. Run your script – your videos will be replaced by the modified videos.
import os
from moviepy.editor import VideoFileClip
from mutagen.mp4 import MP4

# Specify the folder where your mp4 videos are located
folder_path = "Videos"

# Specify the keyword you want to add to the video names

# Get a list of all files in the folder
files = os.listdir(folder_path)

# Loop through the files, edit metadata, and rename them
for i, file_name in enumerate(files):
    if file_name.endswith(".mp4"):
        # Generate the new file name with the keyword and index
        new_file_name = f"{keyword}-{i + 1}.mp4"

        # Construct the full paths to the old and new files
        old_file_path = os.path.join(folder_path, file_name)
        new_file_path = os.path.join(folder_path, new_file_name)

        # Edit metadata
        clip = VideoFileClip(old_file_path)

        # Create a temporary file with the edited video
        temp_file_path = os.path.join(folder_path, f"temp_{i + 1}.mp4")
        clip.write_videofile(temp_file_path, audio=True)

        # Set metadata using mutagen
        mp4 = MP4(temp_file_path)
        mp4['\xa9nam'] = "INSERT YOUR KEYWORD HERE"  # Title
        mp4['\xa9alb'] = "INSERT YOUR KEYWORD HERE"  # Subtitle
        mp4['\xa9gen'] = "INSERT YOUR KEYWORD HERE,TAG1, TAG2, TAG3"  # Tags
        mp4['\xa9cmt'] = "INSERT YOUR KEYWORD HERE"  # Comments

        # Remove the old file

        # Rename the temporary file to the new name
        os.rename(temp_file_path, new_file_path)

        print(f"Edited and Renamed: {file_name} -> {new_file_name}")

Youtube icon

Top And Tail Video Creator

This program concatenates videos together, adding topvideo.mp4 at the start of any video, and tailvideo.mp4 at the end. It does this in bulk for any number of videos.


This is great for branding your videos with an opening (“top”) and closing (“tail”) sequence.


Create your opening and closing videos, and name them “topvideo.mp4” and “tailvideo.mp4”.
Now save the videos you want to brand in a folder named “Videos”. Your branded videos will be created and saved in a new folder called “Completed Videos”

You will need to install the “moviepy” library.

pip install moviepy

How to use it

  1. Save the script below in the folder of your choice
  2. Create a new folder called “Videos”, and save all the videos that you want branding with a top and tail video.
  3. Make sure you have the topvideo.mp4 and tailvideo.mp4 saved in the main folder
  4. Run your script – your new videso will be found in the “Completed Videos” folder.
import os
from moviepy.editor import VideoFileClip, concatenate_videoclips

# Define the input folder for videos and the top and tail videos
videos_folder = "Videos"
top_video_path = "topvideo.mp4"
tail_video_path = "tailvideo.mp4"

# Create the output folder if it doesn't exist
output_folder = "Completed Videos"
os.makedirs(output_folder, exist_ok=True)

# Function to get video codec and resolution
def get_video_info(file_path):
    video = VideoFileClip(file_path)
    codec = video.fps
    resolution = video.size
    return codec, resolution

# Get the codec and resolution of the first video in the folder
first_video_path = os.path.join(videos_folder, os.listdir(videos_folder)[0])
first_video_codec, first_video_resolution = get_video_info(first_video_path)

# Load the top video and tail video
top_video = VideoFileClip(top_video_path)
tail_video = VideoFileClip(tail_video_path)

# Check if the top video codec and resolution match the first video
if top_video.fps != first_video_codec or top_video.size != first_video_resolution:
    # If not, convert the top video to match
    top_video = top_video.set_fps(first_video_codec).resize(first_video_resolution)

# Check if the tail video codec and resolution match the first video
if tail_video.fps != first_video_codec or tail_video.size != first_video_resolution:
    # If not, convert the tail video to match
    tail_video = tail_video.set_fps(first_video_codec).resize(first_video_resolution)

# List to store concatenated videos
concatenated_videos = []

# Loop through all files in the input folder
for filename in os.listdir(videos_folder):
    if filename.endswith(".mp4"):
        # Load the current video
        video_path = os.path.join(videos_folder, filename)
        video = VideoFileClip(video_path)

        # Concatenate the top video, current video, and tail video
        concatenated_video = concatenate_videoclips([top_video, video, tail_video])

        # Set the output filename
        output_filename = os.path.splitext(filename)[0] + "-edited.mp4"
        output_path = os.path.join(output_folder, output_filename)

        # Write the concatenated video to the output folder
        concatenated_video.write_videofile(output_path, codec="libx264", fps=video.fps)

        # Close the video objects

# Close the top and tail video objects

Remember to ensure that the top and tail videos match the format of the videos you are branding.