[FFmpeg-user] ffmpeg record from usb webcam give huge sync problem

Vlăduţ Frăţiman fratiman.vladut at gmail.com
Sun Feb 22 23:03:54 CET 2015

Yes u are right, -s shoul be "-video_size" and -r => -framerate.
But not here are main problem. I make more test, i read everything i
found but still no solution (after two days).
For moment my command is to encode as avi (xvid) because seem to be
faster than mp4 encoding.
So command is: ./ffmpeg -y -f v4l2 -video_size 640x360 -framerate 5 -i
/dev/video0 -f alsa -ac 1 -i hw:1,0 -vcodec mpeg4 -vtag xvid -acodec
libmp3lame -q 3 -ab 96k output2.avi

Output is this:
./ffmpeg -y -f v4l2 -video_size 640x360 -framerate 5 -i /dev/video0 -f
alsa -ac 1 -i hw:1,0 -vcodec mpeg4 -vtag xvid -acodec libmp3lame -q 3
-ab 96k output2.avi
ffmpeg version N-43517-gac424b2-   http://johnvansickle.com/ffmpeg/
Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --enable-gpl --enable-version3 --disable-shared
--disable-debug --enable-runtime-cpudetect --enable-libmp3lame
--enable-libx264 --enable-libx265 --enable-libwebp --enable-libspeex
--enable-libvorbis --enable-libvpx --enable-libfreetype
--enable-fontconfig --enable-libxvid --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libtheora --enable-libvo-aacenc
--enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg
--enable-libopus --enable-libass --enable-gnutls --enable-libvidstab
  libavutil      54. 19.100 / 54. 19.100
  libavcodec     56. 25.101 / 56. 25.101
  libavformat    56. 23.103 / 56. 23.103
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.100 /  5. 11.100
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
[video4linux2,v4l2 @ 0xb941a20] The driver changed the time per frame
from 1/5 to 2/15
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 367.470086, bitrate: 27648 kb/s
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422,
640x360, 27648 kb/s, 7.50 fps, 7.50 tbr, 1000k tbn, 1000k tbc
Guessed Channel Layout for  Input Stream #1.0 : mono
Input #1, alsa, from 'hw:1,0':
  Duration: N/A, start: 1424641531.273806, bitrate: 768 kb/s
    Stream #1:0: Audio: pcm_s16le, 48000 Hz, 1 channels, s16, 768 kb/s
Output #0, avi, to 'output2.avi':
    ISFT            : Lavf56.23.103
    Stream #0:0: Video: mpeg4 (xvid / 0x64697678), yuv420p, 640x360,
q=2-31, 200 kb/s, 7.50 fps, 7.50 tbn, 7.50 tbc
      encoder         : Lavc56.25.101 mpeg4
    Stream #0:1: Audio: mp3 (libmp3lame) (U[0][0][0] / 0x0055), 48000
Hz, mono, s16p, 96 kb/s
      encoder         : Lavc56.25.101 libmp3lame
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg4 (native))
  Stream #1:0 -> #0:1 (pcm_s16le (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
frame=    4 fps=0.0 q=3.0 size=      48kB time=00:00:00.53 bitrate=
743.1kbits/sframe=    8 fps=7.9 q=3.0 size=      75kB time=00:00:01.06
bitrate= 578.8kbits/sframe=   10 fps=6.6 q=3.0 size=      92kB
time=00:00:01.73 bitrate= 432.7kbits/sframe=   13 fps=6.4 q=3.0 size=
   113kB time=00:00:02.26 bitrate= 409.4kbits/sframe=   15 fps=5.9
q=3.0 size=     138kB time=00:00:02.80 bitrate= 403.4kbits/sframe=
17 fps=5.6 q=3.0 size=     161kB time=00:00:03.20 bitrate=
412.3kbits/sframe=   20 fps=5.7 q=3.0 size=     195kB time=00:00:03.60
bitrate= 443.9kbits/sPast duration 0.908470 too large
Past duration 0.732430 too large
Past duration 0.735619 too large
Past duration 0.799629 too large
frame=   24 fps=5.9 q=3.0 size=     231kB time=00:00:04.13 bitrate= 457.4kbits/s

I see some message that is repeated: Past duration xxxxxxxxx too large

Problem i think is with uvcview driver wich is used by my cam.
According with this post:
here are some problems with timestamp in v4l2 buffers
Follow this bugtrac: https://trac.ffmpeg.org/ticket/692#comment:15
tested ffmpeg with all option: -ts abs or mono2abs. Loaded uvcview
kernel module with "modprobe uvcvideo clock=realtime" but no change.
I'm not shure if current uvcview have patch mentioned in first link.
Everytime i get video about 7s later from sound.

On Sun, Feb 22, 2015 at 9:13 PM, Moritz Barsnick <barsnick at gmx.net> wrote:
> On Sun, Feb 22, 2015 at 09:42:40 +0200, Vlăduţ Frăţiman wrote:
>> ffmpeg -y -f v4l2 -s 640x360 -framerate 5 -i /dev/video0 -f alsa -ac 1 -i default:CARD=HD3000 -pix_fmt yuv420p -c:v libx264 -q:v 20 -r 5 -preset ultrafast -strict -2 -c:a aac capture.mkv
> I believe "-s" should be "-video_size".
> I believe "-q:v" has no effect on libx264, but I may be wrong.
> That said:
>> The main problem is that audio and video are totally out of sync.
>> Probably each device (video and audio) will not start simultaneously.
>> Is there any parameter to ensure that the two devices are ready
>> simultaneously so when recording, video and audio will be in sync?
>> In my case, audio start much faster. At begining video is freezing and
>> hear audio, then both play obviously out of sync and then audio is
>> finishing and video still playing until finish.
> Please show us the complete console output from the ffmpeg command.
> Moritz
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user

More information about the ffmpeg-user mailing list