Combining Multiple MP4 Files Using a Simple Windows Batch Script

If you have multiple MP4 video files and you want to combine them into a single file without the fuss of a video editing software, a straightforward approach is to use a Windows batch script alongside ffmpeg, a powerful and flexible software for handling multimedia data.

This guide takes you through a straightforward script that automates the process of combining multiple MP4 files into one.

The script will:

  1. creates a list of all the MP4 files in the current directory,
  2. feeds this list to ffmpeg, which handles the task of concatenating the files.

Pre-requisites:

  • Ensure you have ffmpeg installed on your machine. If not, download it from the official website.
  • Have your MP4 files ready and placed in a single directory.

Steps:

  1. Create Batch Script File:
    • Create a new text document.
    • Copy and paste the script below into the text document.
    • Save the document with a .cmd extension, for example, CombineMP4.cmd
@echo off
:: Delete the filelist if it exists
if exist filelist.txt del filelist.txt

:: Loop through all the MP4 files in the directory and write to filelist.txt for %%i in (*.mp4) do echo file '%%i' >> filelist.txt

:: Run ffmpeg to concatenate the MP4 files ffmpeg -f concat -safe 0 -i filelist.txt -c copy combined.mp4

:: Optional: Remove the temporary filelist.txt del filelist.txt

echo Process completed! pause

  1. Run the Script:
    • Double click on CombineMP4.bat to run the script.
    • The script will now locate all the MP4 files in the current directory, create a list, combines the files, and optionally deletes the temporary list file.
    • Once the script is completed, a message “Process completed!” will be displayed, and you will find a new file named combined.mp4 in the same directory.

How the script works:

  • @echo off – This command prevents the echoing of commands in the command prompt.
  • if exist filelist.txt del filelist.txt – This checks if filelist.txt exists and deletes it to ensure a fresh start.
  • The for loop – Iterates through all the MP4 files in the directory, writing each file name to filelist.txt.
  • ffmpeg command – Uses ffmpeg to concatenate all the MP4 files listed in filelist.txt into a new file combined.mp4.
  • del filelist.txt – Optionally, this command deletes the temporary filelist.txt.
  • echo Process completed! and pause – These commands notify the user that the process is complete and waits for a key press to close the command prompt.