Vertically or horizontally stack several videos using ffmpeg?











up vote
5
down vote

favorite
3












I have two videos of the same exact length, and I would like to use ffmpeg to stack them into one video file.



How can I do this?










share|improve this question




























    up vote
    5
    down vote

    favorite
    3












    I have two videos of the same exact length, and I would like to use ffmpeg to stack them into one video file.



    How can I do this?










    share|improve this question


























      up vote
      5
      down vote

      favorite
      3









      up vote
      5
      down vote

      favorite
      3






      3





      I have two videos of the same exact length, and I would like to use ffmpeg to stack them into one video file.



      How can I do this?










      share|improve this question















      I have two videos of the same exact length, and I would like to use ffmpeg to stack them into one video file.



      How can I do this?







      ffmpeg video-processing






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 4 at 19:30









      LordNeckbeard

      43.1k13101133




      43.1k13101133










      asked Jul 19 '12 at 0:59









      Joseph Turian

      4,778113354




      4,778113354
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          13
          down vote



          accepted










          See this answer to this question for a newer way to do this.





          Old version:

          You should be able to do this using the pad, movie and overlay filters in FFmpeg. The command will look something like this:



          ffmpeg -i top.mov -vf 'pad=iw:2*ih [top]; movie=bottom.mov [bottom]; 
          [top][bottom] overlay=0:main_h/2' stacked.mov


          First the movie that should be on top is padded to twice its height. Then the bottom movie is loaded. Then the bottom movie is overlaid on the padded top movie at an offset of half the padded movie's height.






          share|improve this answer






























            up vote
            32
            down vote













            Use the vstack (vertical), hstack (horizontal), or xstack (custom layout) filters. It is easier and faster than other methods.



            Example 1: Combine/stack two videos



            Vertical



            Using the vstack filter.



            enter image description here



            ffmpeg -i input0 -i input1 -filter_complex vstack=inputs=2 output


            Videos must have the same width.



            Horizontal



            Using the hstack filter.



            enter image description here



            ffmpeg -i input0 -i input1 -filter_complex hstack=inputs=2 output


            Videos must have the same height.





            Example 2: Same as above but with audio



            Combined audio from both inputs



            Add the amerge filter to combine the audio channels from both inputs:



            ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v];[0:a][1:a]amerge=inputs=2[a]" -map "[v]" -map "[a]" -ac 2 output




            • -ac 2 is included to downmix to stereo in case both inputs contain multi-channel audio. For example, if both inputs are stereo, you would get a 4-channel output audio stream instead of stereo if you omit -ac 2.


            Using audio from one particular input



            This example will use the audio from input1:



            ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v]" -map "[v]" -map 1:a output


            Adding silent audio / If one input does not have audio



            If you mix inputs that have audio and inputs that do not have audio then amerge will fail because each input needs audio. You can add silent audio with the anullsrc filter to prevent this:



            ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v];anullsrc[silent];[0:a][silent]amerge=inputs=2[a]" -map "[v]" -map "[a]" -ac 2 output.mp4




            Example 3: Three videos



            enter image description here



            ffmpeg -i input0 -i input1 -i input2 -filter_complex "[0:v][1:v][2:v]vstack=inputs=3[v]" -map "[v]" output




            Example 4: 2x2 grid



            enter image description here



            Using xstack



            ffmpeg -i input0 -i input1 -i input2 -i input3 -filter_complex "[0:v][1:v][2:v][3:v]xstack=inputs=4:layout=0_0|0_h0|w0_0|w0_h0[v]" -map "[v]" output


            Using hstack and vstack



            ffmpeg -i input0 -i input1 -i input2 -i input3 -filter_complex "[0:v][1:v]hstack=inputs=2[top];[2:v][3:v]hstack=inputs=2[bottom];[top][bottom]vstack=inputs=2[v]" -map "[v]" output


            This is less efficient than using xstack as shown above.





            Example 5: Resize/scale an input



            Since both videos need to have the same with for vstack, and the same height for hstack, you may need to scale one of the other videos to match the other:



            Simple scale filter example to set width of input0 to 640 and automatically set height while preserving the aspect ratio:



            ffmpeg -i input0 -i input2 -filter_complex "[0:v]scale=640:-1[v0];[v0][1:v]vstack=inputs=2" output



            • For a more advanced method to fit any size video into a specific size while preserving aspect ratio see Resizing videos with ffmpeg to fit into static sized player.


            • You can also use the scale2ref filter to automatically resize one video to match the dimensions of the other.







            share|improve this answer























            • ffmpeg reports No such filter: 'vstack'. Do I have to install it first?
              – frans
              Dec 12 '15 at 13:39










            • @frans You probably figured this out by now, but your ffmpeg is too old. Users are recommended to use a ffmpeg build derived from the current git master branch.
              – LordNeckbeard
              Dec 14 '15 at 1:36










            • Stream specifier ':a' in filtergraph description [0:v][1:v]vstack[v];[0:a][1:a]amerge=inputs=2[a] matches no streams. Why do I get this?
              – RaduM
              Jun 29 '17 at 9:02






            • 2




              @RaduM its because one of your video doesnt have audio in it , you need to add an audio or silent audio in it , try the same command using two videos with Audio , it will work , am posting because I had the same problem today and rectified it using silent audio addition.
              – Jeffin
              Jul 10 '17 at 7:24










            • @LordNeckbeard I used your Example 2 command for merging two videos. It did worked for me and I got an output with two videos merged along with their Audios mixed. What is the command if I add a third file, say an mp3 file, and merge 2 videos as before and merge 3 audios together.
              – Nasseh
              Jul 31 '17 at 7:59











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11552565%2fvertically-or-horizontally-stack-several-videos-using-ffmpeg%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            13
            down vote



            accepted










            See this answer to this question for a newer way to do this.





            Old version:

            You should be able to do this using the pad, movie and overlay filters in FFmpeg. The command will look something like this:



            ffmpeg -i top.mov -vf 'pad=iw:2*ih [top]; movie=bottom.mov [bottom]; 
            [top][bottom] overlay=0:main_h/2' stacked.mov


            First the movie that should be on top is padded to twice its height. Then the bottom movie is loaded. Then the bottom movie is overlaid on the padded top movie at an offset of half the padded movie's height.






            share|improve this answer



























              up vote
              13
              down vote



              accepted










              See this answer to this question for a newer way to do this.





              Old version:

              You should be able to do this using the pad, movie and overlay filters in FFmpeg. The command will look something like this:



              ffmpeg -i top.mov -vf 'pad=iw:2*ih [top]; movie=bottom.mov [bottom]; 
              [top][bottom] overlay=0:main_h/2' stacked.mov


              First the movie that should be on top is padded to twice its height. Then the bottom movie is loaded. Then the bottom movie is overlaid on the padded top movie at an offset of half the padded movie's height.






              share|improve this answer

























                up vote
                13
                down vote



                accepted







                up vote
                13
                down vote



                accepted






                See this answer to this question for a newer way to do this.





                Old version:

                You should be able to do this using the pad, movie and overlay filters in FFmpeg. The command will look something like this:



                ffmpeg -i top.mov -vf 'pad=iw:2*ih [top]; movie=bottom.mov [bottom]; 
                [top][bottom] overlay=0:main_h/2' stacked.mov


                First the movie that should be on top is padded to twice its height. Then the bottom movie is loaded. Then the bottom movie is overlaid on the padded top movie at an offset of half the padded movie's height.






                share|improve this answer














                See this answer to this question for a newer way to do this.





                Old version:

                You should be able to do this using the pad, movie and overlay filters in FFmpeg. The command will look something like this:



                ffmpeg -i top.mov -vf 'pad=iw:2*ih [top]; movie=bottom.mov [bottom]; 
                [top][bottom] overlay=0:main_h/2' stacked.mov


                First the movie that should be on top is padded to twice its height. Then the bottom movie is loaded. Then the bottom movie is overlaid on the padded top movie at an offset of half the padded movie's height.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited May 23 '17 at 12:10









                Community

                11




                11










                answered Jul 19 '12 at 2:32









                blahdiblah

                24.7k1681140




                24.7k1681140
























                    up vote
                    32
                    down vote













                    Use the vstack (vertical), hstack (horizontal), or xstack (custom layout) filters. It is easier and faster than other methods.



                    Example 1: Combine/stack two videos



                    Vertical



                    Using the vstack filter.



                    enter image description here



                    ffmpeg -i input0 -i input1 -filter_complex vstack=inputs=2 output


                    Videos must have the same width.



                    Horizontal



                    Using the hstack filter.



                    enter image description here



                    ffmpeg -i input0 -i input1 -filter_complex hstack=inputs=2 output


                    Videos must have the same height.





                    Example 2: Same as above but with audio



                    Combined audio from both inputs



                    Add the amerge filter to combine the audio channels from both inputs:



                    ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v];[0:a][1:a]amerge=inputs=2[a]" -map "[v]" -map "[a]" -ac 2 output




                    • -ac 2 is included to downmix to stereo in case both inputs contain multi-channel audio. For example, if both inputs are stereo, you would get a 4-channel output audio stream instead of stereo if you omit -ac 2.


                    Using audio from one particular input



                    This example will use the audio from input1:



                    ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v]" -map "[v]" -map 1:a output


                    Adding silent audio / If one input does not have audio



                    If you mix inputs that have audio and inputs that do not have audio then amerge will fail because each input needs audio. You can add silent audio with the anullsrc filter to prevent this:



                    ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v];anullsrc[silent];[0:a][silent]amerge=inputs=2[a]" -map "[v]" -map "[a]" -ac 2 output.mp4




                    Example 3: Three videos



                    enter image description here



                    ffmpeg -i input0 -i input1 -i input2 -filter_complex "[0:v][1:v][2:v]vstack=inputs=3[v]" -map "[v]" output




                    Example 4: 2x2 grid



                    enter image description here



                    Using xstack



                    ffmpeg -i input0 -i input1 -i input2 -i input3 -filter_complex "[0:v][1:v][2:v][3:v]xstack=inputs=4:layout=0_0|0_h0|w0_0|w0_h0[v]" -map "[v]" output


                    Using hstack and vstack



                    ffmpeg -i input0 -i input1 -i input2 -i input3 -filter_complex "[0:v][1:v]hstack=inputs=2[top];[2:v][3:v]hstack=inputs=2[bottom];[top][bottom]vstack=inputs=2[v]" -map "[v]" output


                    This is less efficient than using xstack as shown above.





                    Example 5: Resize/scale an input



                    Since both videos need to have the same with for vstack, and the same height for hstack, you may need to scale one of the other videos to match the other:



                    Simple scale filter example to set width of input0 to 640 and automatically set height while preserving the aspect ratio:



                    ffmpeg -i input0 -i input2 -filter_complex "[0:v]scale=640:-1[v0];[v0][1:v]vstack=inputs=2" output



                    • For a more advanced method to fit any size video into a specific size while preserving aspect ratio see Resizing videos with ffmpeg to fit into static sized player.


                    • You can also use the scale2ref filter to automatically resize one video to match the dimensions of the other.







                    share|improve this answer























                    • ffmpeg reports No such filter: 'vstack'. Do I have to install it first?
                      – frans
                      Dec 12 '15 at 13:39










                    • @frans You probably figured this out by now, but your ffmpeg is too old. Users are recommended to use a ffmpeg build derived from the current git master branch.
                      – LordNeckbeard
                      Dec 14 '15 at 1:36










                    • Stream specifier ':a' in filtergraph description [0:v][1:v]vstack[v];[0:a][1:a]amerge=inputs=2[a] matches no streams. Why do I get this?
                      – RaduM
                      Jun 29 '17 at 9:02






                    • 2




                      @RaduM its because one of your video doesnt have audio in it , you need to add an audio or silent audio in it , try the same command using two videos with Audio , it will work , am posting because I had the same problem today and rectified it using silent audio addition.
                      – Jeffin
                      Jul 10 '17 at 7:24










                    • @LordNeckbeard I used your Example 2 command for merging two videos. It did worked for me and I got an output with two videos merged along with their Audios mixed. What is the command if I add a third file, say an mp3 file, and merge 2 videos as before and merge 3 audios together.
                      – Nasseh
                      Jul 31 '17 at 7:59















                    up vote
                    32
                    down vote













                    Use the vstack (vertical), hstack (horizontal), or xstack (custom layout) filters. It is easier and faster than other methods.



                    Example 1: Combine/stack two videos



                    Vertical



                    Using the vstack filter.



                    enter image description here



                    ffmpeg -i input0 -i input1 -filter_complex vstack=inputs=2 output


                    Videos must have the same width.



                    Horizontal



                    Using the hstack filter.



                    enter image description here



                    ffmpeg -i input0 -i input1 -filter_complex hstack=inputs=2 output


                    Videos must have the same height.





                    Example 2: Same as above but with audio



                    Combined audio from both inputs



                    Add the amerge filter to combine the audio channels from both inputs:



                    ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v];[0:a][1:a]amerge=inputs=2[a]" -map "[v]" -map "[a]" -ac 2 output




                    • -ac 2 is included to downmix to stereo in case both inputs contain multi-channel audio. For example, if both inputs are stereo, you would get a 4-channel output audio stream instead of stereo if you omit -ac 2.


                    Using audio from one particular input



                    This example will use the audio from input1:



                    ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v]" -map "[v]" -map 1:a output


                    Adding silent audio / If one input does not have audio



                    If you mix inputs that have audio and inputs that do not have audio then amerge will fail because each input needs audio. You can add silent audio with the anullsrc filter to prevent this:



                    ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v];anullsrc[silent];[0:a][silent]amerge=inputs=2[a]" -map "[v]" -map "[a]" -ac 2 output.mp4




                    Example 3: Three videos



                    enter image description here



                    ffmpeg -i input0 -i input1 -i input2 -filter_complex "[0:v][1:v][2:v]vstack=inputs=3[v]" -map "[v]" output




                    Example 4: 2x2 grid



                    enter image description here



                    Using xstack



                    ffmpeg -i input0 -i input1 -i input2 -i input3 -filter_complex "[0:v][1:v][2:v][3:v]xstack=inputs=4:layout=0_0|0_h0|w0_0|w0_h0[v]" -map "[v]" output


                    Using hstack and vstack



                    ffmpeg -i input0 -i input1 -i input2 -i input3 -filter_complex "[0:v][1:v]hstack=inputs=2[top];[2:v][3:v]hstack=inputs=2[bottom];[top][bottom]vstack=inputs=2[v]" -map "[v]" output


                    This is less efficient than using xstack as shown above.





                    Example 5: Resize/scale an input



                    Since both videos need to have the same with for vstack, and the same height for hstack, you may need to scale one of the other videos to match the other:



                    Simple scale filter example to set width of input0 to 640 and automatically set height while preserving the aspect ratio:



                    ffmpeg -i input0 -i input2 -filter_complex "[0:v]scale=640:-1[v0];[v0][1:v]vstack=inputs=2" output



                    • For a more advanced method to fit any size video into a specific size while preserving aspect ratio see Resizing videos with ffmpeg to fit into static sized player.


                    • You can also use the scale2ref filter to automatically resize one video to match the dimensions of the other.







                    share|improve this answer























                    • ffmpeg reports No such filter: 'vstack'. Do I have to install it first?
                      – frans
                      Dec 12 '15 at 13:39










                    • @frans You probably figured this out by now, but your ffmpeg is too old. Users are recommended to use a ffmpeg build derived from the current git master branch.
                      – LordNeckbeard
                      Dec 14 '15 at 1:36










                    • Stream specifier ':a' in filtergraph description [0:v][1:v]vstack[v];[0:a][1:a]amerge=inputs=2[a] matches no streams. Why do I get this?
                      – RaduM
                      Jun 29 '17 at 9:02






                    • 2




                      @RaduM its because one of your video doesnt have audio in it , you need to add an audio or silent audio in it , try the same command using two videos with Audio , it will work , am posting because I had the same problem today and rectified it using silent audio addition.
                      – Jeffin
                      Jul 10 '17 at 7:24










                    • @LordNeckbeard I used your Example 2 command for merging two videos. It did worked for me and I got an output with two videos merged along with their Audios mixed. What is the command if I add a third file, say an mp3 file, and merge 2 videos as before and merge 3 audios together.
                      – Nasseh
                      Jul 31 '17 at 7:59













                    up vote
                    32
                    down vote










                    up vote
                    32
                    down vote









                    Use the vstack (vertical), hstack (horizontal), or xstack (custom layout) filters. It is easier and faster than other methods.



                    Example 1: Combine/stack two videos



                    Vertical



                    Using the vstack filter.



                    enter image description here



                    ffmpeg -i input0 -i input1 -filter_complex vstack=inputs=2 output


                    Videos must have the same width.



                    Horizontal



                    Using the hstack filter.



                    enter image description here



                    ffmpeg -i input0 -i input1 -filter_complex hstack=inputs=2 output


                    Videos must have the same height.





                    Example 2: Same as above but with audio



                    Combined audio from both inputs



                    Add the amerge filter to combine the audio channels from both inputs:



                    ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v];[0:a][1:a]amerge=inputs=2[a]" -map "[v]" -map "[a]" -ac 2 output




                    • -ac 2 is included to downmix to stereo in case both inputs contain multi-channel audio. For example, if both inputs are stereo, you would get a 4-channel output audio stream instead of stereo if you omit -ac 2.


                    Using audio from one particular input



                    This example will use the audio from input1:



                    ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v]" -map "[v]" -map 1:a output


                    Adding silent audio / If one input does not have audio



                    If you mix inputs that have audio and inputs that do not have audio then amerge will fail because each input needs audio. You can add silent audio with the anullsrc filter to prevent this:



                    ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v];anullsrc[silent];[0:a][silent]amerge=inputs=2[a]" -map "[v]" -map "[a]" -ac 2 output.mp4




                    Example 3: Three videos



                    enter image description here



                    ffmpeg -i input0 -i input1 -i input2 -filter_complex "[0:v][1:v][2:v]vstack=inputs=3[v]" -map "[v]" output




                    Example 4: 2x2 grid



                    enter image description here



                    Using xstack



                    ffmpeg -i input0 -i input1 -i input2 -i input3 -filter_complex "[0:v][1:v][2:v][3:v]xstack=inputs=4:layout=0_0|0_h0|w0_0|w0_h0[v]" -map "[v]" output


                    Using hstack and vstack



                    ffmpeg -i input0 -i input1 -i input2 -i input3 -filter_complex "[0:v][1:v]hstack=inputs=2[top];[2:v][3:v]hstack=inputs=2[bottom];[top][bottom]vstack=inputs=2[v]" -map "[v]" output


                    This is less efficient than using xstack as shown above.





                    Example 5: Resize/scale an input



                    Since both videos need to have the same with for vstack, and the same height for hstack, you may need to scale one of the other videos to match the other:



                    Simple scale filter example to set width of input0 to 640 and automatically set height while preserving the aspect ratio:



                    ffmpeg -i input0 -i input2 -filter_complex "[0:v]scale=640:-1[v0];[v0][1:v]vstack=inputs=2" output



                    • For a more advanced method to fit any size video into a specific size while preserving aspect ratio see Resizing videos with ffmpeg to fit into static sized player.


                    • You can also use the scale2ref filter to automatically resize one video to match the dimensions of the other.







                    share|improve this answer














                    Use the vstack (vertical), hstack (horizontal), or xstack (custom layout) filters. It is easier and faster than other methods.



                    Example 1: Combine/stack two videos



                    Vertical



                    Using the vstack filter.



                    enter image description here



                    ffmpeg -i input0 -i input1 -filter_complex vstack=inputs=2 output


                    Videos must have the same width.



                    Horizontal



                    Using the hstack filter.



                    enter image description here



                    ffmpeg -i input0 -i input1 -filter_complex hstack=inputs=2 output


                    Videos must have the same height.





                    Example 2: Same as above but with audio



                    Combined audio from both inputs



                    Add the amerge filter to combine the audio channels from both inputs:



                    ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v];[0:a][1:a]amerge=inputs=2[a]" -map "[v]" -map "[a]" -ac 2 output




                    • -ac 2 is included to downmix to stereo in case both inputs contain multi-channel audio. For example, if both inputs are stereo, you would get a 4-channel output audio stream instead of stereo if you omit -ac 2.


                    Using audio from one particular input



                    This example will use the audio from input1:



                    ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v]" -map "[v]" -map 1:a output


                    Adding silent audio / If one input does not have audio



                    If you mix inputs that have audio and inputs that do not have audio then amerge will fail because each input needs audio. You can add silent audio with the anullsrc filter to prevent this:



                    ffmpeg -i input0 -i input1 -filter_complex "[0:v][1:v]vstack=inputs=2[v];anullsrc[silent];[0:a][silent]amerge=inputs=2[a]" -map "[v]" -map "[a]" -ac 2 output.mp4




                    Example 3: Three videos



                    enter image description here



                    ffmpeg -i input0 -i input1 -i input2 -filter_complex "[0:v][1:v][2:v]vstack=inputs=3[v]" -map "[v]" output




                    Example 4: 2x2 grid



                    enter image description here



                    Using xstack



                    ffmpeg -i input0 -i input1 -i input2 -i input3 -filter_complex "[0:v][1:v][2:v][3:v]xstack=inputs=4:layout=0_0|0_h0|w0_0|w0_h0[v]" -map "[v]" output


                    Using hstack and vstack



                    ffmpeg -i input0 -i input1 -i input2 -i input3 -filter_complex "[0:v][1:v]hstack=inputs=2[top];[2:v][3:v]hstack=inputs=2[bottom];[top][bottom]vstack=inputs=2[v]" -map "[v]" output


                    This is less efficient than using xstack as shown above.





                    Example 5: Resize/scale an input



                    Since both videos need to have the same with for vstack, and the same height for hstack, you may need to scale one of the other videos to match the other:



                    Simple scale filter example to set width of input0 to 640 and automatically set height while preserving the aspect ratio:



                    ffmpeg -i input0 -i input2 -filter_complex "[0:v]scale=640:-1[v0];[v0][1:v]vstack=inputs=2" output



                    • For a more advanced method to fit any size video into a specific size while preserving aspect ratio see Resizing videos with ffmpeg to fit into static sized player.


                    • You can also use the scale2ref filter to automatically resize one video to match the dimensions of the other.








                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Oct 31 at 21:32

























                    answered Nov 17 '15 at 18:59









                    LordNeckbeard

                    43.1k13101133




                    43.1k13101133












                    • ffmpeg reports No such filter: 'vstack'. Do I have to install it first?
                      – frans
                      Dec 12 '15 at 13:39










                    • @frans You probably figured this out by now, but your ffmpeg is too old. Users are recommended to use a ffmpeg build derived from the current git master branch.
                      – LordNeckbeard
                      Dec 14 '15 at 1:36










                    • Stream specifier ':a' in filtergraph description [0:v][1:v]vstack[v];[0:a][1:a]amerge=inputs=2[a] matches no streams. Why do I get this?
                      – RaduM
                      Jun 29 '17 at 9:02






                    • 2




                      @RaduM its because one of your video doesnt have audio in it , you need to add an audio or silent audio in it , try the same command using two videos with Audio , it will work , am posting because I had the same problem today and rectified it using silent audio addition.
                      – Jeffin
                      Jul 10 '17 at 7:24










                    • @LordNeckbeard I used your Example 2 command for merging two videos. It did worked for me and I got an output with two videos merged along with their Audios mixed. What is the command if I add a third file, say an mp3 file, and merge 2 videos as before and merge 3 audios together.
                      – Nasseh
                      Jul 31 '17 at 7:59


















                    • ffmpeg reports No such filter: 'vstack'. Do I have to install it first?
                      – frans
                      Dec 12 '15 at 13:39










                    • @frans You probably figured this out by now, but your ffmpeg is too old. Users are recommended to use a ffmpeg build derived from the current git master branch.
                      – LordNeckbeard
                      Dec 14 '15 at 1:36










                    • Stream specifier ':a' in filtergraph description [0:v][1:v]vstack[v];[0:a][1:a]amerge=inputs=2[a] matches no streams. Why do I get this?
                      – RaduM
                      Jun 29 '17 at 9:02






                    • 2




                      @RaduM its because one of your video doesnt have audio in it , you need to add an audio or silent audio in it , try the same command using two videos with Audio , it will work , am posting because I had the same problem today and rectified it using silent audio addition.
                      – Jeffin
                      Jul 10 '17 at 7:24










                    • @LordNeckbeard I used your Example 2 command for merging two videos. It did worked for me and I got an output with two videos merged along with their Audios mixed. What is the command if I add a third file, say an mp3 file, and merge 2 videos as before and merge 3 audios together.
                      – Nasseh
                      Jul 31 '17 at 7:59
















                    ffmpeg reports No such filter: 'vstack'. Do I have to install it first?
                    – frans
                    Dec 12 '15 at 13:39




                    ffmpeg reports No such filter: 'vstack'. Do I have to install it first?
                    – frans
                    Dec 12 '15 at 13:39












                    @frans You probably figured this out by now, but your ffmpeg is too old. Users are recommended to use a ffmpeg build derived from the current git master branch.
                    – LordNeckbeard
                    Dec 14 '15 at 1:36




                    @frans You probably figured this out by now, but your ffmpeg is too old. Users are recommended to use a ffmpeg build derived from the current git master branch.
                    – LordNeckbeard
                    Dec 14 '15 at 1:36












                    Stream specifier ':a' in filtergraph description [0:v][1:v]vstack[v];[0:a][1:a]amerge=inputs=2[a] matches no streams. Why do I get this?
                    – RaduM
                    Jun 29 '17 at 9:02




                    Stream specifier ':a' in filtergraph description [0:v][1:v]vstack[v];[0:a][1:a]amerge=inputs=2[a] matches no streams. Why do I get this?
                    – RaduM
                    Jun 29 '17 at 9:02




                    2




                    2




                    @RaduM its because one of your video doesnt have audio in it , you need to add an audio or silent audio in it , try the same command using two videos with Audio , it will work , am posting because I had the same problem today and rectified it using silent audio addition.
                    – Jeffin
                    Jul 10 '17 at 7:24




                    @RaduM its because one of your video doesnt have audio in it , you need to add an audio or silent audio in it , try the same command using two videos with Audio , it will work , am posting because I had the same problem today and rectified it using silent audio addition.
                    – Jeffin
                    Jul 10 '17 at 7:24












                    @LordNeckbeard I used your Example 2 command for merging two videos. It did worked for me and I got an output with two videos merged along with their Audios mixed. What is the command if I add a third file, say an mp3 file, and merge 2 videos as before and merge 3 audios together.
                    – Nasseh
                    Jul 31 '17 at 7:59




                    @LordNeckbeard I used your Example 2 command for merging two videos. It did worked for me and I got an output with two videos merged along with their Audios mixed. What is the command if I add a third file, say an mp3 file, and merge 2 videos as before and merge 3 audios together.
                    – Nasseh
                    Jul 31 '17 at 7:59


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11552565%2fvertically-or-horizontally-stack-several-videos-using-ffmpeg%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Guess what letter conforming each word

                    Port of Spain

                    Run scheduled task as local user group (not BUILTIN)