2

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).

4
  • You mean aresample (from "re-sample")?
    – slhck
    Nov 27, 2013 at 12:19
  • sorry. i don't know about that, all these stuffs are new to me ..
    – Khaleel
    Nov 27, 2013 at 12:55
  • @slhck i tried with aresample and got No such filter: 'aresample'
    – Khaleel
    Nov 27, 2013 at 13:04
  • You haven't given a lot of information. If your ffmpeg is too old, it will not have the filter. Also, asyncts is another filter, so the syntax looks a little off to me. Can you please include the full, uncut output of both commands?
    – slhck
    Nov 27, 2013 at 13:26

1 Answer 1

6

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.

1
  • The Updated message was the most usefull. Thanks.
    – Vyacheslav
    Jan 3, 2015 at 8:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .