3

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.

2
  • 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
    Dec 20, 2013 at 16:15
  • Sorry. Amended question. H.264 in MP4 containers.
    – Ana
    Dec 20, 2013 at 16:27

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .