merge/join/concatenate hundreds of ts files into one ts file











up vote
3
down vote

favorite












Downloading a video stream with curl, I ended up with ~400 *.ts files, each about 1MB in size. They are sequentially numbered video1.ts, video2.ts, ...video400.ts. I now need to concatenate them into one file, obviously in the right order (so video10.ts should be followed by video11.ts and not video110.ts).



I've tried to come up with something like "for i in *.ts; do ...." but I just can't figure it out. Also ffmepg and avconv are too complicated for me.



Who knows how to join these 400 files in the right oreder, into a new file? Thx!










share|improve this question




























    up vote
    3
    down vote

    favorite












    Downloading a video stream with curl, I ended up with ~400 *.ts files, each about 1MB in size. They are sequentially numbered video1.ts, video2.ts, ...video400.ts. I now need to concatenate them into one file, obviously in the right order (so video10.ts should be followed by video11.ts and not video110.ts).



    I've tried to come up with something like "for i in *.ts; do ...." but I just can't figure it out. Also ffmepg and avconv are too complicated for me.



    Who knows how to join these 400 files in the right oreder, into a new file? Thx!










    share|improve this question


























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      Downloading a video stream with curl, I ended up with ~400 *.ts files, each about 1MB in size. They are sequentially numbered video1.ts, video2.ts, ...video400.ts. I now need to concatenate them into one file, obviously in the right order (so video10.ts should be followed by video11.ts and not video110.ts).



      I've tried to come up with something like "for i in *.ts; do ...." but I just can't figure it out. Also ffmepg and avconv are too complicated for me.



      Who knows how to join these 400 files in the right oreder, into a new file? Thx!










      share|improve this question















      Downloading a video stream with curl, I ended up with ~400 *.ts files, each about 1MB in size. They are sequentially numbered video1.ts, video2.ts, ...video400.ts. I now need to concatenate them into one file, obviously in the right order (so video10.ts should be followed by video11.ts and not video110.ts).



      I've tried to come up with something like "for i in *.ts; do ...." but I just can't figure it out. Also ffmepg and avconv are too complicated for me.



      Who knows how to join these 400 files in the right oreder, into a new file? Thx!







      ubuntu video merge






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 28 '14 at 19:10









      An Dorfer

      1,2032713




      1,2032713










      asked Oct 22 '13 at 13:36









      user140222

      2613




      2613






















          6 Answers
          6






          active

          oldest

          votes

















          up vote
          1
          down vote













          What sort of does the trick:



          for i in `seq 1 400`; do cat "video$i.ts" >> newvideo.ts; done


          but now the audio is out of sync by ~0.5s and there are ~0.5s silences every few seconds (presumably when fragments are glued together).






          share|improve this answer




























            up vote
            1
            down vote













            This is an old question but I hope the answer may add value for others.



            Based on this reference, the following script will do the job, assuming ffmpeg 1.1 and later.



            #!/bin/bash

            for i in `seq 0 $totalNumberOfTsFiles`; do echo file "'${i}.ts'" >> Input.txt ; done
            /home/hq6/bin/ffmpeg-2.3.3/ffmpeg -f concat -i Input.txt -c copy output.ts





            share|improve this answer

















            • 1




              The entire for loop can probably be replaced by something like seq -f '%g.ts' 0 $totalNumberOfTsFiles for a similar result with a much cleaner command line.
              – a CVn
              Aug 28 '15 at 19:12










            • James Ivey: If you have a new idea for a different way to solve this problem, don’t try to post it in a comment (and don’t edit it into somebody else’s answer); post it as a new answer (in the “Your Answer” box at the bottom of the page). In case you’ve forgotten what you wanted to submit, you can review it here. Notes: (1) When the output of ls is a pipe, it uses -1 mode automatically. You can see this by running plain ls and then ls | cat. (2) ls sorts its output by name unless you tell it not to, so you don’t need ls | sort.
              – Scott
              Oct 29 '17 at 18:09


















            up vote
            0
            down vote













            Try the following command:



            cat video?.ts video??.ts video???.ts  > out.ts





            share|improve this answer























            • The duration of out.ts will likely be that of the first video.
              – Geremia
              Feb 4 at 1:16


















            up vote
            0
            down vote













            Best Solution:



            Download TSSplitter, click "JOIN" tab and drag all files into the window!



            enter image description here






            share|improve this answer




























              up vote
              0
              down vote













              filenames="`ls -rt1 $input | tr 'n' '|' | sed '$ s/.$//'`"



              ffmpeg -i "concat:$filenames" -c copy out.ts,



              where $input is the filename(s) or escaped regexp (e.g., *.ts).






              share|improve this answer




























                up vote
                0
                down vote













                All the answers to this question that mislead readers to concatenate the TS files before running ffmpeg are incorrect. To ensure the audio and video do not fall out of sync during the assembly of the mp4 stream, the poorly documented but important "-f concat" feature of ffmpeg should be used.



                    delimiterBeforeFileNumber="-"
                ls |egrep '[.]ts$'
                |sort "-t$delimiterBeforeFileNumber" -k2,2n
                |sed -r "s/(.*)/file '1'/" >ts.files.txt

                ffmpeg -f concat -i ts.files.txt -c copy tsw.014.ts.mp4


                The two preparatory lines of code just create a file containing a list of TS files in this line format, which is used by ffmpeg like a playlist.



                    file 'seg-37-a.ts'





                share|improve this answer





















                  Your Answer








                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "3"
                  };
                  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%2fsuperuser.com%2fquestions%2f663687%2fmerge-join-concatenate-hundreds-of-ts-files-into-one-ts-file%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  6 Answers
                  6






                  active

                  oldest

                  votes








                  6 Answers
                  6






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  1
                  down vote













                  What sort of does the trick:



                  for i in `seq 1 400`; do cat "video$i.ts" >> newvideo.ts; done


                  but now the audio is out of sync by ~0.5s and there are ~0.5s silences every few seconds (presumably when fragments are glued together).






                  share|improve this answer

























                    up vote
                    1
                    down vote













                    What sort of does the trick:



                    for i in `seq 1 400`; do cat "video$i.ts" >> newvideo.ts; done


                    but now the audio is out of sync by ~0.5s and there are ~0.5s silences every few seconds (presumably when fragments are glued together).






                    share|improve this answer























                      up vote
                      1
                      down vote










                      up vote
                      1
                      down vote









                      What sort of does the trick:



                      for i in `seq 1 400`; do cat "video$i.ts" >> newvideo.ts; done


                      but now the audio is out of sync by ~0.5s and there are ~0.5s silences every few seconds (presumably when fragments are glued together).






                      share|improve this answer












                      What sort of does the trick:



                      for i in `seq 1 400`; do cat "video$i.ts" >> newvideo.ts; done


                      but now the audio is out of sync by ~0.5s and there are ~0.5s silences every few seconds (presumably when fragments are glued together).







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Oct 23 '13 at 13:43









                      user140222

                      2613




                      2613
























                          up vote
                          1
                          down vote













                          This is an old question but I hope the answer may add value for others.



                          Based on this reference, the following script will do the job, assuming ffmpeg 1.1 and later.



                          #!/bin/bash

                          for i in `seq 0 $totalNumberOfTsFiles`; do echo file "'${i}.ts'" >> Input.txt ; done
                          /home/hq6/bin/ffmpeg-2.3.3/ffmpeg -f concat -i Input.txt -c copy output.ts





                          share|improve this answer

















                          • 1




                            The entire for loop can probably be replaced by something like seq -f '%g.ts' 0 $totalNumberOfTsFiles for a similar result with a much cleaner command line.
                            – a CVn
                            Aug 28 '15 at 19:12










                          • James Ivey: If you have a new idea for a different way to solve this problem, don’t try to post it in a comment (and don’t edit it into somebody else’s answer); post it as a new answer (in the “Your Answer” box at the bottom of the page). In case you’ve forgotten what you wanted to submit, you can review it here. Notes: (1) When the output of ls is a pipe, it uses -1 mode automatically. You can see this by running plain ls and then ls | cat. (2) ls sorts its output by name unless you tell it not to, so you don’t need ls | sort.
                            – Scott
                            Oct 29 '17 at 18:09















                          up vote
                          1
                          down vote













                          This is an old question but I hope the answer may add value for others.



                          Based on this reference, the following script will do the job, assuming ffmpeg 1.1 and later.



                          #!/bin/bash

                          for i in `seq 0 $totalNumberOfTsFiles`; do echo file "'${i}.ts'" >> Input.txt ; done
                          /home/hq6/bin/ffmpeg-2.3.3/ffmpeg -f concat -i Input.txt -c copy output.ts





                          share|improve this answer

















                          • 1




                            The entire for loop can probably be replaced by something like seq -f '%g.ts' 0 $totalNumberOfTsFiles for a similar result with a much cleaner command line.
                            – a CVn
                            Aug 28 '15 at 19:12










                          • James Ivey: If you have a new idea for a different way to solve this problem, don’t try to post it in a comment (and don’t edit it into somebody else’s answer); post it as a new answer (in the “Your Answer” box at the bottom of the page). In case you’ve forgotten what you wanted to submit, you can review it here. Notes: (1) When the output of ls is a pipe, it uses -1 mode automatically. You can see this by running plain ls and then ls | cat. (2) ls sorts its output by name unless you tell it not to, so you don’t need ls | sort.
                            – Scott
                            Oct 29 '17 at 18:09













                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          This is an old question but I hope the answer may add value for others.



                          Based on this reference, the following script will do the job, assuming ffmpeg 1.1 and later.



                          #!/bin/bash

                          for i in `seq 0 $totalNumberOfTsFiles`; do echo file "'${i}.ts'" >> Input.txt ; done
                          /home/hq6/bin/ffmpeg-2.3.3/ffmpeg -f concat -i Input.txt -c copy output.ts





                          share|improve this answer












                          This is an old question but I hope the answer may add value for others.



                          Based on this reference, the following script will do the job, assuming ffmpeg 1.1 and later.



                          #!/bin/bash

                          for i in `seq 0 $totalNumberOfTsFiles`; do echo file "'${i}.ts'" >> Input.txt ; done
                          /home/hq6/bin/ffmpeg-2.3.3/ffmpeg -f concat -i Input.txt -c copy output.ts






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 15 '14 at 6:14









                          merlin2011

                          67431022




                          67431022








                          • 1




                            The entire for loop can probably be replaced by something like seq -f '%g.ts' 0 $totalNumberOfTsFiles for a similar result with a much cleaner command line.
                            – a CVn
                            Aug 28 '15 at 19:12










                          • James Ivey: If you have a new idea for a different way to solve this problem, don’t try to post it in a comment (and don’t edit it into somebody else’s answer); post it as a new answer (in the “Your Answer” box at the bottom of the page). In case you’ve forgotten what you wanted to submit, you can review it here. Notes: (1) When the output of ls is a pipe, it uses -1 mode automatically. You can see this by running plain ls and then ls | cat. (2) ls sorts its output by name unless you tell it not to, so you don’t need ls | sort.
                            – Scott
                            Oct 29 '17 at 18:09














                          • 1




                            The entire for loop can probably be replaced by something like seq -f '%g.ts' 0 $totalNumberOfTsFiles for a similar result with a much cleaner command line.
                            – a CVn
                            Aug 28 '15 at 19:12










                          • James Ivey: If you have a new idea for a different way to solve this problem, don’t try to post it in a comment (and don’t edit it into somebody else’s answer); post it as a new answer (in the “Your Answer” box at the bottom of the page). In case you’ve forgotten what you wanted to submit, you can review it here. Notes: (1) When the output of ls is a pipe, it uses -1 mode automatically. You can see this by running plain ls and then ls | cat. (2) ls sorts its output by name unless you tell it not to, so you don’t need ls | sort.
                            – Scott
                            Oct 29 '17 at 18:09








                          1




                          1




                          The entire for loop can probably be replaced by something like seq -f '%g.ts' 0 $totalNumberOfTsFiles for a similar result with a much cleaner command line.
                          – a CVn
                          Aug 28 '15 at 19:12




                          The entire for loop can probably be replaced by something like seq -f '%g.ts' 0 $totalNumberOfTsFiles for a similar result with a much cleaner command line.
                          – a CVn
                          Aug 28 '15 at 19:12












                          James Ivey: If you have a new idea for a different way to solve this problem, don’t try to post it in a comment (and don’t edit it into somebody else’s answer); post it as a new answer (in the “Your Answer” box at the bottom of the page). In case you’ve forgotten what you wanted to submit, you can review it here. Notes: (1) When the output of ls is a pipe, it uses -1 mode automatically. You can see this by running plain ls and then ls | cat. (2) ls sorts its output by name unless you tell it not to, so you don’t need ls | sort.
                          – Scott
                          Oct 29 '17 at 18:09




                          James Ivey: If you have a new idea for a different way to solve this problem, don’t try to post it in a comment (and don’t edit it into somebody else’s answer); post it as a new answer (in the “Your Answer” box at the bottom of the page). In case you’ve forgotten what you wanted to submit, you can review it here. Notes: (1) When the output of ls is a pipe, it uses -1 mode automatically. You can see this by running plain ls and then ls | cat. (2) ls sorts its output by name unless you tell it not to, so you don’t need ls | sort.
                          – Scott
                          Oct 29 '17 at 18:09










                          up vote
                          0
                          down vote













                          Try the following command:



                          cat video?.ts video??.ts video???.ts  > out.ts





                          share|improve this answer























                          • The duration of out.ts will likely be that of the first video.
                            – Geremia
                            Feb 4 at 1:16















                          up vote
                          0
                          down vote













                          Try the following command:



                          cat video?.ts video??.ts video???.ts  > out.ts





                          share|improve this answer























                          • The duration of out.ts will likely be that of the first video.
                            – Geremia
                            Feb 4 at 1:16













                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          Try the following command:



                          cat video?.ts video??.ts video???.ts  > out.ts





                          share|improve this answer














                          Try the following command:



                          cat video?.ts video??.ts video???.ts  > out.ts






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Aug 28 '15 at 20:17









                          kenorb

                          10.6k1577109




                          10.6k1577109










                          answered Aug 28 '15 at 18:44









                          Roadowl

                          9215




                          9215












                          • The duration of out.ts will likely be that of the first video.
                            – Geremia
                            Feb 4 at 1:16


















                          • The duration of out.ts will likely be that of the first video.
                            – Geremia
                            Feb 4 at 1:16
















                          The duration of out.ts will likely be that of the first video.
                          – Geremia
                          Feb 4 at 1:16




                          The duration of out.ts will likely be that of the first video.
                          – Geremia
                          Feb 4 at 1:16










                          up vote
                          0
                          down vote













                          Best Solution:



                          Download TSSplitter, click "JOIN" tab and drag all files into the window!



                          enter image description here






                          share|improve this answer

























                            up vote
                            0
                            down vote













                            Best Solution:



                            Download TSSplitter, click "JOIN" tab and drag all files into the window!



                            enter image description here






                            share|improve this answer























                              up vote
                              0
                              down vote










                              up vote
                              0
                              down vote









                              Best Solution:



                              Download TSSplitter, click "JOIN" tab and drag all files into the window!



                              enter image description here






                              share|improve this answer












                              Best Solution:



                              Download TSSplitter, click "JOIN" tab and drag all files into the window!



                              enter image description here







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Apr 21 '17 at 16:23









                              T.Todua

                              1,40731628




                              1,40731628






















                                  up vote
                                  0
                                  down vote













                                  filenames="`ls -rt1 $input | tr 'n' '|' | sed '$ s/.$//'`"



                                  ffmpeg -i "concat:$filenames" -c copy out.ts,



                                  where $input is the filename(s) or escaped regexp (e.g., *.ts).






                                  share|improve this answer

























                                    up vote
                                    0
                                    down vote













                                    filenames="`ls -rt1 $input | tr 'n' '|' | sed '$ s/.$//'`"



                                    ffmpeg -i "concat:$filenames" -c copy out.ts,



                                    where $input is the filename(s) or escaped regexp (e.g., *.ts).






                                    share|improve this answer























                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote









                                      filenames="`ls -rt1 $input | tr 'n' '|' | sed '$ s/.$//'`"



                                      ffmpeg -i "concat:$filenames" -c copy out.ts,



                                      where $input is the filename(s) or escaped regexp (e.g., *.ts).






                                      share|improve this answer












                                      filenames="`ls -rt1 $input | tr 'n' '|' | sed '$ s/.$//'`"



                                      ffmpeg -i "concat:$filenames" -c copy out.ts,



                                      where $input is the filename(s) or escaped regexp (e.g., *.ts).







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Feb 4 at 1:20









                                      Geremia

                                      190116




                                      190116






















                                          up vote
                                          0
                                          down vote













                                          All the answers to this question that mislead readers to concatenate the TS files before running ffmpeg are incorrect. To ensure the audio and video do not fall out of sync during the assembly of the mp4 stream, the poorly documented but important "-f concat" feature of ffmpeg should be used.



                                              delimiterBeforeFileNumber="-"
                                          ls |egrep '[.]ts$'
                                          |sort "-t$delimiterBeforeFileNumber" -k2,2n
                                          |sed -r "s/(.*)/file '1'/" >ts.files.txt

                                          ffmpeg -f concat -i ts.files.txt -c copy tsw.014.ts.mp4


                                          The two preparatory lines of code just create a file containing a list of TS files in this line format, which is used by ffmpeg like a playlist.



                                              file 'seg-37-a.ts'





                                          share|improve this answer

























                                            up vote
                                            0
                                            down vote













                                            All the answers to this question that mislead readers to concatenate the TS files before running ffmpeg are incorrect. To ensure the audio and video do not fall out of sync during the assembly of the mp4 stream, the poorly documented but important "-f concat" feature of ffmpeg should be used.



                                                delimiterBeforeFileNumber="-"
                                            ls |egrep '[.]ts$'
                                            |sort "-t$delimiterBeforeFileNumber" -k2,2n
                                            |sed -r "s/(.*)/file '1'/" >ts.files.txt

                                            ffmpeg -f concat -i ts.files.txt -c copy tsw.014.ts.mp4


                                            The two preparatory lines of code just create a file containing a list of TS files in this line format, which is used by ffmpeg like a playlist.



                                                file 'seg-37-a.ts'





                                            share|improve this answer























                                              up vote
                                              0
                                              down vote










                                              up vote
                                              0
                                              down vote









                                              All the answers to this question that mislead readers to concatenate the TS files before running ffmpeg are incorrect. To ensure the audio and video do not fall out of sync during the assembly of the mp4 stream, the poorly documented but important "-f concat" feature of ffmpeg should be used.



                                                  delimiterBeforeFileNumber="-"
                                              ls |egrep '[.]ts$'
                                              |sort "-t$delimiterBeforeFileNumber" -k2,2n
                                              |sed -r "s/(.*)/file '1'/" >ts.files.txt

                                              ffmpeg -f concat -i ts.files.txt -c copy tsw.014.ts.mp4


                                              The two preparatory lines of code just create a file containing a list of TS files in this line format, which is used by ffmpeg like a playlist.



                                                  file 'seg-37-a.ts'





                                              share|improve this answer












                                              All the answers to this question that mislead readers to concatenate the TS files before running ffmpeg are incorrect. To ensure the audio and video do not fall out of sync during the assembly of the mp4 stream, the poorly documented but important "-f concat" feature of ffmpeg should be used.



                                                  delimiterBeforeFileNumber="-"
                                              ls |egrep '[.]ts$'
                                              |sort "-t$delimiterBeforeFileNumber" -k2,2n
                                              |sed -r "s/(.*)/file '1'/" >ts.files.txt

                                              ffmpeg -f concat -i ts.files.txt -c copy tsw.014.ts.mp4


                                              The two preparatory lines of code just create a file containing a list of TS files in this line format, which is used by ffmpeg like a playlist.



                                                  file 'seg-37-a.ts'






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Nov 23 at 7:39









                                              Douglas Daseeco

                                              1011




                                              1011






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Super User!


                                                  • 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%2fsuperuser.com%2fquestions%2f663687%2fmerge-join-concatenate-hundreds-of-ts-files-into-one-ts-file%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

                                                  Сан-Квентин

                                                  8-я гвардейская общевойсковая армия

                                                  Алькесар