1

I'm running this command to capture video and audio from my webcam:

ffmpeg -y -f video4linux2 -s 320x240 -i /dev/video0 -f alsa -i "plughw:CARD=U0x46d0x825,DEV=0" -ac 2 -strict experimental Filename.mp4

It works, but the audio is about half a second behind the video (EG if I clap, when I watch the video I'll hear the clap and then see me do it).

This is for an online stream, so I can't fix it up later, it needs to be recorded correctly.

It always seems to be off by the same amount, so I'm trying to find an option to simply delay when audio starts recording, but I can't figure it out.

Any ideas?

Cameron Ball
  • 160
  • 1
  • 9

2 Answers2

1

See FFmpeg: audio start time way off how I solved a very similar problem. I used to use -itsoffset before, but it is too much guesswork for my taste.

Lasse Kliemann
  • 228
  • 2
  • 11
1

Did you give google a try? Look here
They suggest to use -async or -vsync depending on your requirement, or -map in combination with -itsoffset

Using a recent ffmpeg with the following command should do the work:

ffmpeg -y -f video4linux2 -s 320x240 -i /dev/video0 -itsoffset 2 -f alsa -i "plughw:CARD=U0x46d0x825,DEV=0" -ac 2 -strict experimental Filename.mp4
Groxxda
  • 126
  • 2
  • 1
    async and vsync don't work, and I think the solution using map and itsoffset only works if you have source files on your hard disk. In my case it is coming directly from the webcam. – Cameron Ball Jul 07 '14 at 13:38
  • The results google cam up with suggest itsoffset should work with streams coming from your webcam, too. Try `ffmpeg -y -f video4linux2 -s 320x240 -i /dev/video0 -itsoffset 00:00.5 -f alsa -i "plughw:CARD=U0x46d0x825,DEV=0" -ac 2 -strict experimental Filename.mp4`. Does it give any errors or just no different result? – Groxxda Jul 07 '14 at 13:52
  • No errors, the result is the same. – Cameron Ball Jul 07 '14 at 14:03
  • What version of ffmpeg are you using? Can you try capturing a few seconds of both input streams to a file and running the command on them and see if it works then? – Groxxda Jul 07 '14 at 14:06
  • 0.8.12-6:0.8.12-1 I don't think itsoffset is the solution anyway. Using itfoffset I can make the video stream start LATER (IE still frames at the beginning), with a +ve itsoffset but that's no good since the audio is playing too early. And if I use a negative offset it just doesn't change anything at all. – Cameron Ball Jul 07 '14 at 15:01
  • `-itsoffset` should also be able to delay the audio stream. Put it behind the -i of your audio and try again. Also note that in your question you said the audio was behind. If it still doesn't work you may be able to add the delay with a alsa softdevice. – Groxxda Jul 07 '14 at 15:05
  • It doesn't seem to make any difference where I put the itsoffset. – Cameron Ball Jul 07 '14 at 15:11
  • I would try getting a more recent version of ffmpeg, the old versions are known to have bugs with itsoffset. Also please try if it works with recorded streams. Or give the ALSA approach a try. – Groxxda Jul 07 '14 at 15:18
  • Can you point me to some resources on Alsa softdevices. I'm not sure what that is. – Cameron Ball Jul 07 '14 at 15:27
  • Compiling 1.0.9 and using ffmpeg -y -f video4linux2 -s 320x240 -i /dev/video0 -itsoffset 2 -f alsa -i "plughw:CARD=U0x46d0x825,DEV=0" -ac 2 -strict experimental Filename.mp4 worked. So if you post that as an answer I will accept. – Cameron Ball Jul 07 '14 at 16:53
  • > "Did you give google a try?" This was the top result on Google for me. – MiniGod Oct 04 '20 at 13:48