How to merge multiple (more than two) videos on Ubuntu?












22















I want to merge videos in batch size of twenty (20) each. I'm running a Linux machine. The videos are in mp4 format and moderate quality. Some even have the audio stream missing. So far I've tried ffmpeg, mencoder, cvlc/vlc and MP4Box. I want to write a command line script to achieve this, since I'm doing batch processing.



The main issue is that some of the solutions I tried work well for two videos, some work well for videos with audio stream and yet others work well for some other subset of my video set. However, I have not been able to find a comprehensive solution for this task.










share|improve this question




















  • 2





    Please don't ask same question in multi SE sites: superuser.com/questions/928548/…

    – Maythux
    Jun 16 '15 at 10:25











  • Could you post specifically what you've tried so far?

    – ohaal
    Jun 16 '15 at 14:18













  • @ohaal I tried using various concatenation methods given in ffmpeg, including filters and file protocols. I also tried using the concat feature of cvlc/vlc. I also tried the concat feature of mencoder. All of these worked partially. This finally helped me solve the matter.

    – Dhruv Singal
    Jun 18 '15 at 4:25











  • Yes, you already mentioned the tools, what I meant was the actual commands you ran. Also it would be great if you could include the command that ended up solving it for you (in your answer), for future visitors.

    – ohaal
    Jun 18 '15 at 7:18











  • Aah, I see your point. Unfortunately, I can't list the commands due to the sheer number. The command which solved my problem was this melt {input-sequence} -consumer avformat:{output-name} acodec=libmp3lame vcodec=libx264

    – Dhruv Singal
    Jun 19 '15 at 7:14
















22















I want to merge videos in batch size of twenty (20) each. I'm running a Linux machine. The videos are in mp4 format and moderate quality. Some even have the audio stream missing. So far I've tried ffmpeg, mencoder, cvlc/vlc and MP4Box. I want to write a command line script to achieve this, since I'm doing batch processing.



The main issue is that some of the solutions I tried work well for two videos, some work well for videos with audio stream and yet others work well for some other subset of my video set. However, I have not been able to find a comprehensive solution for this task.










share|improve this question




















  • 2





    Please don't ask same question in multi SE sites: superuser.com/questions/928548/…

    – Maythux
    Jun 16 '15 at 10:25











  • Could you post specifically what you've tried so far?

    – ohaal
    Jun 16 '15 at 14:18













  • @ohaal I tried using various concatenation methods given in ffmpeg, including filters and file protocols. I also tried using the concat feature of cvlc/vlc. I also tried the concat feature of mencoder. All of these worked partially. This finally helped me solve the matter.

    – Dhruv Singal
    Jun 18 '15 at 4:25











  • Yes, you already mentioned the tools, what I meant was the actual commands you ran. Also it would be great if you could include the command that ended up solving it for you (in your answer), for future visitors.

    – ohaal
    Jun 18 '15 at 7:18











  • Aah, I see your point. Unfortunately, I can't list the commands due to the sheer number. The command which solved my problem was this melt {input-sequence} -consumer avformat:{output-name} acodec=libmp3lame vcodec=libx264

    – Dhruv Singal
    Jun 19 '15 at 7:14














22












22








22


2






I want to merge videos in batch size of twenty (20) each. I'm running a Linux machine. The videos are in mp4 format and moderate quality. Some even have the audio stream missing. So far I've tried ffmpeg, mencoder, cvlc/vlc and MP4Box. I want to write a command line script to achieve this, since I'm doing batch processing.



The main issue is that some of the solutions I tried work well for two videos, some work well for videos with audio stream and yet others work well for some other subset of my video set. However, I have not been able to find a comprehensive solution for this task.










share|improve this question
















I want to merge videos in batch size of twenty (20) each. I'm running a Linux machine. The videos are in mp4 format and moderate quality. Some even have the audio stream missing. So far I've tried ffmpeg, mencoder, cvlc/vlc and MP4Box. I want to write a command line script to achieve this, since I'm doing batch processing.



The main issue is that some of the solutions I tried work well for two videos, some work well for videos with audio stream and yet others work well for some other subset of my video set. However, I have not been able to find a comprehensive solution for this task.







command-line video vlc ffmpeg mencoder






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 14 '18 at 0:16









Ciro Santilli 新疆改造中心 六四事件 法轮功

9,40944347




9,40944347










asked Jun 16 '15 at 10:02









Dhruv SingalDhruv Singal

1611110




1611110








  • 2





    Please don't ask same question in multi SE sites: superuser.com/questions/928548/…

    – Maythux
    Jun 16 '15 at 10:25











  • Could you post specifically what you've tried so far?

    – ohaal
    Jun 16 '15 at 14:18













  • @ohaal I tried using various concatenation methods given in ffmpeg, including filters and file protocols. I also tried using the concat feature of cvlc/vlc. I also tried the concat feature of mencoder. All of these worked partially. This finally helped me solve the matter.

    – Dhruv Singal
    Jun 18 '15 at 4:25











  • Yes, you already mentioned the tools, what I meant was the actual commands you ran. Also it would be great if you could include the command that ended up solving it for you (in your answer), for future visitors.

    – ohaal
    Jun 18 '15 at 7:18











  • Aah, I see your point. Unfortunately, I can't list the commands due to the sheer number. The command which solved my problem was this melt {input-sequence} -consumer avformat:{output-name} acodec=libmp3lame vcodec=libx264

    – Dhruv Singal
    Jun 19 '15 at 7:14














  • 2





    Please don't ask same question in multi SE sites: superuser.com/questions/928548/…

    – Maythux
    Jun 16 '15 at 10:25











  • Could you post specifically what you've tried so far?

    – ohaal
    Jun 16 '15 at 14:18













  • @ohaal I tried using various concatenation methods given in ffmpeg, including filters and file protocols. I also tried using the concat feature of cvlc/vlc. I also tried the concat feature of mencoder. All of these worked partially. This finally helped me solve the matter.

    – Dhruv Singal
    Jun 18 '15 at 4:25











  • Yes, you already mentioned the tools, what I meant was the actual commands you ran. Also it would be great if you could include the command that ended up solving it for you (in your answer), for future visitors.

    – ohaal
    Jun 18 '15 at 7:18











  • Aah, I see your point. Unfortunately, I can't list the commands due to the sheer number. The command which solved my problem was this melt {input-sequence} -consumer avformat:{output-name} acodec=libmp3lame vcodec=libx264

    – Dhruv Singal
    Jun 19 '15 at 7:14








2




2





Please don't ask same question in multi SE sites: superuser.com/questions/928548/…

– Maythux
Jun 16 '15 at 10:25





Please don't ask same question in multi SE sites: superuser.com/questions/928548/…

– Maythux
Jun 16 '15 at 10:25













Could you post specifically what you've tried so far?

– ohaal
Jun 16 '15 at 14:18







Could you post specifically what you've tried so far?

– ohaal
Jun 16 '15 at 14:18















@ohaal I tried using various concatenation methods given in ffmpeg, including filters and file protocols. I also tried using the concat feature of cvlc/vlc. I also tried the concat feature of mencoder. All of these worked partially. This finally helped me solve the matter.

– Dhruv Singal
Jun 18 '15 at 4:25





@ohaal I tried using various concatenation methods given in ffmpeg, including filters and file protocols. I also tried using the concat feature of cvlc/vlc. I also tried the concat feature of mencoder. All of these worked partially. This finally helped me solve the matter.

– Dhruv Singal
Jun 18 '15 at 4:25













Yes, you already mentioned the tools, what I meant was the actual commands you ran. Also it would be great if you could include the command that ended up solving it for you (in your answer), for future visitors.

– ohaal
Jun 18 '15 at 7:18





Yes, you already mentioned the tools, what I meant was the actual commands you ran. Also it would be great if you could include the command that ended up solving it for you (in your answer), for future visitors.

– ohaal
Jun 18 '15 at 7:18













Aah, I see your point. Unfortunately, I can't list the commands due to the sheer number. The command which solved my problem was this melt {input-sequence} -consumer avformat:{output-name} acodec=libmp3lame vcodec=libx264

– Dhruv Singal
Jun 19 '15 at 7:14





Aah, I see your point. Unfortunately, I can't list the commands due to the sheer number. The command which solved my problem was this melt {input-sequence} -consumer avformat:{output-name} acodec=libmp3lame vcodec=libx264

– Dhruv Singal
Jun 19 '15 at 7:14










7 Answers
7






active

oldest

votes


















27














I am using mkvmerge to join multiple MP4 files into single one:



mkvmerge -o outfile.mkv infile_01.mp4 + infile_02.mp4 + infile_03.mp4





share|improve this answer


























  • Nice, easy, quick. Thanks for sharing

    – augusto
    Mar 5 '17 at 14:10






  • 2





    It is better to use the extension .mkv for the output file, as it is a Matroska container irrespective of what extension you give.

    – haridsv
    Sep 17 '17 at 7:27











  • Here's how to install mkvmerge: tipsonubuntu.com

    – Morgoth
    Jan 31 '18 at 9:54



















17














You can do it using ffmpeg:



ffmpeg -i concat:"input1.mp4|input2.mp4" output.mp4


reference and more info






share|improve this answer





















  • 2





    I tried doing that. The issue with this is that it doesn't give a proper out. 1. The audio tracks are muddled. 2. There is some disturbance in the video track.

    – Dhruv Singal
    Jun 16 '15 at 11:26













  • I used it for more than sample, the result is high quality, maybe your source video quality is the problem?

    – Maythux
    Jun 17 '15 at 5:58











  • You are probably right. This solved the issue: askubuntu.com/a/637179/420614

    – Dhruv Singal
    Jun 18 '15 at 4:18






  • 1





    Don't use the concat protocol to concatenate MP4. It only works with certain formats that most general users don't encounter. Use concat demuxer or concat filter instead.

    – llogan
    Nov 17 '17 at 18:11











  • I tried ffmpeg with 2 mp4 files of 30min each. I got an output file with length 7 hours.

    – Guus
    Jul 3 '18 at 14:33



















5














This solved the matter:
https://stackoverflow.com/a/22324018/5014767



melt is a great command line utility for this.
Here is the page



Edit from comments: The command which solved my problem was this
melt {input-sequence} -consumer avformat:{output-name} acodec=libmp3lame vcodec=libx264






share|improve this answer

































    3














    I wrote a little shell script to concat MP4s without transcoding using ffmpeg.



    for f in $(ls *.MP4); do
    ffmpeg -i $f -c copy -bsf:v h264_mp4toannexb -f mpegts $f.ts
    done

    CONCAT=$(echo $(ls *.ts) | sed -e "s/ /|/g")

    ffmpeg -i "concat:$CONCAT" -c copy -bsf:a aac_adtstoasc output.mp4

    rm *.ts


    This creates intermediate files in an MPEG container and then concatenates them into an MP4.






    share|improve this answer
























    • It's important to note that this script will fail if any of the filenames contain spaces or, in some cases, special characters. For the loop, it's significantly better to use just for f in *.MP4 without using ls. (You should always avoid using ls in scripts for a couple of important reasons; there are better options.) Also, use quotes for variables unless you are certain that there are no spaces or other special characters, so "${f}" (or just "$f") instead of unquoted $f.

      – Paddy Landau
      Jun 14 '18 at 14:11











    • CONCAT=$(echo $(ls *.ts) | sed -e "s/ /|/g") doesn't work well with file names that are 1, 2, 3... 10... 20. It ends up parsing them as 1, 10... 2, 20... etc. I suggest CONCAT=$(echo $(ls -v *.ts) | sed -e "s/ /|/g") this will ensure order.

      – tisaconundrum
      Nov 16 '18 at 8:05





















    0














    My script, purely in bash and ffmpeg. Re-encodes files given on a command line into one.



    Requires the files to be of the same resolution. Accepts different metadata rotation, which ffmpeg concat: doesn't.



    rm ffmpeg-concat-output.mkv

    FILE_COUNT=$#
    INPUTS=""
    FILTER=""
    INDEX=0
    for FNAME in $@; do
    echo "Processing ${FNAME}"
    INPUTS="${INPUTS} -i $FNAME"

    if [ -z "${FILTER}" ]; then
    FILTER="[$INDEX:v:0] [$INDEX:a:0]"
    else
    FILTER="${FILTER} [$INDEX:v:0] [$INDEX:a:0]"
    fi
    let INDEX+=1
    done

    COMMAND="ffmpeg ${INPUTS}
    -filter_complex '${FILTER}
    concat=n=${INDEX}:v=1:a=1 [v] [a]'
    -map '[v]' -map '[a]'
    ffmpeg-concat-output.mkv"

    # -af 'volume=15dB' # won't work with -filter_complex

    bash -c "${COMMAND}"





    share|improve this answer

































      0














      I created a Python script that, using moviepy, can concatenate also subsegments (useful if you want for example remove some parts from a video).



      Use it with:



      vcat -i inputfile1,inputfile2[start-end],... -o <outputfile>





      share|improve this answer































        -1














        In addition to Maythux's answer, from :




        A few multimedia containers (MPEG-1, MPEG-2 PS, DV) allow one to concatenate video by merely concatenating the files containing them.




        I.e. the videos to be concatenated use one of the abovementioned video containers (to which I'll add MPEG-4 Part 14 for personal experience), you could simply:



        cat video1.ext video2.ext video3.ext > video4.ext





        share|improve this answer





















        • 1





          I tried this but it only returns the first video as the output. I read somewhere that it doesn't work, though I don't remember the rationale behind this.

          – Dhruv Singal
          Jun 16 '15 at 11:28











        • @DhruvSingal Yes, I can confirm this, I've tried this on two MP4 videos with the exact same video / audio encoding and as you I could only browse through the first video. Which seems reasonable, however I'm pretty sure that I've done this before once with a couple of MP4 videos. Perhaps the memory isn't serving well here, or there are other requirements for this to work. I want to research on this since I'm interested also, if I find something I'll update the answer and drop you a comment

          – kos
          Jun 16 '15 at 11:45











        • We somehow need to change the metadata at the start of the first video to encompass the entire length of the combined movie, and other stuff probably. Only a few mpeg4 files let me see the metadata..

          – Ken Mollerup
          Oct 22 '15 at 14:55











        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "89"
        };
        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',
        autoActivateHeartbeat: false,
        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%2faskubuntu.com%2fquestions%2f637074%2fhow-to-merge-multiple-more-than-two-videos-on-ubuntu%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        7 Answers
        7






        active

        oldest

        votes








        7 Answers
        7






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        27














        I am using mkvmerge to join multiple MP4 files into single one:



        mkvmerge -o outfile.mkv infile_01.mp4 + infile_02.mp4 + infile_03.mp4





        share|improve this answer


























        • Nice, easy, quick. Thanks for sharing

          – augusto
          Mar 5 '17 at 14:10






        • 2





          It is better to use the extension .mkv for the output file, as it is a Matroska container irrespective of what extension you give.

          – haridsv
          Sep 17 '17 at 7:27











        • Here's how to install mkvmerge: tipsonubuntu.com

          – Morgoth
          Jan 31 '18 at 9:54
















        27














        I am using mkvmerge to join multiple MP4 files into single one:



        mkvmerge -o outfile.mkv infile_01.mp4 + infile_02.mp4 + infile_03.mp4





        share|improve this answer


























        • Nice, easy, quick. Thanks for sharing

          – augusto
          Mar 5 '17 at 14:10






        • 2





          It is better to use the extension .mkv for the output file, as it is a Matroska container irrespective of what extension you give.

          – haridsv
          Sep 17 '17 at 7:27











        • Here's how to install mkvmerge: tipsonubuntu.com

          – Morgoth
          Jan 31 '18 at 9:54














        27












        27








        27







        I am using mkvmerge to join multiple MP4 files into single one:



        mkvmerge -o outfile.mkv infile_01.mp4 + infile_02.mp4 + infile_03.mp4





        share|improve this answer















        I am using mkvmerge to join multiple MP4 files into single one:



        mkvmerge -o outfile.mkv infile_01.mp4 + infile_02.mp4 + infile_03.mp4






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 15 '18 at 22:46









        Elder Geek

        26.5k952126




        26.5k952126










        answered Oct 1 '16 at 9:45









        Szabolcs SpindlerSzabolcs Spindler

        27132




        27132













        • Nice, easy, quick. Thanks for sharing

          – augusto
          Mar 5 '17 at 14:10






        • 2





          It is better to use the extension .mkv for the output file, as it is a Matroska container irrespective of what extension you give.

          – haridsv
          Sep 17 '17 at 7:27











        • Here's how to install mkvmerge: tipsonubuntu.com

          – Morgoth
          Jan 31 '18 at 9:54



















        • Nice, easy, quick. Thanks for sharing

          – augusto
          Mar 5 '17 at 14:10






        • 2





          It is better to use the extension .mkv for the output file, as it is a Matroska container irrespective of what extension you give.

          – haridsv
          Sep 17 '17 at 7:27











        • Here's how to install mkvmerge: tipsonubuntu.com

          – Morgoth
          Jan 31 '18 at 9:54

















        Nice, easy, quick. Thanks for sharing

        – augusto
        Mar 5 '17 at 14:10





        Nice, easy, quick. Thanks for sharing

        – augusto
        Mar 5 '17 at 14:10




        2




        2





        It is better to use the extension .mkv for the output file, as it is a Matroska container irrespective of what extension you give.

        – haridsv
        Sep 17 '17 at 7:27





        It is better to use the extension .mkv for the output file, as it is a Matroska container irrespective of what extension you give.

        – haridsv
        Sep 17 '17 at 7:27













        Here's how to install mkvmerge: tipsonubuntu.com

        – Morgoth
        Jan 31 '18 at 9:54





        Here's how to install mkvmerge: tipsonubuntu.com

        – Morgoth
        Jan 31 '18 at 9:54













        17














        You can do it using ffmpeg:



        ffmpeg -i concat:"input1.mp4|input2.mp4" output.mp4


        reference and more info






        share|improve this answer





















        • 2





          I tried doing that. The issue with this is that it doesn't give a proper out. 1. The audio tracks are muddled. 2. There is some disturbance in the video track.

          – Dhruv Singal
          Jun 16 '15 at 11:26













        • I used it for more than sample, the result is high quality, maybe your source video quality is the problem?

          – Maythux
          Jun 17 '15 at 5:58











        • You are probably right. This solved the issue: askubuntu.com/a/637179/420614

          – Dhruv Singal
          Jun 18 '15 at 4:18






        • 1





          Don't use the concat protocol to concatenate MP4. It only works with certain formats that most general users don't encounter. Use concat demuxer or concat filter instead.

          – llogan
          Nov 17 '17 at 18:11











        • I tried ffmpeg with 2 mp4 files of 30min each. I got an output file with length 7 hours.

          – Guus
          Jul 3 '18 at 14:33
















        17














        You can do it using ffmpeg:



        ffmpeg -i concat:"input1.mp4|input2.mp4" output.mp4


        reference and more info






        share|improve this answer





















        • 2





          I tried doing that. The issue with this is that it doesn't give a proper out. 1. The audio tracks are muddled. 2. There is some disturbance in the video track.

          – Dhruv Singal
          Jun 16 '15 at 11:26













        • I used it for more than sample, the result is high quality, maybe your source video quality is the problem?

          – Maythux
          Jun 17 '15 at 5:58











        • You are probably right. This solved the issue: askubuntu.com/a/637179/420614

          – Dhruv Singal
          Jun 18 '15 at 4:18






        • 1





          Don't use the concat protocol to concatenate MP4. It only works with certain formats that most general users don't encounter. Use concat demuxer or concat filter instead.

          – llogan
          Nov 17 '17 at 18:11











        • I tried ffmpeg with 2 mp4 files of 30min each. I got an output file with length 7 hours.

          – Guus
          Jul 3 '18 at 14:33














        17












        17








        17







        You can do it using ffmpeg:



        ffmpeg -i concat:"input1.mp4|input2.mp4" output.mp4


        reference and more info






        share|improve this answer















        You can do it using ffmpeg:



        ffmpeg -i concat:"input1.mp4|input2.mp4" output.mp4


        reference and more info







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jun 16 '15 at 10:32

























        answered Jun 16 '15 at 10:24









        MaythuxMaythux

        50.6k32169215




        50.6k32169215








        • 2





          I tried doing that. The issue with this is that it doesn't give a proper out. 1. The audio tracks are muddled. 2. There is some disturbance in the video track.

          – Dhruv Singal
          Jun 16 '15 at 11:26













        • I used it for more than sample, the result is high quality, maybe your source video quality is the problem?

          – Maythux
          Jun 17 '15 at 5:58











        • You are probably right. This solved the issue: askubuntu.com/a/637179/420614

          – Dhruv Singal
          Jun 18 '15 at 4:18






        • 1





          Don't use the concat protocol to concatenate MP4. It only works with certain formats that most general users don't encounter. Use concat demuxer or concat filter instead.

          – llogan
          Nov 17 '17 at 18:11











        • I tried ffmpeg with 2 mp4 files of 30min each. I got an output file with length 7 hours.

          – Guus
          Jul 3 '18 at 14:33














        • 2





          I tried doing that. The issue with this is that it doesn't give a proper out. 1. The audio tracks are muddled. 2. There is some disturbance in the video track.

          – Dhruv Singal
          Jun 16 '15 at 11:26













        • I used it for more than sample, the result is high quality, maybe your source video quality is the problem?

          – Maythux
          Jun 17 '15 at 5:58











        • You are probably right. This solved the issue: askubuntu.com/a/637179/420614

          – Dhruv Singal
          Jun 18 '15 at 4:18






        • 1





          Don't use the concat protocol to concatenate MP4. It only works with certain formats that most general users don't encounter. Use concat demuxer or concat filter instead.

          – llogan
          Nov 17 '17 at 18:11











        • I tried ffmpeg with 2 mp4 files of 30min each. I got an output file with length 7 hours.

          – Guus
          Jul 3 '18 at 14:33








        2




        2





        I tried doing that. The issue with this is that it doesn't give a proper out. 1. The audio tracks are muddled. 2. There is some disturbance in the video track.

        – Dhruv Singal
        Jun 16 '15 at 11:26







        I tried doing that. The issue with this is that it doesn't give a proper out. 1. The audio tracks are muddled. 2. There is some disturbance in the video track.

        – Dhruv Singal
        Jun 16 '15 at 11:26















        I used it for more than sample, the result is high quality, maybe your source video quality is the problem?

        – Maythux
        Jun 17 '15 at 5:58





        I used it for more than sample, the result is high quality, maybe your source video quality is the problem?

        – Maythux
        Jun 17 '15 at 5:58













        You are probably right. This solved the issue: askubuntu.com/a/637179/420614

        – Dhruv Singal
        Jun 18 '15 at 4:18





        You are probably right. This solved the issue: askubuntu.com/a/637179/420614

        – Dhruv Singal
        Jun 18 '15 at 4:18




        1




        1





        Don't use the concat protocol to concatenate MP4. It only works with certain formats that most general users don't encounter. Use concat demuxer or concat filter instead.

        – llogan
        Nov 17 '17 at 18:11





        Don't use the concat protocol to concatenate MP4. It only works with certain formats that most general users don't encounter. Use concat demuxer or concat filter instead.

        – llogan
        Nov 17 '17 at 18:11













        I tried ffmpeg with 2 mp4 files of 30min each. I got an output file with length 7 hours.

        – Guus
        Jul 3 '18 at 14:33





        I tried ffmpeg with 2 mp4 files of 30min each. I got an output file with length 7 hours.

        – Guus
        Jul 3 '18 at 14:33











        5














        This solved the matter:
        https://stackoverflow.com/a/22324018/5014767



        melt is a great command line utility for this.
        Here is the page



        Edit from comments: The command which solved my problem was this
        melt {input-sequence} -consumer avformat:{output-name} acodec=libmp3lame vcodec=libx264






        share|improve this answer






























          5














          This solved the matter:
          https://stackoverflow.com/a/22324018/5014767



          melt is a great command line utility for this.
          Here is the page



          Edit from comments: The command which solved my problem was this
          melt {input-sequence} -consumer avformat:{output-name} acodec=libmp3lame vcodec=libx264






          share|improve this answer




























            5












            5








            5







            This solved the matter:
            https://stackoverflow.com/a/22324018/5014767



            melt is a great command line utility for this.
            Here is the page



            Edit from comments: The command which solved my problem was this
            melt {input-sequence} -consumer avformat:{output-name} acodec=libmp3lame vcodec=libx264






            share|improve this answer















            This solved the matter:
            https://stackoverflow.com/a/22324018/5014767



            melt is a great command line utility for this.
            Here is the page



            Edit from comments: The command which solved my problem was this
            melt {input-sequence} -consumer avformat:{output-name} acodec=libmp3lame vcodec=libx264







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 23 '17 at 12:39









            Community

            1




            1










            answered Jun 16 '15 at 14:16









            Dhruv SingalDhruv Singal

            1611110




            1611110























                3














                I wrote a little shell script to concat MP4s without transcoding using ffmpeg.



                for f in $(ls *.MP4); do
                ffmpeg -i $f -c copy -bsf:v h264_mp4toannexb -f mpegts $f.ts
                done

                CONCAT=$(echo $(ls *.ts) | sed -e "s/ /|/g")

                ffmpeg -i "concat:$CONCAT" -c copy -bsf:a aac_adtstoasc output.mp4

                rm *.ts


                This creates intermediate files in an MPEG container and then concatenates them into an MP4.






                share|improve this answer
























                • It's important to note that this script will fail if any of the filenames contain spaces or, in some cases, special characters. For the loop, it's significantly better to use just for f in *.MP4 without using ls. (You should always avoid using ls in scripts for a couple of important reasons; there are better options.) Also, use quotes for variables unless you are certain that there are no spaces or other special characters, so "${f}" (or just "$f") instead of unquoted $f.

                  – Paddy Landau
                  Jun 14 '18 at 14:11











                • CONCAT=$(echo $(ls *.ts) | sed -e "s/ /|/g") doesn't work well with file names that are 1, 2, 3... 10... 20. It ends up parsing them as 1, 10... 2, 20... etc. I suggest CONCAT=$(echo $(ls -v *.ts) | sed -e "s/ /|/g") this will ensure order.

                  – tisaconundrum
                  Nov 16 '18 at 8:05


















                3














                I wrote a little shell script to concat MP4s without transcoding using ffmpeg.



                for f in $(ls *.MP4); do
                ffmpeg -i $f -c copy -bsf:v h264_mp4toannexb -f mpegts $f.ts
                done

                CONCAT=$(echo $(ls *.ts) | sed -e "s/ /|/g")

                ffmpeg -i "concat:$CONCAT" -c copy -bsf:a aac_adtstoasc output.mp4

                rm *.ts


                This creates intermediate files in an MPEG container and then concatenates them into an MP4.






                share|improve this answer
























                • It's important to note that this script will fail if any of the filenames contain spaces or, in some cases, special characters. For the loop, it's significantly better to use just for f in *.MP4 without using ls. (You should always avoid using ls in scripts for a couple of important reasons; there are better options.) Also, use quotes for variables unless you are certain that there are no spaces or other special characters, so "${f}" (or just "$f") instead of unquoted $f.

                  – Paddy Landau
                  Jun 14 '18 at 14:11











                • CONCAT=$(echo $(ls *.ts) | sed -e "s/ /|/g") doesn't work well with file names that are 1, 2, 3... 10... 20. It ends up parsing them as 1, 10... 2, 20... etc. I suggest CONCAT=$(echo $(ls -v *.ts) | sed -e "s/ /|/g") this will ensure order.

                  – tisaconundrum
                  Nov 16 '18 at 8:05
















                3












                3








                3







                I wrote a little shell script to concat MP4s without transcoding using ffmpeg.



                for f in $(ls *.MP4); do
                ffmpeg -i $f -c copy -bsf:v h264_mp4toannexb -f mpegts $f.ts
                done

                CONCAT=$(echo $(ls *.ts) | sed -e "s/ /|/g")

                ffmpeg -i "concat:$CONCAT" -c copy -bsf:a aac_adtstoasc output.mp4

                rm *.ts


                This creates intermediate files in an MPEG container and then concatenates them into an MP4.






                share|improve this answer













                I wrote a little shell script to concat MP4s without transcoding using ffmpeg.



                for f in $(ls *.MP4); do
                ffmpeg -i $f -c copy -bsf:v h264_mp4toannexb -f mpegts $f.ts
                done

                CONCAT=$(echo $(ls *.ts) | sed -e "s/ /|/g")

                ffmpeg -i "concat:$CONCAT" -c copy -bsf:a aac_adtstoasc output.mp4

                rm *.ts


                This creates intermediate files in an MPEG container and then concatenates them into an MP4.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 7 '18 at 20:26









                RawwrBagRawwrBag

                1313




                1313













                • It's important to note that this script will fail if any of the filenames contain spaces or, in some cases, special characters. For the loop, it's significantly better to use just for f in *.MP4 without using ls. (You should always avoid using ls in scripts for a couple of important reasons; there are better options.) Also, use quotes for variables unless you are certain that there are no spaces or other special characters, so "${f}" (or just "$f") instead of unquoted $f.

                  – Paddy Landau
                  Jun 14 '18 at 14:11











                • CONCAT=$(echo $(ls *.ts) | sed -e "s/ /|/g") doesn't work well with file names that are 1, 2, 3... 10... 20. It ends up parsing them as 1, 10... 2, 20... etc. I suggest CONCAT=$(echo $(ls -v *.ts) | sed -e "s/ /|/g") this will ensure order.

                  – tisaconundrum
                  Nov 16 '18 at 8:05





















                • It's important to note that this script will fail if any of the filenames contain spaces or, in some cases, special characters. For the loop, it's significantly better to use just for f in *.MP4 without using ls. (You should always avoid using ls in scripts for a couple of important reasons; there are better options.) Also, use quotes for variables unless you are certain that there are no spaces or other special characters, so "${f}" (or just "$f") instead of unquoted $f.

                  – Paddy Landau
                  Jun 14 '18 at 14:11











                • CONCAT=$(echo $(ls *.ts) | sed -e "s/ /|/g") doesn't work well with file names that are 1, 2, 3... 10... 20. It ends up parsing them as 1, 10... 2, 20... etc. I suggest CONCAT=$(echo $(ls -v *.ts) | sed -e "s/ /|/g") this will ensure order.

                  – tisaconundrum
                  Nov 16 '18 at 8:05



















                It's important to note that this script will fail if any of the filenames contain spaces or, in some cases, special characters. For the loop, it's significantly better to use just for f in *.MP4 without using ls. (You should always avoid using ls in scripts for a couple of important reasons; there are better options.) Also, use quotes for variables unless you are certain that there are no spaces or other special characters, so "${f}" (or just "$f") instead of unquoted $f.

                – Paddy Landau
                Jun 14 '18 at 14:11





                It's important to note that this script will fail if any of the filenames contain spaces or, in some cases, special characters. For the loop, it's significantly better to use just for f in *.MP4 without using ls. (You should always avoid using ls in scripts for a couple of important reasons; there are better options.) Also, use quotes for variables unless you are certain that there are no spaces or other special characters, so "${f}" (or just "$f") instead of unquoted $f.

                – Paddy Landau
                Jun 14 '18 at 14:11













                CONCAT=$(echo $(ls *.ts) | sed -e "s/ /|/g") doesn't work well with file names that are 1, 2, 3... 10... 20. It ends up parsing them as 1, 10... 2, 20... etc. I suggest CONCAT=$(echo $(ls -v *.ts) | sed -e "s/ /|/g") this will ensure order.

                – tisaconundrum
                Nov 16 '18 at 8:05







                CONCAT=$(echo $(ls *.ts) | sed -e "s/ /|/g") doesn't work well with file names that are 1, 2, 3... 10... 20. It ends up parsing them as 1, 10... 2, 20... etc. I suggest CONCAT=$(echo $(ls -v *.ts) | sed -e "s/ /|/g") this will ensure order.

                – tisaconundrum
                Nov 16 '18 at 8:05













                0














                My script, purely in bash and ffmpeg. Re-encodes files given on a command line into one.



                Requires the files to be of the same resolution. Accepts different metadata rotation, which ffmpeg concat: doesn't.



                rm ffmpeg-concat-output.mkv

                FILE_COUNT=$#
                INPUTS=""
                FILTER=""
                INDEX=0
                for FNAME in $@; do
                echo "Processing ${FNAME}"
                INPUTS="${INPUTS} -i $FNAME"

                if [ -z "${FILTER}" ]; then
                FILTER="[$INDEX:v:0] [$INDEX:a:0]"
                else
                FILTER="${FILTER} [$INDEX:v:0] [$INDEX:a:0]"
                fi
                let INDEX+=1
                done

                COMMAND="ffmpeg ${INPUTS}
                -filter_complex '${FILTER}
                concat=n=${INDEX}:v=1:a=1 [v] [a]'
                -map '[v]' -map '[a]'
                ffmpeg-concat-output.mkv"

                # -af 'volume=15dB' # won't work with -filter_complex

                bash -c "${COMMAND}"





                share|improve this answer






























                  0














                  My script, purely in bash and ffmpeg. Re-encodes files given on a command line into one.



                  Requires the files to be of the same resolution. Accepts different metadata rotation, which ffmpeg concat: doesn't.



                  rm ffmpeg-concat-output.mkv

                  FILE_COUNT=$#
                  INPUTS=""
                  FILTER=""
                  INDEX=0
                  for FNAME in $@; do
                  echo "Processing ${FNAME}"
                  INPUTS="${INPUTS} -i $FNAME"

                  if [ -z "${FILTER}" ]; then
                  FILTER="[$INDEX:v:0] [$INDEX:a:0]"
                  else
                  FILTER="${FILTER} [$INDEX:v:0] [$INDEX:a:0]"
                  fi
                  let INDEX+=1
                  done

                  COMMAND="ffmpeg ${INPUTS}
                  -filter_complex '${FILTER}
                  concat=n=${INDEX}:v=1:a=1 [v] [a]'
                  -map '[v]' -map '[a]'
                  ffmpeg-concat-output.mkv"

                  # -af 'volume=15dB' # won't work with -filter_complex

                  bash -c "${COMMAND}"





                  share|improve this answer




























                    0












                    0








                    0







                    My script, purely in bash and ffmpeg. Re-encodes files given on a command line into one.



                    Requires the files to be of the same resolution. Accepts different metadata rotation, which ffmpeg concat: doesn't.



                    rm ffmpeg-concat-output.mkv

                    FILE_COUNT=$#
                    INPUTS=""
                    FILTER=""
                    INDEX=0
                    for FNAME in $@; do
                    echo "Processing ${FNAME}"
                    INPUTS="${INPUTS} -i $FNAME"

                    if [ -z "${FILTER}" ]; then
                    FILTER="[$INDEX:v:0] [$INDEX:a:0]"
                    else
                    FILTER="${FILTER} [$INDEX:v:0] [$INDEX:a:0]"
                    fi
                    let INDEX+=1
                    done

                    COMMAND="ffmpeg ${INPUTS}
                    -filter_complex '${FILTER}
                    concat=n=${INDEX}:v=1:a=1 [v] [a]'
                    -map '[v]' -map '[a]'
                    ffmpeg-concat-output.mkv"

                    # -af 'volume=15dB' # won't work with -filter_complex

                    bash -c "${COMMAND}"





                    share|improve this answer















                    My script, purely in bash and ffmpeg. Re-encodes files given on a command line into one.



                    Requires the files to be of the same resolution. Accepts different metadata rotation, which ffmpeg concat: doesn't.



                    rm ffmpeg-concat-output.mkv

                    FILE_COUNT=$#
                    INPUTS=""
                    FILTER=""
                    INDEX=0
                    for FNAME in $@; do
                    echo "Processing ${FNAME}"
                    INPUTS="${INPUTS} -i $FNAME"

                    if [ -z "${FILTER}" ]; then
                    FILTER="[$INDEX:v:0] [$INDEX:a:0]"
                    else
                    FILTER="${FILTER} [$INDEX:v:0] [$INDEX:a:0]"
                    fi
                    let INDEX+=1
                    done

                    COMMAND="ffmpeg ${INPUTS}
                    -filter_complex '${FILTER}
                    concat=n=${INDEX}:v=1:a=1 [v] [a]'
                    -map '[v]' -map '[a]'
                    ffmpeg-concat-output.mkv"

                    # -af 'volume=15dB' # won't work with -filter_complex

                    bash -c "${COMMAND}"






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 17 '17 at 10:19









                    derHugo

                    2,29021429




                    2,29021429










                    answered Jun 5 '17 at 5:45









                    Victor SergienkoVictor Sergienko

                    4221616




                    4221616























                        0














                        I created a Python script that, using moviepy, can concatenate also subsegments (useful if you want for example remove some parts from a video).



                        Use it with:



                        vcat -i inputfile1,inputfile2[start-end],... -o <outputfile>





                        share|improve this answer




























                          0














                          I created a Python script that, using moviepy, can concatenate also subsegments (useful if you want for example remove some parts from a video).



                          Use it with:



                          vcat -i inputfile1,inputfile2[start-end],... -o <outputfile>





                          share|improve this answer


























                            0












                            0








                            0







                            I created a Python script that, using moviepy, can concatenate also subsegments (useful if you want for example remove some parts from a video).



                            Use it with:



                            vcat -i inputfile1,inputfile2[start-end],... -o <outputfile>





                            share|improve this answer













                            I created a Python script that, using moviepy, can concatenate also subsegments (useful if you want for example remove some parts from a video).



                            Use it with:



                            vcat -i inputfile1,inputfile2[start-end],... -o <outputfile>






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 2 at 16:37









                            AntonelloAntonello

                            314317




                            314317























                                -1














                                In addition to Maythux's answer, from :




                                A few multimedia containers (MPEG-1, MPEG-2 PS, DV) allow one to concatenate video by merely concatenating the files containing them.




                                I.e. the videos to be concatenated use one of the abovementioned video containers (to which I'll add MPEG-4 Part 14 for personal experience), you could simply:



                                cat video1.ext video2.ext video3.ext > video4.ext





                                share|improve this answer





















                                • 1





                                  I tried this but it only returns the first video as the output. I read somewhere that it doesn't work, though I don't remember the rationale behind this.

                                  – Dhruv Singal
                                  Jun 16 '15 at 11:28











                                • @DhruvSingal Yes, I can confirm this, I've tried this on two MP4 videos with the exact same video / audio encoding and as you I could only browse through the first video. Which seems reasonable, however I'm pretty sure that I've done this before once with a couple of MP4 videos. Perhaps the memory isn't serving well here, or there are other requirements for this to work. I want to research on this since I'm interested also, if I find something I'll update the answer and drop you a comment

                                  – kos
                                  Jun 16 '15 at 11:45











                                • We somehow need to change the metadata at the start of the first video to encompass the entire length of the combined movie, and other stuff probably. Only a few mpeg4 files let me see the metadata..

                                  – Ken Mollerup
                                  Oct 22 '15 at 14:55
















                                -1














                                In addition to Maythux's answer, from :




                                A few multimedia containers (MPEG-1, MPEG-2 PS, DV) allow one to concatenate video by merely concatenating the files containing them.




                                I.e. the videos to be concatenated use one of the abovementioned video containers (to which I'll add MPEG-4 Part 14 for personal experience), you could simply:



                                cat video1.ext video2.ext video3.ext > video4.ext





                                share|improve this answer





















                                • 1





                                  I tried this but it only returns the first video as the output. I read somewhere that it doesn't work, though I don't remember the rationale behind this.

                                  – Dhruv Singal
                                  Jun 16 '15 at 11:28











                                • @DhruvSingal Yes, I can confirm this, I've tried this on two MP4 videos with the exact same video / audio encoding and as you I could only browse through the first video. Which seems reasonable, however I'm pretty sure that I've done this before once with a couple of MP4 videos. Perhaps the memory isn't serving well here, or there are other requirements for this to work. I want to research on this since I'm interested also, if I find something I'll update the answer and drop you a comment

                                  – kos
                                  Jun 16 '15 at 11:45











                                • We somehow need to change the metadata at the start of the first video to encompass the entire length of the combined movie, and other stuff probably. Only a few mpeg4 files let me see the metadata..

                                  – Ken Mollerup
                                  Oct 22 '15 at 14:55














                                -1












                                -1








                                -1







                                In addition to Maythux's answer, from :




                                A few multimedia containers (MPEG-1, MPEG-2 PS, DV) allow one to concatenate video by merely concatenating the files containing them.




                                I.e. the videos to be concatenated use one of the abovementioned video containers (to which I'll add MPEG-4 Part 14 for personal experience), you could simply:



                                cat video1.ext video2.ext video3.ext > video4.ext





                                share|improve this answer















                                In addition to Maythux's answer, from :




                                A few multimedia containers (MPEG-1, MPEG-2 PS, DV) allow one to concatenate video by merely concatenating the files containing them.




                                I.e. the videos to be concatenated use one of the abovementioned video containers (to which I'll add MPEG-4 Part 14 for personal experience), you could simply:



                                cat video1.ext video2.ext video3.ext > video4.ext






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Jun 17 '15 at 6:00









                                Maythux

                                50.6k32169215




                                50.6k32169215










                                answered Jun 16 '15 at 10:49









                                koskos

                                25.4k870120




                                25.4k870120








                                • 1





                                  I tried this but it only returns the first video as the output. I read somewhere that it doesn't work, though I don't remember the rationale behind this.

                                  – Dhruv Singal
                                  Jun 16 '15 at 11:28











                                • @DhruvSingal Yes, I can confirm this, I've tried this on two MP4 videos with the exact same video / audio encoding and as you I could only browse through the first video. Which seems reasonable, however I'm pretty sure that I've done this before once with a couple of MP4 videos. Perhaps the memory isn't serving well here, or there are other requirements for this to work. I want to research on this since I'm interested also, if I find something I'll update the answer and drop you a comment

                                  – kos
                                  Jun 16 '15 at 11:45











                                • We somehow need to change the metadata at the start of the first video to encompass the entire length of the combined movie, and other stuff probably. Only a few mpeg4 files let me see the metadata..

                                  – Ken Mollerup
                                  Oct 22 '15 at 14:55














                                • 1





                                  I tried this but it only returns the first video as the output. I read somewhere that it doesn't work, though I don't remember the rationale behind this.

                                  – Dhruv Singal
                                  Jun 16 '15 at 11:28











                                • @DhruvSingal Yes, I can confirm this, I've tried this on two MP4 videos with the exact same video / audio encoding and as you I could only browse through the first video. Which seems reasonable, however I'm pretty sure that I've done this before once with a couple of MP4 videos. Perhaps the memory isn't serving well here, or there are other requirements for this to work. I want to research on this since I'm interested also, if I find something I'll update the answer and drop you a comment

                                  – kos
                                  Jun 16 '15 at 11:45











                                • We somehow need to change the metadata at the start of the first video to encompass the entire length of the combined movie, and other stuff probably. Only a few mpeg4 files let me see the metadata..

                                  – Ken Mollerup
                                  Oct 22 '15 at 14:55








                                1




                                1





                                I tried this but it only returns the first video as the output. I read somewhere that it doesn't work, though I don't remember the rationale behind this.

                                – Dhruv Singal
                                Jun 16 '15 at 11:28





                                I tried this but it only returns the first video as the output. I read somewhere that it doesn't work, though I don't remember the rationale behind this.

                                – Dhruv Singal
                                Jun 16 '15 at 11:28













                                @DhruvSingal Yes, I can confirm this, I've tried this on two MP4 videos with the exact same video / audio encoding and as you I could only browse through the first video. Which seems reasonable, however I'm pretty sure that I've done this before once with a couple of MP4 videos. Perhaps the memory isn't serving well here, or there are other requirements for this to work. I want to research on this since I'm interested also, if I find something I'll update the answer and drop you a comment

                                – kos
                                Jun 16 '15 at 11:45





                                @DhruvSingal Yes, I can confirm this, I've tried this on two MP4 videos with the exact same video / audio encoding and as you I could only browse through the first video. Which seems reasonable, however I'm pretty sure that I've done this before once with a couple of MP4 videos. Perhaps the memory isn't serving well here, or there are other requirements for this to work. I want to research on this since I'm interested also, if I find something I'll update the answer and drop you a comment

                                – kos
                                Jun 16 '15 at 11:45













                                We somehow need to change the metadata at the start of the first video to encompass the entire length of the combined movie, and other stuff probably. Only a few mpeg4 files let me see the metadata..

                                – Ken Mollerup
                                Oct 22 '15 at 14:55





                                We somehow need to change the metadata at the start of the first video to encompass the entire length of the combined movie, and other stuff probably. Only a few mpeg4 files let me see the metadata..

                                – Ken Mollerup
                                Oct 22 '15 at 14:55


















                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Ask Ubuntu!


                                • 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%2faskubuntu.com%2fquestions%2f637074%2fhow-to-merge-multiple-more-than-two-videos-on-ubuntu%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

                                Mouse cursor on multiple screens with different PPI

                                Agildo Ribeiro

                                Sometime when accessing a menu: “Ubuntu 16.04 has experienced an internal error”