Simplified FFmpeg Filter Complex: Splitting Source with Multiple Overlays
In this article, we will discuss a simplified approach to creating complex FFmpeg filter_complex scenarios. Specifically, we will focus on splitting a single overlay source into multiple uniquely shaped cropped slices (s1, s2, etc.) to overlay on a padded background plate.
Background
FFmpeg is a powerful, open-source multimedia framework that can handle various video and audio manipulation tasks. It provides a wide range of filters and filtering options through the filter_complex feature. With filter_complex, you can chain multiple filters together, making it possible to create complex video processing scenarios.
The Challenge
The challenge is to split a single 1372x1372 input source into multiple cropped slices (s1, s2, etc.) and overlay them on a padded background plate. This can be a daunting task for beginners, but FFmpeg provides a simple and efficient way to achieve this.
The Solution
To split the input source into multiple cropped slices, we can use the split filter. This filter duplicates the input stream into multiple identical output streams. We can then use the crop filter to crop each output stream into the desired shape. Here's an example:
ffmpeg -i input.mp4 -filter_complex "
[0:v]split=4[s1][s2][s3][s4];
[s1]crop=700:700:300:300[s1crop];
[s2]crop=700:700:0:0[s2crop];
[s3]crop=700:700:0:600[s3]crop;
[s4]crop=700:700:600:600[s4crop];
[s1crop][s2crop][s3crop][s4crop]overlay=shortest=1[out]
" -map "[out]" output.mp4
In this example, we first split the input source into four identical streams. We then crop each stream into the desired shape using the crop filter. Finally, we overlay the cropped slices on top of each other to create the final output.
Padded Background Plate
To add the padded background plate, we can use the color filter to crop a solid color to the desired size and then overlay it on top of the cropped slices. Here's an example:
ffmpeg -i input.mp4 -filter_complex "
[0:v]split=4[s1][s2][s3][s4];
[0:v]color=c=black:s=1372x1372:d=1[bg];
[s1]crop=700:700:300:300[s1crop];
[s2]crop=700:700:0:0[s2crop];
[s3]crop=700:700:0:600[s3]crop;
[s4]crop=700:700:600:600[s4crop];
[bg][s1crop][s2crop][s3crop][s4crop]overlay=shortest=1[out]
" -map "[out]" output.mp4
In this example, we first create a solid black background using the color filter. We then overlay the cropped slices on top of the background to create the final output.
- FFmpeg provides a powerful filter_complex feature that enables complex video processing scenarios.
- The
splitfilter duplicates the input stream into multiple identical output streams. - The
cropfilter crops each output stream into the desired shape. - The
colorfilter creates a solid color background. - The
overlayfilter overlays the cropped slices on top of the background to create the final output.