10

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!

An Dorfer
  • 1,178

8 Answers8

10

Shortest way to concat all .ts into one .ts file : on linux

cat *.ts > all.ts

Shortest way to concatenate all .ts into one .ts file : on Windows (using cmd)

copy /b *.ts all.ts
K14
  • 101
6

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).

Geremia
  • 573
2

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'
1

Best Solution:

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

enter image description here

T.Todua
  • 4,053
1

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).

1

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
merlin2011
  • 2,117
1

Try the following command:

cat video?.ts video??.ts video???.ts  > out.ts
kenorb
  • 26,615
Roadowl
  • 222
0

the topic is old, but you can always find it here on Google. So I use the avidemuxer for all kinds of videos that I want to combine under Linux. It has the option “append”. It is very intuitive to use and has been around forever.