Ffmpeg encode subtitle

ffmpeg

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?

Best Answer

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