Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know maybe it's not a right place to ask this question but I couldn't find more related Q/A site from StackExchange group so here it goes :

I need to add subtitle to a movie, i already have avi format video and srt format subtitle file and now i want to encode them both into one file. so the output file should have 3 streams, video,audio and subtitle. when i try ffmpeg -i video.avi -i subtitle.srt combined.mkv it understands what I want and logs

stream #0.0 -> #0.0
stream #0.1 -> #0.1
stream #1.0 -> #0.2

but then it generates error Encoder (codec id 0) not found for output stream #0.2. I tried adding -newsubtitle option after combined.mkv but that seemed to be unnecessory cause it generated log like this :

stream #0.0 -> #0.0
stream #0.1 -> #0.1
stream #1.0 -> #0.2
stream #1.0 -> #0.3

can anyone help me what I should do to introduce subtitle encoder to ffmpeg (I also tried mp4 format for output stream but the same error was reported) ? and by the way does anyone know a way to keep the original video quality in generated one?

share|improve this question

migrated from stackoverflow.com Jun 4 '11 at 16:39

This question came from our site for professional and enthusiast programmers.

up vote 3 down vote accepted

The answer as given will (lossily) re-encode the audio and video of the input file, and it will only select a single audio and video track (so if you have multiple languages, you're S-O-L). The correct way to do this in modern ffmpeg (or avconv for Ubuntu/Debian users, same syntax) is:

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

MKVmerge, a part of mkvtoolsnix, can do this perfectly well too

mkvmerge -o output.mkv input.avi subtitle.srt
share|improve this answer
    
I can understand the loss part, but why would I lose autio/video streams? – Ali.S Dec 18 '12 at 10:08
    
@Gajoo by default, ffmpeg only uses one video stream, one audio stream, and one subtitle stream. It tries to choose the best quality one (though it goes about this in a pretty naive way), but if you have, say, both English and Japanese audio on a cartoon, then you will lose one of them. -map 0 overrides those defaults and tells ffmpeg to use every stream from input 0 (the first input file). – evilsoup Dec 19 '12 at 16:49

after some trials it seems i had to add -scodec copy to my command line. I mean ffmpeg -i video.avi -i subtitle.srt -scodec copy combined.mkv did add subtitles to my video.

share|improve this answer
1  
This answer will lossily re-encode the video and audio, see my answer for two better alternatives. – evilsoup Dec 18 '12 at 10:04

You must log in to answer this question.

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