6

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?

5

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
2
  • I can understand the loss part, but why would I lose autio/video streams?
    – Ali1S232
    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
3

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.

1
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.