Using FFMPEG to add subtitles to a M4v video file
Solution 1
-newsubtitle
is an obsolete option from old versions of ffmpeg; with more modern versions, the command will look like this:
ffmpeg -i input.m4v -i subtitle.srt -map 0 -map 1 -c copy -c:s mov_text output.m4v
-i input.m4v -i subtitle.srt
tells ffmpeg to use those two files as its inputs.
-map 0 -map 1
tells ffmpeg to use all the streams from input number 0 and input number 1.
It's not directly relevant to this, but you can select individual streams with -map
: -map 0:v
would select all video streams from input 0, -map 1:s
would select all subtitle streams from input 1, -map 0:0
would select stream 0 (the first stream) from input 0, -map 1:a:0
would select the first audio stream of input 1.
-c copy
tells ffmpeg to copy all streams from the input without re-encoding, while having -c:s mov_text
after the -c copy
overrides the copy setting for the subtitle stream, re-encoding it to a form the MP4 container can contain.
Solution 2
With FFmpeg 0.9, the -newsubtitle
option was removed. If you want to add all input files' video/audio/subtitle streams to the output, use the -map
options, e.g.:
ffmpeg -i movie_input.m4v -i subtitles.srt -c:v copy -c:a copy -c:s mov_text \
-map 0 -map 1 out.m4v
This will copy video and audio streams, but encode the subtitles to mov_text
, which is the only officially supported subtitle format for MP4. SRT by default won't work.
The map
options here specify that all the streams from the first file (0
) and the second file (1
) will be copied, so it'd work even if your original had multiple audio streams, for example.
For a detailed article on how to use the map
option, see the FFmpeg wiki.
Reason for removing those options from the Changelog:
-newvideo/-newaudio/-newsubtitle options were removed. Not only were they irregular and highly confusing, they were also redundant. In avconv the -map option will create new streams in the output file and map input streams to them. E.g. avconv -i INPUT -map 0 OUTPUT will create an output stream for each stream in the first input file.
Related videos on Youtube
Yuval Cohen
Updated on September 18, 2022Comments
-
Yuval Cohen almost 2 years
I am having troubles adding subtitles to a video file using ffmpeg.
I am using this command:
ffmpeg -i movie_input.m4v -newsubtitle subtitles.srt -acodec copy -vcodec copy movie_output.m4v
I found this command line example in various tutorials but for some reason (a newer version of ffmpeg?) it gives me:
Unrecognized option 'newsubtitle'
Any clue as to how can I add subtitles using ffmpeg?
Thanks!
P.S. I need a solution that can be automated in a bash script, so using programs like Subler are not fit for this task.
-
Koray Tugay over 9 yearsIs there a way to burn-in the subtitles to a m4v file using ffmpeg?
-
evilsoup over 9 years@KorayTugay Yes. If you need any help not contained in that link, feel free to ask a question (and don't forget to tag it with
ffmpeg
). -
Koray Tugay over 9 yearsI am confused because examples here do not contain m4v.