3

Having an issue with an hstack FFmpeg command that has stumped me.

input1 and input2 are both vertical 360x640 videos. I am cropping input1 to a square, merging it vertically with input2, then cropping a vertical strip off each side of the resulting video and horizontally merging these three videos (left strip, middle vertically-stacked video, right strip).

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex [0:v]crop=360:360:0:140,fps=30[v0],[1:v]fps=30[v1],[v0][v1]vstack=inputs=2[m],[m]crop=101:ih:0:0[l],[m]crop=101:ih:259:0[r],[l][m][r]hstack=inputs=3[v];[0:a][1:a]amix[a] -map [v] -map [a] -preset ultrafast ./stackedOutput.mp4

When I run this, I get an error:

[Parsed_hstack_6 @ 0x7ff5394482c0] Input 1 height 640 does not match input 0 height 1000. [Parsed_hstack_6 @ 0x7ff5394482c0] Failed to configure output pad on Parsed_hstack_6

(Full FFmpeg output here.)

But the height of [m] (Input 1 in hstack) is not 640, it's 1000. I have verified this when the commands are run independently.

Why is FFmpeg not recognizing the correct height of [m]? Any help or pointers greatly appreciated! Thanks in advance!

lach_codes
  • 45
  • 4

1 Answers1

3

Use:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "[0:v]crop=360:360:0:140,fps=30[v0];[1:v]fps=30[v1];[v0][v1]vstack=inputs=2,split=3[lc][m][rc];[lc]crop=101:ih:0:0[l];[rc]crop=101:ih:259:0[r];[l][m][r]hstack=inputs=3[v];[0:a][1:a]amix[a]" -map "[v]" -map "[a]" -preset ultrafast ./stackedOutput.mp4

Two problems:

  1. Your syntax is incorrect. Filters in the same linear chain are separated by commas, and distinct linear chains of filters are separated by semicolons. See filtering introduction.

  2. You can't re-use the output from a filter multiple times. In your command [m] was already consumed by the first crop, so it is no longer available for the following crop and hstack. The split filter can be used to make multiple copies of a filter output.

llogan
  • 121,796
  • 28
  • 232
  • 243
  • Awesome, thank you so much! I never knew about the "split" option, and appreciate the clarification about commas vs. semicolons. – lach_codes Mar 23 '21 at 12:24