Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


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.

share|improve this question
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 '13 at 16:15
Sorry. Amended question. H.264 in MP4 containers. – Ana Dec 20 '13 at 16:27

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.

share|improve this answer

You must log in to answer this question.

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