How to Convert SRT to TX3G for MP4 Using FFmpeg

This article provides a quick guide on how to convert SubRip (.srt) subtitle files into the timed text (tx3g) format and embed them directly into an MP4 video file using FFmpeg. You will learn the exact command-line syntax required to perform this conversion, enabling native subtitle compatibility for Apple devices, QuickTime, and various HTML5 web players.

The Standard Conversion Command

In FFmpeg, the MPEG-4 Timed Text format (tx3g) is referred to by its codec name, mov_text. To convert an external SRT file and embed it into an MP4 container as a tx3g subtitle track, run the following command in your terminal:

ffmpeg -i input.mp4 -i subtitle.srt -c:v copy -c:a copy -c:s mov_text output.mp4

Command Breakdown

Adding Language Metadata

To ensure media players recognize the language of your subtitle track, you should define the language metadata using an ISO 639-2 three-letter code (e.g., eng for English, spa for Spanish).

ffmpeg -i input.mp4 -i subtitle.srt -c copy -c:s mov_text -metadata:s:s:0 language=eng output.mp4

In this command, -metadata:s:s:0 language=eng targets the first subtitle stream (s:s:0) and sets its language to English.

Merging Multiple SRT Subtitles into One MP4

If you need to add multiple subtitle tracks in different languages to a single MP4 file, you can map them using the -map option:

ffmpeg -i input.mp4 -i english.srt -i spanish.srt \
-map 0:v -map 0:a -map 1 -map 2 \
-c:v copy -c:a copy -c:s mov_text \
-metadata:s:s:0 language=eng -metadata:s:s:1 language=spa \
output.mp4

This mapping structure ensures that the video and audio from the first input (-map 0:v and -map 0:a), the English subtitles (-map 1), and the Spanish subtitles (-map 2) are all properly packaged into the output file.