7

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.

0

2 Answers 2

11

-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.

3
  • 1
    Is there a way to burn-in the subtitles to a m4v file using ffmpeg? Oct 24, 2014 at 8:22
  • @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).
    – evilsoup
    Oct 24, 2014 at 8:27
  • I am confused because examples here do not contain m4v. Oct 24, 2014 at 11:23
6

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .