Concatenate Videos with Different Pixel Formats in FFmpeg

Concatenating videos with different pixel formats in FFmpeg often leads to errors or playback issues because the output stream requires a unified format. This guide provides a straightforward FFmpeg command and explanation to reformat and merge your videos seamlessly using the complex filtergraph.

The Solution: FFmpeg Filter_Complex Command

When video files have different pixel formats (such as yuv422p and yuv420p), you cannot use the fast “concat demuxer” without re-encoding. Instead, you must use the filter_complex option to convert the pixel formats to a common standard (usually yuv420p for maximum compatibility) before merging them.

Use the following command to concatenate two videos with different pixel formats:

ffmpeg -i video1.mp4 -i video2.mp4 -filter_complex \
"[0:v]format=yuv420p[v0]; \
 [1:v]format=yuv420p[v1]; \
 [v0][0:a][v1][1:a]concat=n=2:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]" output.mp4

How the Command Works

Handling Different Resolutions (Optional)

If your videos also have different resolutions in addition to different pixel formats, you must scale them to match. You can chain the scale and format filters together inside the same command:

ffmpeg -i video1.mp4 -i video2.mp4 -filter_complex \
"[0:v]scale=1920:1080,format=yuv420p[v0]; \
 [1:v]scale=1920:1080,format=yuv420p[v1]; \
 [v0][0:a][v1][1:a]concat=n=2:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]" output.mp4

This ensures both videos are scaled to 1920x1080 and converted to the yuv420p pixel format before concatenation, preventing any rendering or playback errors.