[FFmpeg-user] Video grabbing from webcam drops and duplicates frames

David Ventura davidventura27 at gmail.com
Wed Aug 27 02:00:23 CEST 2014


Hi

I'm trying to record and stream my webcam (LifeCam Studio) with ffmpeg, but
the output has (most of the time) drops and dupes. Lots of them, to the
point where the video effectively reaches 1fps (there are about 29
duplicated frames every second, with 1 "good" frame)

Setting the input framerate to 20 makes it happen less often.

Here's a 'good' output (after running v4l2-ctl to set the camera state)

v4l2-ctl -d $device --set-parm=20
--set-fmt-video=width=1280,height=720,pixelformat=1
v4l2-ctl -d $device --set-ctrl
focus_absolute=20,zoom_absolute=0,exposure_auto=1,exposure_absolute=78


ffmpeg -f v4l2 -input_format mjpeg -video_size 1280x720 -i /dev/video1 -c:v
libx264 -preset veryfast -tune zerolatency -y /compilin/asd.mp4
ffmpeg version 2.3.3 Copyright (c) 2000-2014 the FFmpeg developers
  built on Aug 18 2014 06:26:16 with gcc 4.9 (Debian 4.9.1-6)
  configuration: --prefix=/usr --extra-cflags='-g -O2
-fstack-protector-strong -Wformat -Werror=format-security '
--extra-ldflags='-Wl,-z,relro' --cc='ccache cc' --enable-shared
--enable-libmp3lame --enable-gpl --enable-nonfree --enable-libvorbis
--enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc
--enable-x11grab --enable-libgsm --enable-libtheora
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264
--enable-libspeex --enable-nonfree --disable-stripping --enable-libvpx
--enable-libschroedinger --disable-encoder=libschroedinger
--enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter
--enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb
--enable-libvo-amrwbenc --enable-libaacplus
--libdir=/usr/lib/x86_64-linux-gnu --disable-vda --enable-libbluray
--enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl
--enable-libass --enable-libopus --enable-fontconfig --enable-libpulse
--disable-mips32r2 --disable-mipsdspr1 --disable-mipsdspr2
--enable-libvidstab --enable-libzvbi --enable-avresample
--disable-htmlpages --disable-podpages --enable-libiec61883
--enable-libfdk-aac --enable-vaapi --enable-libx265 --enable-libdc1394
--disable-altivec --disable-armv5te --disable-armv6
--shlibdir=/usr/lib/x86_64-linux-gnu
  libavutil      52. 92.100 / 52. 92.100
  libavcodec     55. 69.100 / 55. 69.100
  libavformat    55. 48.100 / 55. 48.100
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.100 /  4. 11.100
  libavresample   1.  3.  0 /  1.  3.  0
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, video4linux2,v4l2, from '/dev/video1':
  Duration: N/A, start: 33606.265487, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg), 1280x720, -3 kb/s, 20
fps, 20 tbr, 1000k tbn, 1000k tbc
No pixel format specified, yuvj422p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x11f4140] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
AVX XOP FMA4 FMA3 LZCNT BMI1
[libx264 @ 0x11f4140] profile High 4:2:2, level 3.1, 4:2:2 8-bit
[libx264 @ 0x11f4140] 264 - core 142 - H.264/MPEG-4 AVC codec - Copyleft
2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=1
deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00
mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11
fast_pskip=1 chroma_qp_offset=0 threads=8 lookahead_threads=8
sliced_threads=1 slices=8 nr=0 decimate=1 interlaced=0 bluray_compat=0
constrained_intra=0 bframes=0 weightp=1 keyint=250 keyint_min=20
scenecut=40 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0
qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/compilin/asd.mp4':
  Metadata:
    encoder         : Lavf55.48.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuvj422p,
1280x720, q=-1--1, 20 fps, 10240 tbn, 20 tbc
    Metadata:
      encoder         : Lavc55.69.100 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame=  290 fps= 20 q=25.0 Lsize=    5897kB time=00:00:14.50
bitrate=3331.6kbits/s dup=0 drop=142
video:5893kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 0.067810%
[libx264 @ 0x11f4140] frame I:2     Avg QP:11.93  size: 30074
[libx264 @ 0x11f4140] frame P:288   Avg QP:21.37  size: 20742
[libx264 @ 0x11f4140] mb I  I16..4: 55.4% 40.7%  3.9%
[libx264 @ 0x11f4140] mb P  I16..4: 10.5% 21.5%  0.0%  P16..4: 40.6%  6.5%
1.6%  0.0%  0.0%    skip:19.3%
[libx264 @ 0x11f4140] 8x8 transform intra:66.5% inter:67.4%
[libx264 @ 0x11f4140] coded y,uvDC,uvAC intra: 49.7% 68.6% 60.0% inter:
7.3% 55.4% 20.8%
[libx264 @ 0x11f4140] i16 v,h,dc,p: 35% 20% 39%  6%
[libx264 @ 0x11f4140] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 15% 55%  3%  2%
2%  3%  2%  3%
[libx264 @ 0x11f4140] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 17% 23%  5%  5%
8%  5%  5%  4%
[libx264 @ 0x11f4140] i8c dc,h,v,p: 74%  7% 14%  4%
[libx264 @ 0x11f4140] Weighted P-Frames: Y:7.6% UV:1.0%
[libx264 @ 0x11f4140] kb/s:3329.05


And here the camera took about 1 second to initialize:

ffmpeg -f v4l2 -input_format mjpeg -video_size 1280x720 -i /dev/video1 -c:v
libx264 -preset veryfast -tune zerolatency -y /compilin/asd.mp4
ffmpeg version 2.3.3 Copyright (c) 2000-2014 the FFmpeg developers
  built on Aug 18 2014 06:26:16 with gcc 4.9 (Debian 4.9.1-6)
  configuration: --prefix=/usr --extra-cflags='-g -O2
-fstack-protector-strong -Wformat -Werror=format-security '
--extra-ldflags='-Wl,-z,relro' --cc='ccache cc' --enable-shared
--enable-libmp3lame --enable-gpl --enable-nonfree --enable-libvorbis
--enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc
--enable-x11grab --enable-libgsm --enable-libtheora
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264
--enable-libspeex --enable-nonfree --disable-stripping --enable-libvpx
--enable-libschroedinger --disable-encoder=libschroedinger
--enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter
--enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb
--enable-libvo-amrwbenc --enable-libaacplus
--libdir=/usr/lib/x86_64-linux-gnu --disable-vda --enable-libbluray
--enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl
--enable-libass --enable-libopus --enable-fontconfig --enable-libpulse
--disable-mips32r2 --disable-mipsdspr1 --disable-mipsdspr2
--enable-libvidstab --enable-libzvbi --enable-avresample
--disable-htmlpages --disable-podpages --enable-libiec61883
--enable-libfdk-aac --enable-vaapi --enable-libx265 --enable-libdc1394
--disable-altivec --disable-armv5te --disable-armv6
--shlibdir=/usr/lib/x86_64-linux-gnu
  libavutil      52. 92.100 / 52. 92.100
  libavcodec     55. 69.100 / 55. 69.100
  libavformat    55. 48.100 / 55. 48.100
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.100 /  4. 11.100
  libavresample   1.  3.  0 /  1.  3.  0
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, video4linux2,v4l2, from '/dev/video1':
  Duration: N/A, start: 33843.648665, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg), 1280x720, -5 kb/s, 30
fps, 30 tbr, 1000k tbn, 1000k tbc
No pixel format specified, yuvj422p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x25f7140] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
AVX XOP FMA4 FMA3 LZCNT BMI1
[libx264 @ 0x25f7140] profile High 4:2:2, level 3.1, 4:2:2 8-bit
[libx264 @ 0x25f7140] 264 - core 142 - H.264/MPEG-4 AVC codec - Copyleft
2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=1
deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00
mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11
fast_pskip=1 chroma_qp_offset=0 threads=8 lookahead_threads=8
sliced_threads=1 slices=8 nr=0 decimate=1 interlaced=0 bluray_compat=0
constrained_intra=0 bframes=0 weightp=1 keyint=250 keyint_min=25
scenecut=40 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0
qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/compilin/asd.mp4':
  Metadata:
    encoder         : Lavf55.48.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuvj422p,
1280x720, q=-1--1, 30 fps, 15360 tbn, 30 tbc
    Metadata:
      encoder         : Lavc55.69.100 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame= 1997 fps=222 q=25.0 Lsize=    2409kB time=00:01:06.56 bitrate=
296.4kbits/s dup=1990 drop=28
video:2386kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 0.935014%
[libx264 @ 0x25f7140] frame I:9     Avg QP: 7.30  size:104081
[libx264 @ 0x25f7140] frame P:1988  Avg QP: 9.79  size:   758
[libx264 @ 0x25f7140] mb I  I16..4: 34.6% 42.2% 23.1%
[libx264 @ 0x25f7140] mb P  I16..4:  0.1%  0.1%  0.0%  P16..4:  3.1%  0.1%
0.0%  0.0%  0.0%    skip:96.7%
[libx264 @ 0x25f7140] 8x8 transform intra:46.1% inter:17.6%
[libx264 @ 0x25f7140] coded y,uvDC,uvAC intra: 82.7% 43.4% 38.8% inter:
0.9% 0.6% 0.3%
[libx264 @ 0x25f7140] i16 v,h,dc,p: 32% 12% 52%  4%
[libx264 @ 0x25f7140] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 15% 50%  3%  2%
2%  2%  3%  4%
[libx264 @ 0x25f7140] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 18% 17%  7%  6%
7%  6%  7%  6%
[libx264 @ 0x25f7140] i8c dc,h,v,p: 82%  5% 11%  3%
[libx264 @ 0x25f7140] Weighted P-Frames: Y:0.1% UV:0.1%
[libx264 @ 0x25f7140] kb/s:293.61


Upon starting to record, I noticed that the time is 1 minute and the fps is
way above the maximum for the camera, but it's duplicating A LOT.Maybe
there's a buffer somewhere that's full?

If I see the camera with qv4l2 it works perfectly.
And also, on the cases that it actually works, the image sometimes gets
frozen (duplicates the same frame 30 times, over the course of 1 second)


The /complin dir is on ram
If there's anything else I should attach or try please let me know.

Thanks

-- 
We need only a little more code,and little more money,and little more time,
and little more sleep but the world needs a lot more freedom


More information about the ffmpeg-user mailing list