[FFmpeg-user] ffmpeg "stretches" encoding
tte at cs.fau.de
tte at cs.fau.de
Sun Jun 17 19:10:02 CEST 2012
I am trying to use ffmpeg to encode mpeg2 TV programming to h264/mp3/mkv.
But i never get audio/video synchronized correctly, whatever i do.
And it is not clear to me which av-sync options in ffmpeg should give me
even the desired results.
The mpeg2 file plays back with av in sync (of course). I also
extracted the subtitles from the mpeg2 into a .srt file with ccextractor.
And that .srt file is then also played back by eg: xbmc/vlc well, and
the timestamps in the .srt file match well with the audio track of the
So, i encode as follows:
ffmpeg -v 0 -loglevel error -i infile.mpg \
-vcodec libx264 -vf scale=1280:720 -vpre libx264-baseline -b 1200k \
-acodec libmp3lame -ab 64k -ac 2 \
<...av-sync options> outfile.mkv
a) If i do not use any av-sync options, audio and video are not in
sync, and video is slower than audio. ON an example show,
a sentence is at 58 min 06 seconds in the mpeg, it is spoken in the
encoded mkv at 58 min 06 (in sync with the .srt) but the video
comes at 58 min 19 sec.
b) If i use "-async 5000", audio and video are in sync, but both audio
and video are now at 58 min 19 sec. Which i guess is to be expected.
And because they are both out of sync with the .srt, this is not
really useful for me. Besides, even if i could stretch the .srt, why
would i want to.
c) If i use "-vsync 1 -async 5000", i get the same result as b).
d) If i use "-vsync 0", i get the same results as a).
e) If i use "-vsync 0 -async 5000", i still get the same result as a).
It seems to me there is really no option in ffmpeg to synchronize the
video to the audio stream, and seeemingly this is what it takes, because
whenever one stretches/shrinks audio to fit video, then it will result
in stretching/shrinking the whole length of the clip and getting out
of sync with the subtitles.
So, any recommendations on what i could do ? I was made to believe
that i should move from mencoder to ffmpeg because mencoder is old and
not maintained, but i never had these problems with mencoder *sigh*.
Hopefully i am just missing some magic parameter that should have been
Each of these trial encodings takes 6 hours, so it's not really fun
experimenting around with these type of paramerers *sigh*.
More information about the ffmpeg-user