Ffmpeg/avconv async is not working – unsync audio

audioffmpeglibavsyncwebcam

I have a javascript that records video from a webcam as webm and audio from microphone as wav together. I am encoding these webm and wave files to generate a mp4 file using ffmpeg/avconv. But i've noticed a small differrence in length of audio and length of video which makes the output out of sync.

I tried the async/asyncts option, but i've noticed no differrence in output, still out of sync

ffmpeg -async 1 -y -i audio.wav -i  video.webm -vcodec libx264 output.mp4

I tried using areasample filter with avconv gave me error

No such filter: 'areasample'
Error opening filters!

for

avconv -y -i audio.wav -i  video.webm -vcodec libx264 -filter "areasample=asyncts:compensate" output.mp4

How can i make the video in sync?

Update:

My audio length is less than that of video. I'm using the command
ffmpeg -itsoffset -00:00:01 -y -i audio.wav -i video.webm -vcodec libx264 output.mp4
to make them in sync. But I'm not sure there will be a 1 sec difference always. So I'm looking for a solution that could manage this dynamically(add the offset for missing audio length).

Best Answer

Option -async helps only if you have timestamps in your audio and video streams. I doubt you have it. That's why you don't see any difference in output.

So probably your problem is that video and audio have different duration and start time. If it's so, you should trim your audio or video stream (it depends whether your audio or video is longer).

You have not specified which one is longer and what is out of sync time in seconds. So I've give an example. Let's assume you have your audio early by 0.5 sec. Then you should run:

ffmpeg -i audio.wav -af "atrim=start=0.5" -i video.webm -vcodec libx264 output.mp4

P.S. use ffmpeg from git or find latest package for your OS.

Update: Ffmpeg does not have any information about which audio package should be displayed at the same time as some video frame. You should use some container that have timestamps in streams like mpegts, not wav.

Related Question