Use ffmpeg to add text subtitles [closed]
ffmpeg -i infile.mp4 -i infile.srt -c copy -c:s mov_text outfile.mp4
-vf subtitles=infile.srt
will not work with -c copy
The order of -c copy -c:s mov_text
is important. You are telling FFmpeg:
- Video: copy, Audio: copy, Subtitle: copy
- Subtitle: mov_text
If you reverse them, you are telling FFmpeg:
- Subtitle: mov_text
- Video: copy, Audio: copy, Subtitle: copy
Alternatively you could just use -c:v copy -c:a copy -c:s mov_text
in any
order.
NOTE: This solution "burns the subtitles" into the video, so that every viewer of the video will be forced to see them.
If your ffmpeg has libass enabled at compile time, you can directly do:
ffmpeg -i mymovie.mp4 -vf subtitles=subtitles.srt mysubtitledmovie.mp4
This is the case e.g. for Ubuntu 20.10, you can check if ffmpeg --version
has --enable-libass
.
Otherwise, you can the libass
library (make sure your ffmpeg install has the library in the configuration --enable-libass
).
First convert the subtitles to .ass
format:
ffmpeg -i subtitles.srt subtitles.ass
Then add them using a video filter:
ffmpeg -i mymovie.mp4 -vf ass=subtitles.ass mysubtitledmovie.mp4
You are trying to mux subtitles as a subtitle stream. It is easy but different syntax is used for MP4 (or M4V) and MKV. In both cases you must specify video and audio codec, or just copy stream if you just want to add subtitle.
MP4:
ffmpeg -i input.mp4 -f srt -i input.srt \
-map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy \
-c:s mov_text output.mp4
MKV:
ffmpeg -i input.mp4 -f srt -i input.srt \
-map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy \
-c:s srt output.mkv
MKV container supports video and audio codecs Virtually anything and also supports subtitles and DVD menus. So you can just copy codecs from input video to output video with MKV container with subtitles. First you should convert SRT to ASS subtitle format
ffmpeg -i input.srt input.ass
and embed ASS subtitles to video
ffmpeg -i input.mp4 -i input.ass -c:v copy -c:a copy -c:s copy -map 0:0 -map 0:1 -map 1:0 -y out.mkv
Also worked with VMW file.
ffmpeg -i input.wmv -i input.ass -c:v copy -c:a copy -c:s copy -map 0:0 -map 0:1 -map 1:0 -y out.mkv
see the wiki page Comparison of container formats