# ffmpeg + video4linux2 =  Cannot allocate memory



## pashap (Feb 14, 2015)

Hello,
I try to capture video from a USB camera and streem it. The ffmpeg works fine but after a while ffmpeg stop with error "av_interleaved_write_frame(): Cannot allocate memory". On Linux host ffmpeg work without this problem.

```
ffmpeg -f video4linux2 -r 25 -s 1280x720 -i /dev/video0 -an -c:v libx264 -f flv rtmp://****/hometest                                     
ffmpeg version 2.3.6 Copyright (c) 2000-2014 the FFmpeg developers
  built on Feb  8 2015 17:30:57 with FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
  configuration: --enable-libaacplus --disable-indev=alsa --disable-outdev=alsa --disable-libopencore-amrnb --disable-libopencore-amrwb --disable-libass --disable-libcdio --disable-libcelt --enable-libfaac --disable-libfdk-aac --disable-ffserver --disable-fontconfig --disable-libfreetype --enable-frei0r --disable-gnutls --disable-libgsm --enable-iconv --disable-indev=jack --enable-libmp3lame --disable-libbluray --enable-libv4l2 --disable-libmodplug --disable-openal --disable-indev=openal --enable-libopencv --enable-libopenjpeg --disable-openssl --disable-libopus --disable-libpulse --disable-indev=pulse --disable-outdev=pulse --disable-librtmp --enable-libschroedinger --disable-libspeex --enable-libtheora --disable-vaapi --disable-vdpau --enable-libvorbis --disable-libvo-aacenc --disable-libvo-amrwbenc --enable-libvpx --enable-libx264 --disable-libx265 --enable-libxvid --prefix=/usr/local --mandir=/usr/local/man --datadir=/usr/local/share/ffmpeg --enable-shared --enable-gpl --enable-postproc --enable-avfilter --enable-avresample --enable-pthreads --enable-memalign-hack --disable-libstagefright-h264 --disable-libutvideo --disable-libsoxr --cc=cc --extra-cflags='-msse -I/usr/local/include/vorbis -I/usr/local/include' --extra-ldflags='-L/usr/local/lib ' --extra-libs=-pthread --disable-debug --disable-ffplay --disable-outdev=sdl --enable-nonfree
  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
[video4linux2,v4l2 @ 0x808056420] The driver changed the time per frame from 1/25 to 1/30
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 2427664.835232, bitrate: 331776 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1280x720, 331776 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
[libx264 @ 0x808074520] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0x808074520] profile High, level 3.1
[libx264 @ 0x808074520] 264 - core 142 r2455 021c0dc - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://*****/hometest':
  Metadata:
    encoder         : Lavf55.48.100
    Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 1280x720, q=-1--1, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc55.69.100 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
av_interleaved_write_frame(): Cannot allocate memory5:13.20 bitrate=5683.1kbits/s   
[flv @ 0x808056a20] Failed to update header with correct duration.e=5683.2kbits/s   
[flv @ 0x808056a20] Failed to update header with correct filesize.
frame=67886 fps=7.5 q=-1.0 Lsize= 1882381kB time=00:45:13.36 bitrate=5683.2kbits/s   
video:1881056kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.070450%
[libx264 @ 0x808074520] frame I:305   Avg QP:22.37  size: 76041
[libx264 @ 0x808074520] frame P:34688 Avg QP:25.30  size: 32685
[libx264 @ 0x808074520] frame B:32893 Avg QP:26.36  size: 23431
[libx264 @ 0x808074520] consecutive B-frames:  3.1% 96.9%  0.0%  0.0%
[libx264 @ 0x808074520] mb I  I16..4:  1.6% 90.0%  8.4%
[libx264 @ 0x808074520] mb P  I16..4:  0.5%  8.2%  0.1%  P16..4: 55.1% 22.1% 13.8%  0.0%  0.0%    skip: 0.2%
[libx264 @ 0x808074520] mb B  I16..4:  0.3%  4.2%  0.0%  B16..8: 44.2%  3.6%  0.8%  direct:34.7%  skip:12.3%  L0:53.1% L1:40.6% BI: 6.2%
[libx264 @ 0x808074520] 8x8 transform intra:92.8% inter:87.3%
[libx264 @ 0x808074520] coded y,uvDC,uvAC intra: 74.7% 99.9% 98.1% inter: 36.4% 92.3% 69.3%
[libx264 @ 0x808074520] i16 v,h,dc,p: 11% 35%  4% 50%
[libx264 @ 0x808074520] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 10% 18% 31%  6%  7%  6%  9%  6%  7%
[libx264 @ 0x808074520] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 23% 21%  7%  9%  5% 10%  4%  6%
[libx264 @ 0x808074520] i8c dc,h,v,p: 71% 11%  9%  9%
[libx264 @ 0x808074520] Weighted P-Frames: Y:37.1% UV:31.8%
[libx264 @ 0x808074520] ref P L0: 32.7%  8.5% 23.2% 25.9%  9.6%
[libx264 @ 0x808074520] ref B L0: 56.5% 43.5%
[libx264 @ 0x808074520] kb/s:5679.23
Conversion failed!
```


```
ffmpeg-2.3.6,1                 Realtime audio/video encoder/converter and streaming server
webcamd-3.18.0.1               Port of Linux USB webcam and DVB drivers into userspace

ugen1.5: <Microsoft LifeCam StudioTM Microsoft> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (500mA)
```


----------

