How to join ts files together into mp4 with ffmpeg

codecffmpegvideovlc-media-player

I download a lot of streams since the internet speed is too slow to watch high definition. When I download a stream I find the .m3u8 file which points to the TS files. Then I use the following command:

ffmpeg -i stream.m3u8 vid.mp4

This works. But it takes a really long time because it basically reëncodes everything, even though it's already the right format. To avoid reëncoding I can use this command:

ffmpeg -i stream.m3u8 -vcodec copy -acodec copy vid.mp4

This works fine when I play from start to end without interuption. But When I skip back or forward, vlc has trouble creating an image. It can't properly display for a few seconds. This is very annoying.

My question: How Can I create the video without complete reëncoding, but WITH good vlc rendering at any point?

Best Answer

You're asking ffmpeg to encode the files into mp4 instead joining them into a single stream. You need to concatenate into temp.ts and then convert that into .mp4 with -codec copy.

Also, I believe you need to convert adts to aac in the second step -bsf:a aac_adtstoasc.

Related Question