2

I have two videos that are different widths. I want to stack one on top of the other, retaining their respective aspect ratios. The top video is 1920x1080, and the bottom video is 3240x1080. I've tried:

ffmpeg -i video1.mp4 -i video2.mp4 -filter_complex '[1][0]scale2ref[2nd][ref];[ref][2nd]vstack' -map [vid] -c:v libx264 -crf 23 -preset veryfast output.mp4

But I get: "Output with label 'vid' does not exist in any defined filter graph, or was already used elsewhere." Not sure what I'm doing wrong here...

1 Answer 1

3

Use

ffmpeg -i video1.mp4 -i video2.mp4 -filter_complex '[1][0]scale2ref=iw:ow/mdar[2nd][ref];[ref][2nd]vstack[vid]' -map [vid] -c:v libx264 -crf 23 -preset veryfast output.mp4

The vstack output pad hasn't been labelled, so the map won't refer to anything. Depending on your shell, you may need to quote the map value.

4
  • That indeed doesn't throw the error (thanks!), but the output has scaled the bottom video so that the height is stretched to match the top video. I'd like the bottom video to be the same aspect ratio it started with. Is there a simple modification to get that to work?
    – pts2
    Commented Jun 22, 2018 at 17:46
  • Use edited cmd with a recent version of ffmpeg
    – Gyan
    Commented Jun 22, 2018 at 17:51
  • In case it helps anyone in the future, I also wanted to add the audio from the top video (video1.mp4) and put it in the combined output.mp4 (the bottom video video2.mp4 has no audio). This code worked to do all of this: ffmpeg -i video1.mp4 -i video2.mp4 -filter_complex '[1][0]scale2ref=iw:ow/mdar[2nd][ref];[ref][2nd]vstack[vid];anullsrc[silent];[0:a][silent]amerge=inputs=2[a]' -map [vid] -map [a] -c:v libx264 -crf 23 -preset veryfast output.mp4
    – pts2
    Commented Jun 22, 2018 at 18:02
  • You can skip the audio filters and just do -map 0:a
    – Gyan
    Commented Jun 22, 2018 at 18:07

You must log in to answer this question.

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