
It’s typical to merge several video clips into one, especially when making highlight reels, product presentations, or content for social platforms. While FFmpeg concat can make this happen in small workflows, the process can become complicated when handling various formats, audio tracks, and lengthy command sequences. If timing or encoding is even slightly off, it could result in desynchronization problems or failed output.
You can concatenate videos with FFmpeg using either a concat file or the concat filter, both of which require careful setup. As your library grows or your workflow speeds up, manual commands become harder to manage. Cloudinary offers a faster path by stitching clips together through simple programmable URLs and automated processing. This helps teams produce clean, consistent videos without handling each step by hand.
Table of Contents
- Method 1: Using FFmpeg Concat Demuxer (No Re-Encoding)
- Method 2: Using FFmpeg Concat Filter (With Re-Encoding)
- How to Concatenate MP4 Files Specifically
- Speed Up FFmpeg Concat Workflows with Cloudinary
Method 1: Using FFmpeg Concat Demuxer (No Re-Encoding)
If all your videos share the same format, codec, and frame rate, this is the best method to start with. FFmpeg’s concat demuxer reads a simple text file that tells it which clips to merge.
Create a List of Files
Open your text editor and make a file like this:
# files.txt file 'intro.mp4' file 'scene1.mp4' file 'scene2.mp4' file 'outro.mp4'
Save it as files.txt in the same folder as your videos, and FFmpeg will combine them in that order.
Run the Demuxer Command
Now, open your terminal and type this:
ffmpeg -f concat -safe 0 -i files.txt -c copy output.mp4
Once you run it, the merge happens in seconds. FFmpeg creates a new file called output.mp4 that keeps full quality.
Method 2: Using FFmpeg Concat Filter (With Re-Encoding)
Sometimes your videos don’t share the same format, codec, or frame rate. When that happens, the concat demuxer won’t work. Instead, we can use FFmpeg’s concat filter to join them together.
Understanding the Filtergraph Syntax
Filtergraphs in FFmpeg give you a structured way to describe how video and audio should be processed. They let you connect filters in sequence, pass outputs forward, and build complex edits through a single command. Instead of writing long scripts, you express the workflow as text that FFmpeg parses and runs.
A filterchain is the core unit. It is a comma-separated list of filters that run in order. A full filtergraph contains one or more filterchains separated by semicolons, which allows multiple processing paths in the same operation.
Here’s a quick view of how filtergraphs are built:
- A filterchain is a comma separated list of filters
- Multiple filterchains form a filtergraph
- Filters can include input labels, a name, arguments, and output labels
- Arguments can be key value pairs, ordered values, or a mix
This structure keeps even advanced processing tasks predictable and easier to maintain.
Run the Filter-Based Command
Let’s try an example. Open your terminal and type this:
ffmpeg -i intro.mp4 -i scene1.mp4 -i outro.mp4 -filter_complex "[0:v][0:a][1:v][1:a][2:v][2:a]concat=n=3:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" output.mp4
You can control the output quality using FFmpeg’s codec flags. For example, to use H.264 and keep quality high, try:
ffmpeg -i intro.mp4 -i scene1.mp4 -i outro.mp4 -filter_complex "[0:v][0:a][1:v][1:a][2:v][2:a]concat=n=3:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" -c:v libx264 -crf 18 -preset veryfast output.mp4
How to Concatenate MP4 Files Specifically
MP4 files are special. They store video metadata (“moov atoms”) differently from other formats, which can cause problems if you try to merge them like .ts or .mkv files. So, depending on how your MP4s are encoded, you’ll need one of two approaches.
Using Demuxer for MP4
If your MP4 files share the same codec, resolution, and frame rate, this method will save you so much time. The demuxer method works best when all your MP4s have the same resolution, frame rate, and encoding.
Let’s say you have three files: part1.mp4, part2.mp4, and part3.mp4. Create a list file just like before:
# files.txt file 'part1.mp4' file 'part2.mp4' file 'part3.mp4'
Then run this command:
ffmpeg -f concat -safe 0 -i files.txt -c copy output.mp4
That’s it! You’ll get one clean MP4 without losing any quality.
Using Filter for MP4
Now, if your MP4 files don’t match in format or encoding, you’ll need to use the concat filter method instead.
Here’s an example:
ffmpeg -i part1.mp4 -i part2.mp4 -i part3.mp4 -filter_complex "[0:v][0:a][1:v][1:a][2:v][2:a]concat=n=3:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" -c:v libx264 -c:a aa -crf 20 -preset fast output.mp4
This command re-encodes your videos so they match perfectly. It takes a little longer but works with every MP4 setup.
Speed Up FFmpeg Concat Workflows with Cloudinary
Concatenating videos with FFmpeg works well, but it becomes slow when you manage many clips, track formats, or run commands on limited hardware. Each step requires careful setup, and scaling the process often adds more complexity.
Cloudinary streamlines this by letting you stitch videos together through simple programmable URLs. It handles formatting, processing, and delivery in the cloud, which removes the need for manual scripts. With Cloudinary managing the heavy lifting, you can produce clean, consistent videos and deliver them quickly across all channels.
Preprocess Locally with FFmpeg
Before uploading, it’s a good idea to prepare your clips so everything goes smoothly.
Here’s what to check:
- Formats and codecs: Make sure each clip uses a supported format (like MP4 or WebM) and standard codecs.
- Trim or fix issues: Remove unwanted parts or fix small errors before uploading.
- Compress large files: Smaller uploads save time and bandwidth.
Example: Compress a clip with FFmpeg
ffmpeg -i scene1.mp4 -vcodec libx264 -crf 23 scene1_compressed.mp4
Once your clips are ready, upload them to Cloudinary. You don’t have to merge them locally; Cloudinary handles that part automatically.
Upload and Transform on Cloudinary
Want to see it in action?
Here’s an example that combines three clips (intro, scene1, and outro) using only a delivery URL:
https://res.cloudinary.com/<cloud_name>/video/upload/fl_splice,l_video:scene1/fl_splice,l_video:outro/intro.mp4
Just open this link in your browser and the video plays instantly.
Combine Videos with Node.js
You can generate the same merged video URL dynamically using Cloudinary’s Node.js SDK. Create a file (e.g., combine.js) and add:
import { v2 as cloudinary } from 'cloudinary';
import dotenv from 'dotenv';
dotenv.config();
// Configure Cloudinary with your credentials
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
secure: true
});
function combineVideos() {
// Generate a URL for the combined video
const url = cloudinary.url('intro.mp4', {
resource_type: 'video',
transformation: [
{ overlay: 'video:scene1', flags: 'splice' },// append scene1
{ overlay: 'video:outro', flags: 'splice' } // append outro
]
});
console.log('Combined video URL:', url);
}
combineVideos();
Then, run node combine.js in your terminal. Cloudinary will generate a ready-to-stream URL for your combined video.
Wrapping Up
FFmpeg is an amazing tool for combining videos. It gives you control and helps you understand how video processing really works. But when your projects get bigger, manually using FFmpeg concat can slow you down.
That’s where Cloudinary comes in. It takes everything you learned with FFmpeg and makes it faster and easier. You can upload your videos once, and Cloudinary can merge, optimize, and deliver them automatically.
Concatenate and deliver videos in multiple formats without hassle with Cloudinary. Sign up for Cloudinary and start streamlining your video pipelines today.
Frequently Asked Questions
Can I concatenate videos with different frame rates in FFmpeg?
Yes, you can, FFmpeg can merge videos with different frame rates if you use the concat filter. This method re-encodes your videos so everything plays smoothly together. If you want a faster way to handle mixed frame rates, Cloudinary can automatically adjust and process your videos when you upload them.
How do I concatenate videos with multiple audio streams in FFmpeg?
You can do it in FFmpeg by mapping each audio track correctly with the concat filter. It takes a little time to get the syntax right, but it works well once you practice. Cloudinary makes it simpler by letting you combine video and audio layers automatically with one API call.
Can I do this online instead of using FFmpeg?
Yes, and this is where Cloudinary is perfect. You can upload all your clips to Cloudinary and concat them directly in the cloud. It’s fast, scalable, and works with any format you upload.