Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I converted an mkv (matroska) file to avi using ffmpeg:

ffmpeg -i input.mkv -f mp4 -vcodec mpeg4 -sameq -r 29.97 -b 512kb -acodec ac3 -ab 128kb -vol 512  output.avi

The output file plays fine using mplayer. After that, I used mencoder to insert subtitles:

mencoder output.avi -o new.avi -oac pcm -ovc lavc -subfont-text-scale 3 -sub subtitle.srt

After I play back the video "new.avi", the video and audio is out of sync. What options can I put into mencoder to sync the A/V?

I have also tried the ffmpeg -newsubtitle option but can't get it work. Any examples of usage of -newsubtitle would be greatly appreciated.

share|improve this question

migrated from stackoverflow.com Oct 11 '09 at 20:54

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

    
I suggest looking at (a) doing the entire encode with mencoder, there is no need for ffmpeg here; (b) -mc 0, -noskip, and -vf harddup. –  derobert Sep 26 '09 at 6:37
    
did you play it back after conversion, but before subtitle insertion? is it in sync then? –  quack quixote Oct 11 '09 at 21:16
add comment

2 Answers

As derobert mentioned you can do the whole thing in mencoder, which uses the ffmpeg libraries itself, and is much more powerful, this will avoid the transcoding that you are currently doing. The -audio-delay option in mencoder sets an offset for the audio relative to the video, if the offset difference is absolute. You could also try different -autosync settings (the default value is 0, up to 30 is mentioned in the manual).

share|improve this answer
add comment

If you don't really need the AVI, you might try using mkvmerge from the MkvToolnix suite to do this (instead of mencoder). MKVs can contain "soft" subtitle tracks, which means you don't have to re-encode the video stream to include them. (This also means that players can disable the subtitle tracks during playback if desired.)

Adding an SRT file into an MKV is as simple as

$ mkvmerge -o with-subtitles.mkv without-subtitles.mkv mymovie.srt

or to specify a language for the subtitle track:
$ mkvmerge -o with-lang-codes.mkv without-lang-codes.mkv --language 0:eng english.srt --default-track 0

(adapted from the Examples section of the mkvmerge manpage linked above).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.