20

I tried googling a way to set the language of a subtitle stream with ffmpeg and found the -slang option. So I tried the following command but immediately receive an error:

ffmpeg -i input.avi -i subs.srt -c:a copy -c:s mov_text -slang eng -c:v libx264 -profile:v high -level:v 4.0 output.mp4
ffmpeg version 1.1 Copyright (c) 2000-2013 the FFmpeg developers
built on Jul 18 2013 23:00:53 with Apple clang version 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn)

libavutil 52. 13.100 / 52. 13.100

libavcodec 54. 86.100 / 54. 86.100

libavformat 54. 59.106 / 54. 59.106

libavdevice 54. 3.102 / 54. 3.102

libavfilter 3. 32.100 / 3. 32.100

libswscale 2. 1.103 / 2. 1.103

libswresample 0. 17.102 / 0. 17.102

libpostproc 52. 2.100 / 52. 2.100

Unrecognized option 'slang'.

Error splitting the argument list: Option not found

After more googling I found another way to do it using the -metadata command:

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

And that works absolutely fine. But this isn't mentioned in the ffmpeg man page, whereas -slang is, which makes me think the -metadata command is maybe outdated or in some other way not as good as -slang.

  1. What is the difference between using the two above methods (-slang vs -metadata)?
  2. Why did my -slang command give an error? Have I used it incorrectly?
sion
  • 1,367
  • 6
  • 17
  • 21

2 Answers2

37

The option

-metadata:s:1 language=eng

sets metadata language to eng on the stream id 1 (which is, in typical cases, the first audio stream). Whereas the option

-metadata:s:s:0 language=eng

sets the metadata language to eng on the first subtitle stream.

From ffmpeg manpage:

-metadata[:metadata_specifier] key=value (output,per-metadata)
Set a metadata key/value pair.

An optional metadata_specifier may be given to set metadata on streams or chapters. See "-map_metadata" documentation for details.

s[:stream_spec]
per-stream metadata. stream_spec is a stream specifier as described in the Stream specifiers chapter. In an input metadata specifier, the first matching stream is copied from. In an output metadata specifier, all matching streams are copied to.

And finally from the chapter of stream specifiers, we see

Possible forms of stream specifiers are:
stream_index
Matches the stream with this index. E.g. "-threads:1 4" would set the thread count for the second stream to 4.

stream_type[:stream_index]
stream_type is one of: 'v' for video, 'a' for audio, 's' for subtitle, 'd' for data and 't' for attachments. If stream_index is given, then matches stream number stream_index of this type. Otherwise matches all streams of this type.

c-x-berger
  • 991
  • 12
  • 30
Ed.B
  • 465
  • 4
  • 4
10

After some research, found the reason why -slang didn't work. In fact you use a recent version of ffmpeg and it's a good thing but if the documentation still describe the option, you can find in the ChangeLog:

version 0.9:
...
 * -metadata can now be used to set metadata on streams and chapters, e.g.
      -metadata:s:1 language=eng sets the language of the first stream to 'eng'.
      This made -vlang/-alang/-slang options redundant, so they were removed.

When you find a command line example, check if the option used are in Your version of ffmpeg.

 ffmpeg --help >> ffmpeg-doc.txt

The -slang option isn't in.

But it also proof that the on-line documentation about ffmpeg is sometime incorrect regarding the code change.

alexbuisson
  • 7,699
  • 3
  • 31
  • 44
  • 3
    Thanks for clearing that up. Any idea why this metadata command seems to index the streams from 1 whereas when mapping streams and performing other actions, streams are indexed from zero? I would have thought `-metadata:s:1 language=eng` would set the second stream to english and to set the first stream you would use `-metadata:s:0 language=eng`. Any thoughts? – sion Jul 30 '13 at 19:55
  • 2
    This indexing *is* consistent with the rest of the indexing. Everything starts at 0 (programmers, sigh...). In this case, stream 0 is the video stream (this is always the case with MP4?). So, you specify the first audio as either `-metadata:s:1` (the 2nd stream in the file) or more correctly as `-metadata:s:a:0` (the first *audio* stream in the file). – jimtut Aug 24 '14 at 13:53
  • 2
    I couldn't find any documentation about which naming convention to use for the language (in my case, trying to specify Finnish). Going from the `eng` example, I'd assume [ISO 639-3](https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes) (eg. `fin` for Finnish)? – dsample Dec 25 '16 at 22:07