Search code examples
videoffmpegvideo-streamingvideo-processing

how to change ffmpeg xstack background color


I creating a 2x2 grid of videos but only had 3 videos. So I created an xstack of these 3 videos. The bottom right corner does not get a video. This causes it to be left to FFmpeg default colour.

Here is the command I use to create the video mosaic:

ffmpeg -i TEST.mkv -i TEST.mkv -i TEST.mkv -filter_complex "
[0:v] scale=960x540 [a0];
[1:v] scale=960x540 [a1];
[2:v] scale=960x540 [a2];
[a0][a1][a2] xstack=inputs=3:layout=0_0|0_h0|w0_0[out]"
 -map "[out]" -f matroska - | ffplay -

enter image description here

How can I make the green corner black or any other colour?

I'm using FFmpeg version 4.4


Solution

  • Add the fill option:

    ffmpeg -i TEST.mkv -i TEST.mkv -i TEST.mkv -filter_complex "
    [0:v] scale=960x540 [a0];
    [1:v] scale=960x540 [a1];
    [2:v] scale=960x540 [a2];
    [a0][a1][a2] xstack=inputs=3:layout=0_0|0_h0|w0_0:fill=black[out]"
     -map "[out]" -f matroska - | ffplay -
    

    See xstack filter documentation.