Converting a bunch of TS video segments into H.264 files

3

0

I have a lot of directories of TS video fragment files that I would like to convert into H.264 in MP4 files. Each directory consists multiple fragments that comprise one single video, and there is a m3u8 index file to sequence all of them.

index.m3u8       
segment1_0_av.ts 
segment2_0_av.ts 
segment3_0_av.ts 
segment4_0_av.ts 
segment5_0_av.ts 
segment6_0_av.ts 
segment7_0_av.ts 
segment8_0_av.ts 
segment9_0_av.ts

I am on a Mac and I can use homebrew to install whatever is necessary. What is a command line that I can use to convert the above into a single H.264 file? A command line would allow me to build a script to auto-convert multiple folders later on.

Ana

Posted 2013-12-20T16:11:05.153

Reputation: 991

TS and H.264 are talking about two different things, video containers(TS) and a video codec (H.264). What exactly do you want as your final format (ie MP4, MOV, AVI, MKV)? – heavyd – 2013-12-20T16:15:42.040

Sorry. Amended question. H.264 in MP4 containers. – Ana – 2013-12-20T16:27:41.493

Answers

2

You need to merge the segments together first, then encode. TS files can be merged as simply as by concatenating them. So try:

$ cat segment*.ts > onefile.ts
$ ffmpeg -i onefile.ts -c:v libx264 -preset medium -tune film -crf 23 \
    -strict experimental -c:a aac -b:a 192k output.mp4

In above example, you obviously need to get "ffmpeg" from homebrew or macports or from OSX binaries that are freely available.

Change "-crf 23" to a lower integer in two-steps 21,19, ... for higher quality, if you're unsatisfied with the results - but the default 23 should be just fine. Don't go lower than 16 though, because that is "practically lossless" for normal human perception standards.

Have fun.

Paxsali

Posted 2013-12-20T16:11:05.153

Reputation: 134