Adding Soft Subtitles to MP4 with FFmpeg (Without Burning Them In)
To add SRT subtitles to an MP4 without burning them in, add them as a subtitle track with -c:s mov_text. The video and audio are copied without re-encoding, so the process finishes quickly. Use this method when you want soft subtitles that the player can turn on and off, or switch between Japanese and English.
With MP4, -c copy alone either fails with an error or silently drops the subtitles. I checked the correct command and the cases where things go wrong, in order.
The test environment was Ubuntu 24.04.5 with FFmpeg 6.1.1 (Ubuntu package 6.1.1-3ubuntu5). The video was an 8-second MP4 (H.264 and AAC) made from FFmpeg's test video and audio sources. The subtitles were SRT and ASS files I wrote myself. I used Chromium 158 for the browser checks. I did not test how Safari, VLC, or other players display the subtitle track (its name or language), and I did not test switching on the default iPhone or Android players.
- 1. Adding an SRT as a mov_text subtitle track
- 2.
-c copyalone does not add subtitles - 3. Write the language as a three-letter code
- 4. Adding both Japanese and English subtitles
- 5. A Shift_JIS SRT produces an MP4 even when errors appear
- 6. Overlapping subtitles: the earlier one gets cut short
- 7. In Chromium's video element, subtitles inside the MP4 did not appear in textTracks
Adding an SRT as a mov_text subtitle track
The subtitle file I used is this SRT (ja.srt).
1
00:00:01,000 --> 00:00:03,000
猫が窓の外を見ています
2
00:00:03,500 --> 00:00:05,500
鳥が飛んできました
しっぽが揺れています
3
00:00:06,000 --> 00:00:07,500
<i>Hello</i>, subtitles!
This command adds the subtitles to the video (src.mp4).
ffmpeg -i src.mp4 -i ja.srt -map 0 -map 1 -c:v copy -c:a copy -c:s mov_text -metadata:s:s:0 language=jpn soft.mp4
The options mean the following:
-map 0 -map 1: Put all streams from the first input (the video) and the second input (the subtitles) into the output.-c:v copy -c:a copy: Copy the video and audio without re-encoding them.-c:s mov_text: Convert the subtitles to mov_text, the format MP4 supports.-metadata:s:s:0 language=jpn: Set the language of the first subtitle in the output to Japanese (jpn).
The console output showed the video and audio being copied, and the SRT being converted to mov_text.
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Stream #1:0 -> #0:2 (subrip (srt) -> mov_text (native))
When I inspected the output MP4 with ffprobe, the subtitles appeared as the third stream.
ffprobe -hide_banner soft.mp4
Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 3016 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 kb/s (default)
Stream #0:2[0x3](jpn): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
(I extracted only the stream lines from the actual output.)
The file size went from 3,096,063 bytes to 3,096,783 bytes, an increase of 720 bytes. Across three runs, processing took 0.048 to 0.050 seconds. The video and audio data were identical to the original video, down to the MD5 hash.
I also extracted the subtitles to check their content. When I exported the mov_text back to SRT, the timestamps, the two-line subtitle, and the italic <i> tag all matched the original SRT. Only the line endings and the trailing blank line differed. For extracting subtitles, see the separate article "How to extract subtitles embedded in a video with FFmpeg."
-c copy alone does not add subtitles
If you write -c copy as you would when copying video or audio, the subtitles are not added to the MP4. I found three ways this goes wrong.
The first is selecting the subtitles with -map and then using -c copy to copy them too.
ffmpeg -i src.mp4 -i ja.srt -map 0 -map 1 -c copy fail_copy.mp4
[mp4 @ 0x55be1f832500] Could not find tag for codec subrip in stream #2, codec not currently supported in container
[out#0/mp4 @ 0x55be1f796b00] Could not write header (incorrect codec parameters ?): Invalid argument
Error opening output file fail_copy.mp4.
Error opening output files: Invalid argument
(I extracted only the error lines. The other errors in this article are the same.) SRT (subrip) cannot be stored in an MP4 as-is, so FFmpeg stops. The exit code was 234.
The second is copying the video and audio but not specifying a subtitle format.
ffmpeg -i src.mp4 -i ja.srt -map 0 -map 1 -c:v copy -c:a copy fail_noc.mp4
[sost#0:2 @ 0x560be3ed61c0] Automatic encoder selection failed Default encoder for format mp4 (codec none) is probably disabled. Please choose an encoder manually.
[sost#0:2 @ 0x560be3ed61c0] Error selecting an encoder
Error opening output file fail_noc.mp4.
Error opening output files: Encoder not found
FFmpeg could not automatically select an encoder for the subtitles and stopped. The exit code was 8. The stream selection section of the ffmpeg command documentation also says that the MP4 format has no default subtitle encoder registered. So with MP4, you need to specify -c:s mov_text yourself.
The third is the hardest to notice: using -c copy without -map.
ffmpeg -i src.mp4 -i ja.srt -c copy nomap.mp4
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
There was no error and the exit code was 0, but the subtitles were not selected. The output MP4 contained only the video and audio. As the same documentation explains, without -map, subtitles are selected automatically only if the output format has a default subtitle encoder or if you specify a subtitle encoder. In fact, when I used -c:v copy -c:a copy -c:s mov_text without -map, the subtitles were selected. However, I use -map in this article so it is clear which subtitles are selected.
I also tried adding the subtitles to the MP4 in WebVTT format (-c:s webvtt). It failed with the same kind of error as the first case (Could not find tag for codec webvtt). Of the formats I tried (SRT copied as-is, WebVTT, and mov_text), only mov_text went into the MP4.
Write the language as a three-letter code
You can record which language each subtitle track is in. I changed the value after -metadata:s:s:0 language= and checked what remained in the MP4.
| Value written | Language kept in MP4 |
|---|---|
jpn |
jpn |
ja |
none |
jp |
none |
japanese |
jap |
Two-letter codes like ja were dropped with no error or warning. In ffprobe output, the language part such as (jpn) disappeared. japanese kept only its first three letters, becoming jap, a different value. In the FFmpeg 6.1.1 source (ff_mov_iso639_to_lang in libavformat/isom.c), the language written to an MP4 is built by treating the first three characters as lowercase letters. If the value is shorter than three characters, as with ja, it cannot be converted to a language code. Use three-letter codes such as jpn for Japanese or eng for English.
I also added -metadata:s:s:0 title=Japanese to name the subtitle track, but the name was not kept in the MP4. The description that did persist was handler_name. When I set -metadata:s:s:0 handler_name=日本語, ffprobe showed handler_name=日本語.
Adding both Japanese and English subtitles
To add two subtitle tracks, add one more input and one more -map, and set a language for each.
ffmpeg -i src.mp4 -i ja.srt -i en.srt -map 0 -map 1 -map 2 -c:v copy -c:a copy -c:s mov_text -metadata:s:s:0 language=jpn -metadata:s:s:1 language=eng multi.mp4
ffprobe -v error -select_streams s -show_entries stream=index:stream_tags=language:stream_disposition=default -of compact multi.mp4
stream|index=2|disposition:default=1|tag:language=jpn
stream|index=3|disposition:default=0|tag:language=eng
default=1 marks the subtitle set as the default track. Even without specifying anything, the first Japanese subtitle became the default. As the -disposition section of the documentation says, when no -disposition is given, there are several streams of the same type, and none is marked as default, FFmpeg makes the first one the default.
To make English the default, swap them with -disposition.
ffmpeg -i src.mp4 -i ja.srt -i en.srt -map 0 -map 1 -map 2 -c:v copy -c:a copy -c:s mov_text -metadata:s:s:0 language=jpn -metadata:s:s:1 language=eng -disposition:s:0 0 -disposition:s:1 default multi_en.mp4
stream|index=2|disposition:default=0|tag:language=jpn
stream|index=3|disposition:default=1|tag:language=eng
You can also add a Japanese subtitle to an MP4 that already has an English one. Because -map 0 keeps the original subtitles, the new one becomes the second subtitle in the output. The language index also changes to s:s:1.
ffmpeg -i en_only.mp4 -i ja.srt -map 0 -map 1 -c:v copy -c:a copy -c:s mov_text -metadata:s:s:1 language=jpn add.mp4
stream|index=2|tag:language=eng
stream|index=3|tag:language=jpn
A Shift_JIS SRT produces an MP4 even when errors appear
When I added an SRT saved in Shift_JIS (CP932) as-is, the following messages appeared (progress output omitted).
[srt @ 0x5632f2e9db00] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[sist#1:0/subrip @ 0x5632f2e9d980] Error decoding subtitles: Invalid data found when processing input
Even so, the exit code was 0 and the MP4 was created. When I extracted the subtitles from it, only the third subtitle, the English-only one, remained. The two Japanese subtitles were gone.
1
00:00:06,000 --> 00:00:07,500
<i>Hello</i>, subtitles!
Use sub_charenc (from the codec options documentation) to specify the subtitle file's character encoding. It is an input option, so put it before the -i for the subtitle file.
ffmpeg -i src.mp4 -sub_charenc CP932 -i ja_sjis.srt -map 0 -map 1 -c:v copy -c:a copy -c:s mov_text sjis_ok.mp4
The subtitles extracted from this MP4 matched the ones made from the UTF-8 SRT. If you process many videos in a script and only check the exit code, you may not notice missing subtitles, so also check the logs for Invalid UTF-8.
Overlapping subtitles: the earlier one gets cut short
An SRT can have two subtitles whose times overlap. However, after the subtitles went into the MP4, the overlap was gone. I tested with this SRT.
1
00:00:01,000 --> 00:00:04,000
上の字幕
2
00:00:02,000 --> 00:00:05,000
下の字幕
This is the SRT I extracted after putting the subtitles into the MP4.
1
00:00:01,000 --> 00:00:02,000
上の字幕
2
00:00:02,000 --> 00:00:05,000
下の字幕
In the original SRT, the upper subtitle was shown until 4 seconds. In the MP4, it ended at 2 seconds, when the lower subtitle started. When I looked at the subtitle packets with ffprobe, the two subtitles were simply in sequence: 1 to 2 seconds, then 2 to 5 seconds.

When I put the same SRT into an MKV and extracted it, the times stayed at 1 to 4 seconds and 2 to 5 seconds, and the overlap was preserved.
Converting an ASS subtitle to mov_text changed it even more. I used two ASS subtitles that both start at 1 second: one from 1 to 3 seconds, and one from 1 to 7.5 seconds. The second uses a style with bold, size 40, and yellow, and is positioned at the top of the screen with {\pos(640,60)}. After I put them into the MP4 and converted them back to ASS, the result was this.
Dialogue: 0,0:00:01.00,0:00:01.00,Default,,0,0,0,,猫が窓の外を見ています
Dialogue: 0,0:00:01.00,0:00:07.50,Default,,0,0,0,,{\b1}{\fs40}{\1c&HFFFF&}検証用の動画
ffprobe showed the first subtitle's duration as 0.000001 seconds. The second kept its bold, font size, and yellow color, but lost its position. Overlapping subtitles stay overlapped in MKV, as shown above. If you need ASS positioning and colors to appear exactly as intended, use burn-in instead, as described in the separate article "How to burn subtitle files into a video with FFmpeg."
In Chromium's video element, subtitles inside the MP4 did not appear in textTracks
When I loaded the output MP4 into a <video> element in Chromium 158, the video could play, but textTracks had zero entries. Chromium did not expose the mov_text subtitles inside the MP4 to the page as subtitles.
If you want subtitles on a web page, save them as a WebVTT file and attach it with a <track> element. You can export WebVTT from the MP4's subtitles.
ffmpeg -i soft.mp4 -map 0:s:0 ja.vtt
<video src="soft.mp4"><track src="ja.vtt" kind="subtitles" srclang="ja" default></video>
With this setup, textTracks showed 1 in the same Chromium, and the three subtitles loaded (the first was "The cat is looking out the window"). Unlike the MP4's language code, the srclang on <track> takes a BCP 47 language tag such as ja.



