FFMPEG An Intermediate Guide/subtitle options

From Wikibooks, open books for an open world
< FFMPEG An Intermediate Guide
Jump to: navigation, search

Subtitle Options[edit]

ffmpeg -i "INPUT" [-sub_charenc [character encoding]] -i "SUBTITLE_INPUT" 
        -vcodec [codec] -acodec [codec] -scodec [codec] [...] "OUTPUT"

Set Subtitles Character Encoding Conversion[edit]

Set input text subtitles character encoding conversion

-sub_charenc [character encoding]

If you want to import and encode a subtitle plaintext file (Windows/ANSI) which contains special characters of some languages (like French, German, Italian, Spanish and so on) this option is needed for subtitle encoding conversion from Windows/ANSI to UTF-8.

[character encoding] parameter examples:
CP1252, CP874, CP936, CP1250, ... , CP1258,
ISO-8859-1, ISO-8859-2, ... , ISO-8859-16,
UTF-8, UTF-16, UTF-32

See also: sub_charenc_parameters.txt in #2431

[-sub_charenc [character encoding]] is not mandatory, but whenever used, it must be placed right before the reference of the subtitle to be processed with that encoding.
If you try to import ANSI subtitle files with a newer version of FFmpeg without using of "-sub_charenc" you can get an error message like:
Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
Then you have to use option "-sub_charenc" to define the right coding format or code page of subtitle file.

Set Subtitle Codec[edit]

Force to set subtitle codec ('copy' to copy stream)

-scodec [subtitle codec]

Not every subtitle codec can be used for every video container format!

[subtitle codec] parameter examples:
for MKV containers: copy, ass, srt, ssa
for MP4 containers: copy, mov_text
for MOV containers: copy, mov_text

Many Philips Blu-Ray Players, Samsung Smart TV's and other standalone players can only read "SRT" subtitle streams in "MKV" files.

Set Subtitle Language[edit]

Set subtitle language using the ISO 639 language code (3 letters)

-metadata:s:s:[stream number] language=[language code]

-metadata:s:s:0 ... that means to set the metadata for ... Stream:Subtitle:Number of stream, starting with 0

[language code] parameter examples:
eng - English
fre - French
ger - German
ita - Italian
spa - Spanish

FFmpegg command line examples to importing subtitle files:[edit]

Import a subtitle file (copy video/audio streams, without re-encoding):[edit]

ffmpeg -i input.mp4 -sub_charenc CP1252 -i subtitle.srt -map 0:v -map 0:a -c copy -map 1 -c:s:0 mov_text -metadata:s:s:0 language=ger output.mp4
ffmpeg -i input.mkv -sub_charenc CP1252 -i subtitle.srt -map 0:v -map 0:a -c copy -map 1 -c:s:0 srt -metadata:s:s:0 language=fre output.mkv


ffmpeg -i input.mp4 -sub_charenc CP1252 -i subtitle.srt -vcodec copy -acodec copy -scodec mov_text -metadata:s:s:0 language=ger output.mp4
ffmpeg -i input.mkv -sub_charenc CP1252 -i subtitle.srt -vcodec copy -acodec copy -scodec srt -metadata:s:s:0 language=fre output.mkv

Import subtitle and re-encode video/audio streams:[edit]

ffmpeg -i input.avi -sub_charenc ISO-8859-1 -i subtitle.srt -vcodec h264 -acodec ac3 -scodec ass -metadata:s:s:0 language=ita output2.mkv
ffmpeg -i input.mov -sub_charenc WINDOWS-1252 -i subtitle.srt -vcodec mpeg4 -acodec mp3 -scodec mov_text -metadata:s:s:0 language=spa output2.mp4