merge/join/concatenate hundreds of ts files into one ts file
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!
Solution 1:
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
Solution 2:
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).
Solution 3:
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).