Home » How To » How to Convert .ts to ,mp4 Using FFmpeg

How to Convert .ts to ,mp4 Using FFmpeg

If you have a bunch of .ts (Transport Stream) media files or if you downloaded one from the internet and want to convert it to .mp4 format (MPEG-4), you can use the free and open-source FFmpeg software to do so. In this quick and easy tutorial, I will show you how to convert .ts to .mp4 with FFmpeg in 4 ways. i.e., without re-encoding, lossless, downscaling or upscaling, and batch conversion. Depending on the use case and your requirements, follow the method of your choice.

Before proceeding, ensure you’ve already installed FFmpeg on Windows. If not follow the linked guide and install it.

Convert .ts to .mp4 with FFmpeg Without Re-encoding

If you don’t want to re-encode while converting from TS to MP4 with FFmpeg then use the command given below. It will simply copy the video and audio streams to the MP4 container and preserve the original quality and resolution. Subtitles are not copied.

First, go to where the .ts file is saved in File Explorer, right-click, and choose Open Terminal. Next, run the below command. Don’t forget to replace the input.ts part of the command with the actual .ts file name. Once the conversion is done, the new MP4 file is saved with the name “output.mp4” to the same directory. If you want, you can change the output.mp4 part of the command and give it a custom name.

ffmpeg -i input.ts -c:v copy -c:a copy output.mp4
ffmpeg command to convert ts to mp4 without re-encoding

Let’s break down the command:

  • ffmpeg: This is how you invoke the FFmpeg command line application.
  • -i input.ts: specifies the input file.
  • -c:v copy and -c:a copy: Copies video and audio streams to output without re-encoding.
  • output.mp4: This is the name of the output file.

Batch Convert .ts to .mp4 with FFmpeg

To batch convert TS to MP4 using FFmpeg, we will use a batch script. The script when executed will take files one by one and feed them to FFmpeg to convert. Here’s how to do it.

First, make sure all the .ts files are in a single directory/folder. Next, right-click anywhere in the File Explorer and choose the New > Text document option to create a text file.

create new text file

Double-click on the text file to open it in Notepad. Paste the below code in it and press Ctrl + S to save.

@echo off
for %%i in (*.ts) do (
   ffmpeg -i "%%i" -c:v copy -c:a copy "%%~ni.mp4"
)

Rename the file to “convert_ts_to_mp4.bat”.

batch script file

Double-click on the newly created batch file. It will batch-convert all the .ts files in the folder to .mp4 with FFmpeg. The converted MP4 files are saved to the same directory and with the same name.

Convert .ts to .mp4 with FFmpeg in a Lossless Way

If you want to make sure that no data or quality is lost while converting, you can use lossless encoders libx264 or libx265. Here’s the FFmpeg command to convert .ts to .mp4 in a lossless manner using libx264 encoder (H.264 codec). Do keep in mind that choosing to convert in a lossless way might increase the file size.ffmpeg -i input.ts -c:v libx264 -crf 0 -preset veryfast -c:a copy output.mp4

If you want to use H.265 codec then use the libx265 encoder. Here’s the command for that.

ffmpeg -i input.ts -c:v libx265 -crf 0 -preset veryfast -c:a copy output.mp4
ffmpeg command to convert ts to mp4 losslessly

Let’s break down the command:

  • ffmpeg: This is how you invoke the FFmpeg command line application.
  • -i input.ts: specifies the input file.
  • -c:v libx264 or -c:v libx265: Specifies which codec to use (H.264 or H.265).
  • -crf 0: This flag sets the Constant Rate Factor (CRF) to 0. This is what determines the lossless quality.
  • -preset veryfast: This is the default encoding preset and offers a good balance between encoding speed and file size.
  • -c:a copy: Copies the audio stream from input to output file with re-encoding.

Upscale or Downscale .ts to .mp4 with FFmpeg

While converting, you can also upscale or download the media files. For example, if you have a 4K .ts file and want to watch it on a tablet or mobile phone, you might want to downscale it to 1080P while converting it to MP4. This makes it easier on the device and reduces battery drain.

To upscale or downscale a video while converting .ts to .mp4, use the below command. Don’t forget to change the input file name and video resolution to upscale or downscale.

ffmpeg -i input.ts -c:v libx264 -crf 0 -preset veryfast -vf "scale=1920:1080" -c:a copy output.mp4

Note: Upscaling a video resolution doesn’t increase the video quality. Additionally, it will also increase the file size.

ffmpeg command to convert ts to mp4 and upscale or downscale

Let’s break down the command:

  • ffmpeg: This is how you invoke the FFmpeg command line application.
  • -i input.ts: specifies the input file.
  • -c:v libx264 or -c:v libx265: Specifies which codec to use (H.264 or H.265).
  • -crf 0: This flag sets the Constant Rate Factor (CRF) to 0. This is what determines the lossless quality.
  • -preset veryfast: This is the default encoding preset and offers a good balance between encoding speed and file size.
  • -vf "scale=1920:1080": This command scales the output video to a given video resolution. In this case, that resolution is 1920 x 1080 pixels (Full HD). You can use any resolution you want. For instance, if the input video is 4K then scaling it to 1080P will downscale the video resolution. Conversely, to upscale a 1080P video to 4K, you’d modify the command to -vf "scale=3840:2160".
  • -c:a copy: Copies the audio stream from input to output file with re-encoding.

Wrapping Up

As you can see, it is pretty easy to convert a TS file to MP4 using FFmpeg.

If you want FFmpeg to convert without re-encoding then use the first command. To batch convert multiple .ts files at once, follow the batch conversion method shown in the second section. Alternatively, to preserve the video quality at the expense of encoding time and file size, follow the lossless method shown in the third section. To upscale or downscale the output video while converting, follow the fourth method.

I hope this tutorial helped you convert all your TS files to MP4 using FFmpeg.

If you are stuck or need help, send an email, and I will try to help as much as possible.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top