Opened 5 years ago

Closed 4 years ago

#692 closed defect (fixed)

Audio is not in sync with video, webcam capturing

Reported by: burek Owned by:
Priority: normal Component: avdevice
Version: git-master Keywords: v4l2 alsa
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

This command:

ffmpeg -f alsa -ar 44100 -ac 1 -i front:CARD=U0x46d0x809,DEV=0 -f video4linux2 -r 25 -s vga -i /dev/video0 -vcodec libx264 -preset fast -crf 20 -acodec libaacplus -ab 32k -f mpegts udp://burek:10001

produces such a stream that AUDIO is late (video comes before audio), and this command (just swapped a/v inputs):

ffmpeg -f video4linux2 -r 25 -s vga -i /dev/video0 -f alsa -ar 44100 -ac 1 -i front:CARD=U0x46d0x809,DEV=0 -vcodec libx264 -preset fast -crf 20 -acodec libaacplus -ab 32k -f mpegts udp://burek:10001

produces such a stream that VIDEO is late (audio comes before video).

The sync time difference is less than a second, but it's noticable. Also, I've tried with -isync option (before, between and after both inputs) and it didn't have any effect.

Attachments (2)

ffmpeg-20120831-173134.log (6.3 KB) - added by ewhac 4 years ago.
Specifies audio input first; audio in final file is very late.
ffmpeg-20120831-173234.log (6.3 KB) - added by ewhac 4 years ago.
Specifies video input first; audio in final file is slightly early.

Download all attachments as: .zip

Change History (18)

comment:1 Changed 5 years ago by cehoyos

  • Component changed from FFmpeg to undetermined

Do you think this is a regression?

Please add complete, uncut console output.

comment:2 Changed 5 years ago by burek

There were no errors in the output, that's why I didn't provide it, so here it is:

root@bla:~# ffmpeg -f video4linux2 -r 25 -s vga -i /dev/video0 -f alsa -ar 44100 -ac 1 -i front:CARD=U0x46d0x809,DEV=0 -isync -vcodec libx264 -preset fast -crf 20 -acodec libaacplus -ab 32k -f mpegts udp://burek:10001
ffmpeg version N-35149-g3880b45, Copyright (c) 2000-2011 the FFmpeg developers
  built on Nov 25 2011 02:16:49 with gcc 4.6.2
  configuration: --enable-static --enable-shared --enable-gpl --enable-nonfree --enable-postproc --enable-libx264 --enable-libaacplus --enable-libmp3lame --enable-libv4l2 --enable-libvo-aacenc --enable-version3
  libavutil    51. 28. 0 / 51. 28. 0
  libavcodec   53. 37. 0 / 53. 37. 0
  libavformat  53. 21. 0 / 53. 21. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 49. 0 /  2. 49. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[video4linux2,v4l2 @ 0x124ca20] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 865.119708, bitrate: 92160 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 640x480, 92160 kb/s, 25 tbr, 1000k tbn, 25 tbc
[alsa @ 0x124da00] Estimating duration from bitrate, this may be inaccurate
Input #1, alsa, from 'front:CARD=U0x46d0x809,DEV=0':
  Duration: N/A, start: 1322445758.231273, bitrate: N/A
    Stream #1:0: Audio: pcm_s16le, 48000 Hz, 1 channels, s16, 768 kb/s
[buffer @ 0x124f040] w:640 h:480 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[libx264 @ 0x1247580] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[libx264 @ 0x1247580] profile High, level 3.0
[mpegts @ 0x1247040] muxrate VBR, pcr every 2 pkts, sdt every 200, pat/pmt every 40 pkts
Output #0, mpegts, to 'udp://burek:10001':
  Metadata:
    encoder         : Lavf53.21.0
    Stream #0:0: Video: h264, yuv420p, 640x480, q=-1--1, 90k tbn, 25 tbc
    Stream #0:1: Audio: aac, 48000 Hz, 1 channels, s16, 32 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> libx264)
  Stream #1:0 -> #0:1 (pcm_s16le -> libaacplus)
Press [q] to stop, [?] for help
frame=  373 fps= 24 q=25.0 Lsize=    2648kB time=00:00:14.46 bitrate=1499.7kbits/s dup=155 drop=0
video:2350kB audio:59kB global headers:0kB muxing overhead 9.917098%
[libx264 @ 0x1247580] frame I:2     Avg QP:17.79  size: 23828
[libx264 @ 0x1247580] frame P:306   Avg QP:19.51  size:  6459
[libx264 @ 0x1247580] frame B:65    Avg QP:21.62  size:  5883
[libx264 @ 0x1247580] consecutive B-frames: 66.5% 30.6%  0.8%  2.1%
[libx264 @ 0x1247580] mb I  I16..4:  9.5% 78.3% 12.2%
[libx264 @ 0x1247580] mb P  I16..4:  0.1%  0.9%  0.1%  P16..4: 39.7% 14.0%  7.2%  0.0%  0.0%    skip:38.0%
[libx264 @ 0x1247580] mb B  I16..4: 19.8% 19.3%  0.0%  B16..8:  9.2%  1.2%  0.0%  direct:31.1%  skip:19.5%  L0:40.8% L1:48.1% BI:11.1%
[libx264 @ 0x1247580] 8x8 transform intra:54.9% inter:75.2%
[libx264 @ 0x1247580] coded y,uvDC,uvAC intra: 36.2% 100.0% 98.6% inter: 24.4% 57.2% 43.1%
[libx264 @ 0x1247580] i16 v,h,dc,p: 43% 19% 22% 15%
[libx264 @ 0x1247580] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 15% 40%  5%  4%  4%  4%  5%  5%
[libx264 @ 0x1247580] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 25% 14%  7%  6%  5%  6%  5%  7%
[libx264 @ 0x1247580] i8c dc,h,v,p: 61% 21% 11%  7%
[libx264 @ 0x1247580] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x1247580] ref P L0: 75.1% 24.9%
[libx264 @ 0x1247580] ref B L0: 75.4% 24.6%
[libx264 @ 0x1247580] kb/s:1290.40

I always had problems with syncing audio and video with ffmpeg and webcam capturing, so I believe this might not be a regression.

Last edited 5 years ago by burek (previous) (diff)

comment:3 follow-up: Changed 5 years ago by cehoyos

  • Priority changed from important to normal

Not a regression.

For future bugreports: Please do not use external libraries (in this case: libaacplus) if they are not needed to reproduce a problem.

comment:4 Changed 5 years ago by burek

ok, the following examples all have the same issue:

(internal aac)

root@bla:~# ffmpeg -f video4linux2 -r 25 -s vga -i /dev/video0 -f alsa -ar 44100 -ac 1 -i front:CARD=U0x46d0x809,DEV=0 -isync -vcodec libx264 -preset fast -crf 20 -acodec aac -ab 128k -strict experimental -f mpegts udp://burek:10001
ffmpeg version N-35149-g3880b45, Copyright (c) 2000-2011 the FFmpeg developers
  built on Nov 25 2011 02:16:49 with gcc 4.6.2
  configuration: --enable-static --enable-shared --enable-gpl --enable-nonfree --enable-postproc --enable-libx264 --enable-libaacplus --enable-libmp3lame --enable-libv4l2 --enable-libvo-aacenc --enable-version3
  libavutil    51. 28. 0 / 51. 28. 0
  libavcodec   53. 37. 0 / 53. 37. 0
  libavformat  53. 21. 0 / 53. 21. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 49. 0 /  2. 49. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[video4linux2,v4l2 @ 0x1857a20] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 168.168777, bitrate: 92160 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 640x480, 92160 kb/s, 25 tbr, 1000k tbn, 25 tbc
[alsa @ 0x1858a00] Estimating duration from bitrate, this may be inaccurate
Input #1, alsa, from 'front:CARD=U0x46d0x809,DEV=0':
  Duration: N/A, start: 1322476404.313276, bitrate: N/A
    Stream #1:0: Audio: pcm_s16le, 48000 Hz, 1 channels, s16, 768 kb/s
[buffer @ 0x185a180] w:640 h:480 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[libx264 @ 0x1852580] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[libx264 @ 0x1852580] profile High, level 3.0
[mpegts @ 0x1852040] muxrate VBR, pcr every 2 pkts, sdt every 200, pat/pmt every 40 pkts
Output #0, mpegts, to 'udp://burek:10001':
  Metadata:
    encoder         : Lavf53.21.0
    Stream #0:0: Video: h264, yuv420p, 640x480, q=-1--1, 90k tbn, 25 tbc
    Stream #0:1: Audio: aac, 48000 Hz, 1 channels, s16, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> libx264)
  Stream #1:0 -> #0:1 (pcm_s16le -> aac)
Press [q] to stop, [?] for help
frame=  591 fps= 24 q=25.0 Lsize=    2990kB time=00:00:23.18 bitrate=1056.1kbits/s dup=358 drop=0
video:2355kB audio:325kB global headers:0kB muxing overhead 11.540911%
[libx264 @ 0x1852580] frame I:3     Avg QP:17.89  size: 26873
[libx264 @ 0x1852580] frame P:270   Avg QP:19.24  size:  7880
[libx264 @ 0x1852580] frame B:318   Avg QP:20.23  size:   640
[libx264 @ 0x1852580] consecutive B-frames: 26.4%  5.4%  0.5% 67.7%
[libx264 @ 0x1852580] mb I  I16..4:  9.4% 64.8% 25.8%
[libx264 @ 0x1852580] mb P  I16..4:  0.2%  1.4%  0.2%  P16..4: 44.6% 23.2% 13.8%  0.0%  0.0%    skip:16.5%
[libx264 @ 0x1852580] mb B  I16..4:  1.5%  1.4%  0.0%  B16..8: 11.1%  0.7%  0.0%  direct: 9.1%  skip:76.2%  L0:54.1% L1:42.7% BI: 3.2%
[libx264 @ 0x1852580] 8x8 transform intra:59.9% inter:63.5%
[libx264 @ 0x1852580] coded y,uvDC,uvAC intra: 49.7% 95.9% 71.8% inter: 17.6% 37.4% 7.5%
[libx264 @ 0x1852580] i16 v,h,dc,p: 37%  8% 34% 21%
[libx264 @ 0x1852580] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 17% 11% 37%  5%  5%  6%  6%  7%  6%
[libx264 @ 0x1852580] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 19% 13%  6%  7%  6%  8%  7%  8%
[libx264 @ 0x1852580] i8c dc,h,v,p: 60% 16% 16%  8%
[libx264 @ 0x1852580] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x1852580] ref P L0: 57.3% 42.7%
[libx264 @ 0x1852580] ref B L0: 95.4%  4.6%
[libx264 @ 0x1852580] ref B L1: 99.6%  0.4%
[libx264 @ 0x1852580] kb/s:816.20

(libmp3lame)

root@bla:~# ffmpeg -f video4linux2 -r 25 -s vga -i /dev/video0 -f alsa -ar 44100 -ac 1 -i front:CARD=U0x46d0x809,DEV=0 -isync -vcodec libx264 -preset fast -crf 20 -acodec libmp3lame -ab 128k -f mpegts udp://burek:10001
ffmpeg version N-35149-g3880b45, Copyright (c) 2000-2011 the FFmpeg developers
  built on Nov 25 2011 02:16:49 with gcc 4.6.2
  configuration: --enable-static --enable-shared --enable-gpl --enable-nonfree --enable-postproc --enable-libx264 --enable-libaacplus --enable-libmp3lame --enable-libv4l2 --enable-libvo-aacenc --enable-version3
  libavutil    51. 28. 0 / 51. 28. 0
  libavcodec   53. 37. 0 / 53. 37. 0
  libavformat  53. 21. 0 / 53. 21. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 49. 0 /  2. 49. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[video4linux2,v4l2 @ 0x1335a20] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 289.069699, bitrate: 92160 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 640x480, 92160 kb/s, 25 tbr, 1000k tbn, 25 tbc
[alsa @ 0x1336a00] Estimating duration from bitrate, this may be inaccurate
Input #1, alsa, from 'front:CARD=U0x46d0x809,DEV=0':
  Duration: N/A, start: 1322476525.134211, bitrate: N/A
    Stream #1:0: Audio: pcm_s16le, 48000 Hz, 1 channels, s16, 768 kb/s
[buffer @ 0x1383880] w:640 h:480 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[libx264 @ 0x1330040] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[libx264 @ 0x1330040] profile High, level 3.0
[mpegts @ 0x1338040] muxrate VBR, pcr every 2 pkts, sdt every 200, pat/pmt every 40 pkts
Output #0, mpegts, to 'udp://burek:10001':
  Metadata:
    encoder         : Lavf53.21.0
    Stream #0:0: Video: h264, yuv420p, 640x480, q=-1--1, 90k tbn, 25 tbc
    Stream #0:1: Audio: mp3, 48000 Hz, 1 channels, s16, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> libx264)
  Stream #1:0 -> #0:1 (pcm_s16le -> libmp3lame)
Press [q] to stop, [?] for help
frame=  810 fps= 23 q=-1.0 Lsize=    4818kB time=00:00:32.32 bitrate=1221.1kbits/s dup=113 drop=0
video:3855kB audio:505kB global headers:0kB muxing overhead 10.485526%
[libx264 @ 0x1330040] frame I:4     Avg QP:18.06  size: 19483
[libx264 @ 0x1330040] frame P:479   Avg QP:19.86  size:  5369
[libx264 @ 0x1330040] frame B:327   Avg QP:21.23  size:  3970
[libx264 @ 0x1330040] consecutive B-frames: 19.8% 79.3%  0.0%  1.0%
[libx264 @ 0x1330040] mb I  I16..4:  8.9% 76.3% 14.7%
[libx264 @ 0x1330040] mb P  I16..4:  0.1%  0.6%  0.0%  P16..4: 50.8% 18.6% 10.3%  0.0%  0.0%    skip:19.7%
[libx264 @ 0x1330040] mb B  I16..4: 14.4% 17.3%  0.0%  B16..8: 13.3%  2.7%  0.0%  direct:25.9%  skip:26.4%  L0:52.6% L1:38.8% BI: 8.6%
[libx264 @ 0x1330040] 8x8 transform intra:56.4% inter:76.0%
[libx264 @ 0x1330040] coded y,uvDC,uvAC intra: 36.8% 98.2% 78.0% inter: 25.0% 64.6% 11.5%
[libx264 @ 0x1330040] i16 v,h,dc,p: 42% 15% 30% 13%
[libx264 @ 0x1330040] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 13% 44%  4%  3%  4%  4%  4%  4%
[libx264 @ 0x1330040] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 20% 13%  7%  6%  5%  7%  6%  6%
[libx264 @ 0x1330040] i8c dc,h,v,p: 62% 19% 14%  5%
[libx264 @ 0x1330040] Weighted P-Frames: Y:0.8% UV:0.0%
[libx264 @ 0x1330040] ref P L0: 61.9% 38.1%
[libx264 @ 0x1330040] ref B L0: 53.5% 46.5%
[libx264 @ 0x1330040] ref B L1: 100.0%  0.0%
[libx264 @ 0x1330040] kb/s:974.78

(internal mp2)

root@bla:~# ffmpeg -f video4linux2 -r 25 -s vga -i /dev/video0 -f alsa -ar 44100 -ac 1 -i front:CARD=U0x46d0x809,DEV=0 -isync -vcodec libx264 -preset fast -crf 20 -f mpegts udp://burek:10001
ffmpeg version N-35149-g3880b45, Copyright (c) 2000-2011 the FFmpeg developers
  built on Nov 25 2011 02:16:49 with gcc 4.6.2
  configuration: --enable-static --enable-shared --enable-gpl --enable-nonfree --enable-postproc --enable-libx264 --enable-libaacplus --enable-libmp3lame --enable-libv4l2 --enable-libvo-aacenc --enable-version3
  libavutil    51. 28. 0 / 51. 28. 0
  libavcodec   53. 37. 0 / 53. 37. 0
  libavformat  53. 21. 0 / 53. 21. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 49. 0 /  2. 49. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[video4linux2,v4l2 @ 0xa58a20] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 409.621608, bitrate: 92160 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 640x480, 92160 kb/s, 25 tbr, 1000k tbn, 25 tbc
[alsa @ 0xa59a00] Estimating duration from bitrate, this may be inaccurate
Input #1, alsa, from 'front:CARD=U0x46d0x809,DEV=0':
  Duration: N/A, start: 1322476645.783991, bitrate: N/A
    Stream #1:0: Audio: pcm_s16le, 48000 Hz, 1 channels, s16, 768 kb/s
[buffer @ 0xa6be60] w:640 h:480 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[libx264 @ 0xa53040] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[libx264 @ 0xa53040] profile High, level 3.0
[mpegts @ 0xa5b040] muxrate VBR, pcr every 2 pkts, sdt every 200, pat/pmt every 40 pkts
Output #0, mpegts, to 'udp://burek:10001':
  Metadata:
    encoder         : Lavf53.21.0
    Stream #0:0: Video: h264, yuv420p, 640x480, q=-1--1, 90k tbn, 25 tbc
    Stream #0:1: Audio: mp2, 48000 Hz, 1 channels, s16, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> libx264)
  Stream #1:0 -> #0:1 (pcm_s16le -> mp2)
Press [q] to stop, [?] for help
frame=  676 fps= 24 q=25.0 Lsize=    3291kB time=00:00:26.68 bitrate=1010.0kbits/s dup=409 drop=0
video:2539kB audio:417kB global headers:0kB muxing overhead 11.301029%
[libx264 @ 0xa53040] frame I:3     Avg QP:17.29  size: 28390
[libx264 @ 0xa53040] frame P:284   Avg QP:19.11  size:  7924
[libx264 @ 0xa53040] frame B:389   Avg QP:20.11  size:   680
[libx264 @ 0xa53040] consecutive B-frames: 22.6%  1.8%  0.4% 75.1%
[libx264 @ 0xa53040] mb I  I16..4:  8.9% 65.5% 25.6%
[libx264 @ 0xa53040] mb P  I16..4:  0.1%  1.0%  0.1%  P16..4: 47.5% 24.7% 15.0%  0.0%  0.0%    skip:11.5%
[libx264 @ 0xa53040] mb B  I16..4:  1.5%  1.6%  0.0%  B16..8: 11.7%  0.7%  0.0%  direct: 9.8%  skip:74.7%  L0:55.8% L1:41.3% BI: 2.8%
[libx264 @ 0xa53040] 8x8 transform intra:58.3% inter:65.5%
[libx264 @ 0xa53040] coded y,uvDC,uvAC intra: 43.4% 95.6% 69.6% inter: 16.9% 38.2% 7.4%
[libx264 @ 0xa53040] i16 v,h,dc,p: 35%  9% 36% 20%
[libx264 @ 0xa53040] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 11% 44%  5%  4%  5%  4%  5%  6%
[libx264 @ 0xa53040] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 21% 14%  6%  6%  5%  8%  6%  8%
[libx264 @ 0xa53040] i8c dc,h,v,p: 63% 17% 14%  6%
[libx264 @ 0xa53040] Weighted P-Frames: Y:0.4% UV:0.0%
[libx264 @ 0xa53040] ref P L0: 52.2% 47.8%
[libx264 @ 0xa53040] ref B L0: 95.4%  4.6%
[libx264 @ 0xa53040] ref B L1: 99.6%  0.4%
[libx264 @ 0xa53040] kb/s:769.35

(the same problem occurs even without -isync)

comment:5 in reply to: ↑ 3 Changed 5 years ago by cehoyos

Replying to cehoyos:

For future bugreports: Please do not use external libraries (in this case: libaacplus) if they are not needed to reproduce a problem.

Should have been "in this case: libaacplus and libx264"

comment:6 Changed 5 years ago by burek

This is also producing the same issue

ffmpeg \
	-f video4linux2 -r 25 -s vga -i /dev/video0 \
	-f alsa -ar 44100 -ac 1 -i front:CARD=U0x46d0x809,DEV=0 \
	-f mpegts udp://burek:10001

And now, I guess, you will say don't use udp, try to save to a file, so here it is:

ffmpeg \
	-f video4linux2 -r 25 -s vga -i /dev/video0 \
	-f alsa -ar 44100 -ac 1 -i front:CARD=U0x46d0x809,DEV=0 \
	out.ts
root@bla:~# ffmpeg -f video4linux2 -r 25 -s vga -i /dev/video0 -f alsa -ar 44100 -ac 1 -i front:CARD=U0x46d0x809,DEV=0 out.ts
ffmpeg version N-35149-g3880b45, Copyright (c) 2000-2011 the FFmpeg developers
  built on Nov 25 2011 02:16:49 with gcc 4.6.2
  configuration: --enable-static --enable-shared --enable-gpl --enable-nonfree --enable-postproc --enable-libx264 --enable-libaacplus --enable-libmp3lame --e
nable-libv4l2 --enable-libvo-aacenc --enable-version3
  libavutil    51. 28. 0 / 51. 28. 0
  libavcodec   53. 37. 0 / 53. 37. 0
  libavformat  53. 21. 0 / 53. 21. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 49. 0 /  2. 49. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[video4linux2,v4l2 @ 0xf46a20] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 136.366416, bitrate: 92160 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 640x480, 92160 kb/s, 25 tbr, 1000k tbn, 25 tbc
[alsa @ 0xf47a00] Estimating duration from bitrate, this may be inaccurate
Input #1, alsa, from 'front:CARD=U0x46d0x809,DEV=0':
  Duration: N/A, start: 1322479771.473944, bitrate: N/A
    Stream #1:0: Audio: pcm_s16le, 48000 Hz, 1 channels, s16, 768 kb/s
[buffer @ 0xf48ee0] w:640 h:480 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[mpegts @ 0xf49040] muxrate VBR, pcr every 2 pkts, sdt every 200, pat/pmt every 40 pkts
Output #0, mpegts, to 'out.ts':
  Metadata:
    encoder         : Lavf53.21.0
    Stream #0:0: Video: mpeg2video, yuv420p, 640x480, q=2-31, 200 kb/s, 90k tbn, 25 tbc
    Stream #0:1: Audio: mp2, 48000 Hz, 1 channels, s16, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> mpeg2video)
  Stream #1:0 -> #0:1 (pcm_s16le -> mp2)
Press [q] to stop, [?] for help
frame=  264 fps= 26 q=9.7 Lsize=     712kB time=00:00:10.15 bitrate= 574.5kbits/s dup=111 drop=0
video:468kB audio:159kB global headers:0kB muxing overhead 13.596405%

The problem still exists.

comment:7 follow-up: Changed 5 years ago by burek

Also, notice the ALSA inputs are always at 48000 Hz, but I've specifically added "-f alsa -ar 44100 -i ...". Should I report that as a bug too?

comment:8 in reply to: ↑ 7 Changed 5 years ago by cehoyos

Replying to burek:

Also, notice the ALSA inputs are always at 48000 Hz, but I've specifically added "-f alsa -ar 44100 -i ...". Should I report that as a bug too?

I suspect the sample rate is a hardware property, also see the documentation of snd_pcm_hw_params_set_rate_near() (that sets/gets the sample rate).

comment:9 Changed 5 years ago by cehoyos

  • Keywords v4l2 alsa added
  • Reproduced by developer set
  • Status changed from new to open

I can reproduce the problem on my system (Bt878) with the following command:

$ ffmpeg -f video4linux2 -i /dev/video1 -f alsa -i hw:2 -qscale 2 out.avi
ffmpeg version N-35260-g2cf4bd7, Copyright (c) 2000-2011 the FFmpeg developers
  built on Nov 28 2011 11:11:04 with gcc 4.5.3
  configuration: --cc='/usr/local/gcc-4.5.3/bin/gcc -m32'
  libavutil    51. 29. 1 / 51. 29. 1
  libavcodec   53. 38. 1 / 53. 38. 1
  libavformat  53. 22. 0 / 53. 22. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 50. 0 /  2. 50. 0
  libswscale    2.  1. 0 /  2.  1. 0
[video4linux2,v4l2 @ 0x8d98b00] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2,v4l2, from '/dev/video1':
  Duration: N/A, start: 1322486483.843191, bitrate: 132710 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 768x576, 132710 kb/s, 25 tbr, 1000k tbn, 25 tbc
[alsa @ 0x8d9f360] Estimating duration from bitrate, this may be inaccurate
Input #1, alsa, from 'hw:2':
  Duration: N/A, start: 1322486483.836794, bitrate: N/A
    Stream #1:0: Audio: pcm_s16le, 32000 Hz, 2 channels, s16, 1024 kb/s
[buffer @ 0x8d999a0] w:768 h:576 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
Incompatible sample format 's16' for codec 'ac3', auto-selecting format 'flt'
[ac3 @ 0x8d968e0] channel_layout not specified
[ac3 @ 0x8d968e0] No channel layout specified. The encoder will guess the layout, but it might be incorrect.
Output #0, avi, to 'out.avi':
  Metadata:
    ISFT            : Lavf53.22.0
    Stream #0:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 768x576, q=2-31, 200 kb/s, 25 tbn, 25 tbc
    Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 32000 Hz, stereo, flt, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> mpeg4)
  Stream #1:0 -> #0:1 (pcm_s16le -> ac3)
Press [q] to stop, [?] for help
frame= 1020 fps= 25 q=2.0 Lsize=  138227kB time=00:00:40.80 bitrate=27753.9kbits/s
video:137519kB audio:653kB global headers:0kB muxing overhead 0.039427%

The resulting file is out-of-sync, the amount is different for every run, works fine for me with -async 1 (but since your output is slightly difference, see "start:", that may not work for you).
The following command always results in files that are in-sync:

$ mencoder tv:// -ovc lavc -oac faac -lavcopts vqscale=2 -o out.avi

comment:10 Changed 5 years ago by cehoyos

Does -async 1 help in your case?
Did you test MEncoder? Is the resulting file in-sync?

comment:11 follow-up: Changed 4 years ago by stokholm

I have the same problem. For me at least -async 1 doesn't help. The audio is about a second late. I generated output with -report. I don't know if I'm allowed to post it all here, so I put it on pastebin.

comment:12 in reply to: ↑ 11 Changed 4 years ago by cehoyos

Replying to stokholm:

I generated output with -report. I don't know if I'm allowed to post it all here, so I put it on pastebin.

You *have* to post the command line and the complete, uncut console output here if you want help / want to help us.

comment:13 Changed 4 years ago by stokholm

Never mind. I just realized you asked not to use external libraries for bug reports. I'm getting this problem with libx264, not with the command line from (your) comment 9.

comment:14 Changed 4 years ago by cehoyos

Did you already try to put the video as the first input (with libx264, I mean)?

Changed 4 years ago by ewhac

Specifies audio input first; audio in final file is very late.

Changed 4 years ago by ewhac

Specifies video input first; audio in final file is slightly early.

comment:15 Changed 4 years ago by ewhac

I'm seeing the same problem, using a Pinnacle Dazzle DVC-100. Audio and video recorded from the device using ffmpeg are out of sync. However, they are out of sync differently depending on the order in which you specify the inputs on the command line.

I tried two invocations:

ffmpeg  -f alsa -i hw:1,0  -f v4l2 -i /dev/video0  -acodec mp2 -b:a 384k -vcodec mpeg2video -b:v 8000k -f mpegts badsync-av.mpg -report

This first one specifies the audio input on the command line first. In the final file, the audio is very late relative to the video.

ffmpeg  -f v4l2 -i /dev/video0  -f alsa -i hw:1,0  -acodec mp2 -b:a 384k -vcodec mpeg2video -b:v 8000k -f mpegts badsync-va.mpg -report

This second one specifies the video input on the command line first. In the final file, the audio is slightly early relative to the video.

All other arguments are identical. I've attached the -report logs to this bug.

Based on this behavior, I would guess that the input streams are not being synchronized/flushed before writing of the output file begins. In other words, stale data is accumulating in the FIFO of one device while the next one is being opened. In the case of a V4L2 device, this can take non-trivial time, allowing large amounts of audio data to accumulate.

Hopefully this was of some help to someone.

Version 0, edited 4 years ago by ewhac (next)

comment:16 Changed 4 years ago by cehoyos

  • Component changed from undetermined to avdevice
  • Resolution set to fixed
  • Status changed from open to closed

The original problem - that starttime is broken for -f v4l2 apparently leading to completely broken A/V sync - was fixed by adding some options specific for -f v4l2, see ffmpeg -h full ("V4L2 indev AVOptions").

For other problems, please open a new ticket.

Note: See TracTickets for help on using tickets.