How to convert .ts file into a mainstream format losslessly?

Matroska (MKV)

This will stream copy (re-mux) all streams:

ffmpeg -i input -map 0 -c copy output.mkv

The -map 0 option is used to include all streams. Otherwise it will use the default stream selection behavior which would only result in one stream per stream type being selected. Since Matroska can handle most arbitrary streams I included -map 0.

MP4

This will stream copy (re-mux) all streams:

ffmpeg -i input -map 0 -c copy output.mp4
  • If your inputs formats are not compatible with MP4 you will get an error.
  • Your player/device may not support all arbitrary, less common, or legacy formats even if they are supported by MP4.
  • If in doubt re-encode to H.264 + AAC as shown below.

This will re-encode the video to H.264 and stream copy the audio:

ffmpeg -i input.ts -c:v libx264 -c:a copy output.mp4

The next example will re-encode both video and audio:

ffmpeg -i input.ts -c:v libx264 -c:a aac output.mp4

Lossless H.264 example:

ffmpeg -i input.ts -c:v libx264 -crf 0 -c:a copy output.mp4

Lossless files will be huge.

See FFmpeg Wiki: H.264 for more info.


VideoLAN (VLC - http://www.videolan.org/vlc/index.html) will easily convert just about anything into anything.

Give it a shot. It runs on Linux, Windows, and Mac OS X, and has a very user-friendly interface.


As a complement to the other answer by @llogan - as a stream copy is preferable anyway:

I have been using for a long time some commands to extract audio without changing the name of the files, which can be adapted to those presented here, in order to have them integrated into file managers' context menus.

So, for "demuxing and muxing" without changing the name of the file use:

ffmpeg -i "$0" -map 0 -c copy "${0%%.*}".mkv

I have added that to Thunar's custom actions and to FileManager Actions Configuration tool (Nautilus, Nemo, Caja, PCManFM), like so:

sh -c 'ffmpeg -i "$0" -map 0 -c copy "${0%%.*}".mkv' %f

while restricting it to "*.ts" in Thunar and video/mp2t in FileManager Actions.


As for GUI applications, there are some that can process without transcoding, by copying streams into a different container like mkv or mp4.

I use MKVToolNix (output only mkv) and dmMediaConverter (mkv, mp4 and any format supported by ffmpeg).