1

How do I use ffmpeg to concatenate 5 videos side by side? And could someone also kindly explain the command please. I only know how to write python and have an extremely hard time trying to understand the more complicated ffmpeg commands. For example, this script below concats the videos from left to right and top to bottom but how do I read the command?

ffmpeg -i input0 -i input1 -i input2 -i input3 -filter_complex \
"[0:v][1:v]hstack[top]; \
 [2:v][3:v]hstack[bottom]; \
 [top][bottom]vstack,format=yuv420p[v]; \
 [0:a][1:a][2:a][3:a]amerge=inputs=4[a]" \
-map "[v]" -map "[a]" -ac 2 output.mp4

does [0:v] mean the 0th row to v-1'th row?

what variables are the hstack command applied to for the line [0:v][1:v]hstack[top]? Why is it not hstack(input0,input1)?

1 Answer 1

3

5 videos side-by-side

ffmpeg -i input0 -i input1 -i input2 -i input3 -i input4 -filter_complex \
"[0:v][1:v][2:v][3:v][4:v]hstack=inputs=5[v]
 [0:a][1:a][2:a][3:a][4:a]amix=inputs=5[a]" \
-map "[v]" -map "[a]" output.mp4

Questions

does [0:v] mean the 0th row to v-1'th row?

  • [0:v] refers to [input0:video]. [3:a] refers to [input3:audio]. This is how you tell a filter which input and stream types you want to use as an input. The order of inputs given to hstack dictates the order that they are arranged.
  • [v] is the arbitrary name given to the output from the hstack filter. You can choose almost any name. Same for [a].
  • -map "[v]" instructs ffmpeg to put the output from the hstack filter ([v]) into output.mp4.

what variables are the hstack command applied to for the line [0:v][1:v]hstack[top]?

Two inputs ([0:v][1:v]), the filter name (hstack), and an output label ([top]).

Why is it not hstack(input0,input1)?

Why would it be? The current syntax [input0][input1]filer=option0=value0:option1=value1[output] makes more sense to me.

3
  • Thanks, could you kindly let me know how and where you found out what [0:v] stands for? The documentation for hstack at ffmpeg.org/ffmpeg-filters.html does provide any useful description about hstack. And that is the biggest problem I face. How do I understand ffmpeg if the documentation is so short
    – Kong
    Jul 29, 2020 at 5:20
  • 1
    @Kong It's a stream specifier, but yes, it should be described better in the filters page. The filtering introduction is not as helpful as it could be.
    – llogan
    Aug 1, 2020 at 19:28
  • @Ilogan Thank you. I have spent quite a bit of time reading through the docs and googling the description for some of its syntaxes and I am understanding it a lot better now.
    – Kong
    Aug 1, 2020 at 19:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .