Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kurlov
Created December 16, 2017 23:41
Show Gist options
  • Star 47 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kurlov/32cbe841ea9d2b299e15297e54ae8971 to your computer and use it in GitHub Desktop.
Save kurlov/32cbe841ea9d2b299e15297e54ae8971 to your computer and use it in GitHub Desktop.
ffmpeg command to add .srt based subtitles to an .mkv file
ffmpeg -i in.mkv -f srt -i in.srt -map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy -c:s srt out.mkv
@akostadinov
Copy link

akostadinov commented Feb 17, 2022

To just add subtitles to file without removing any subtitles it is very easy:

ffmpeg -i input.mkv -i input.srt -map 0 -map 1 -c copy output.mkv

-map x selects all streams from a file so all streams from both files get into the output file.

See the very conscious and simple documentation https://trac.ffmpeg.org/wiki/Map

P.S. Thanks @eladkarako for the metadata usage

@alexg0240
Copy link

I've tried all the above options without success... the only thing that happens is that there is a closed caption option listed yet no text is displayed and the file size of the video file was increased.

I'm using both mediainfo and vlc to look at the file info.

I'm running this thru a ubuntu server 22.04.1 LTS

is this supposed to add the CEA-708 metadata for Closed Captioning or is this a different type of embedded text?

@SalimF
Copy link

SalimF commented Sep 23, 2022

I've tried all the above options without success..

This code I use both on my PC and my server, works perfectly, the sub file should be .ass format (use aegisub or even ffmpeg to convert your sub to it)

ffmpeg -loglevel 16 -i input.mp4 -f ass -i sub.ass -brand isom -tag:v avc1 -map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy -c:s ass -disposition:s:0 default Fname.mkv

@nxtreaming
Copy link

ffmpeg -i $1 -f ass -i $2 -map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy -c:s ass $RANDOM.mkv

I confirm this code is fine.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment