how to join ts files together into mp4 with ffmpeg?

1

1

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?

Nicky Smits

Posted 2015-01-26T19:02:57.987

Reputation: 245

Do you specifically need the MP4 container format? Please show the complete console output from your second command. – llogan – 2015-01-26T19:09:57.047

I do not specifically need the mp4 container. An MKV would siffice. That doesnt get rid of the problem though – Nicky Smits – 2015-01-26T19:29:42.550

Answers

3

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.

hdezela

Posted 2015-01-26T19:02:57.987

Reputation: 141

I tried this and the result is not satisfying. The audio never had any problems in the MKV format, just the video stream had hiccups. And with this, I get the same while having to perform three seperate steps. – Nicky Smits – 2015-02-28T07:28:22.410

0

If you do not re-encode, you might not be able to change the key frames etc of the video, resulting to the behavior you describe. You could try however something like

ffmpeg -i stream.m3u8 -codec:v" "libx264" "-preset" "ultrafast" vid.mp4

Keep in mind that what you gain in speed you lose in quality, so "fast" might be better...

ntg

Posted 2015-01-26T19:02:57.987

Reputation: 207

-1

See my variant with ffmpeg mp4joiner

Screenshot

Bogdik

Posted 2015-01-26T19:02:57.987

Reputation: 1

2

It might be worth adding a little more than a screenshot - here's a guide on how to recommend software. I also noticed your username and the name on the github account is the same - revealing your affliation to the software is necessary,

– Journeyman Geek – 2018-03-24T12:17:59.947