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:
- creates a list of all the MP4 files in the current directory,
- feeds this list to
ffmpeg, which handles the task of concatenating the files.
Pre-requisites:
- Ensure you have
ffmpeginstalled on your machine. If not, download it from the official website. - Have your MP4 files ready and placed in a single directory.
Steps:
- Create Batch Script File:
- Create a new text document.
- Copy and paste the script below into the text document.
- Save the document with a
.cmdextension, 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
- Run the Script:
- Double click on
CombineMP4.batto 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.mp4in the same directory.
- Double click on
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 iffilelist.txtexists and deletes it to ensure a fresh start.- The
forloop – Iterates through all the MP4 files in the directory, writing each file name tofilelist.txt. ffmpegcommand – Usesffmpegto concatenate all the MP4 files listed infilelist.txtinto a new filecombined.mp4.del filelist.txt– Optionally, this command deletes the temporaryfilelist.txt.echo Process completed!andpause– These commands notify the user that the process is complete and waits for a key press to close the command prompt.