视频监控项目中ffmpeg录制MP4报错

最开始以为板子性能不足导致运行ffmpeg的进程被杀死,但是调低帧数和画面质量降低板子资源的利用率依然会报错。求助!

命令执行的打印信息如下:

[root@100ask:~]# ffmpeg -f v4l2 -framerate 10 -i /dev/video0 -q 10 my.mp4

ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers

built with gcc 8.4.0 (Buildroot 2020.02-g85b7ab8)

configuration: --enable-cross-compile --cross-prefix=/home/book/100ask_stm32mp157_pro-sdk/Buildroot_2020.02.x/output/host/bin/arm-buildroot-linux-gnueabihf- --sysroot=/home/book/100ask_stm32mp157_pro-sdk/Buildroot_2020.02.x/output/host/arm-buildroot-linux-gnueabihf/sysroot --host-cc=’/home/book/100ask_stm32mp157_pro-sdk/Buildroot_2020.02.x/output/host/bin/ccache /usr/bin/gcc’ --arch=arm --target-os=linux --disable-stripping --pkg-config=/home/book/100ask_stm32mp157_pro-sdk/Buildroot_2020.02.x/output/host/bin/pkg-config --disable-static --enable-shared --prefix=/usr --enable-avfilter --disable-version3 --enable-logging --enable-optimizations --disable-extra-warnings --enable-avdevice --enable-avcodec --enable-avformat --enable-network --disable-gray --enable-swscale-alpha --disable-small --enable-dct --enable-fft --enable-mdct --enable-rdft --disable-crystalhd --disable-dxva2 --enable-runtime-cpudetect --disable-hardcoded-tables --disable-mipsdsp --disable-mipsdspr2 --disable-msa --enable-hwaccels --disable-cuda --disable-cuvid --disable-nvenc --disable-avisynth --disable-frei0r --disable-libopencore-amrnb --disable-libopencore-amrwb --disable-libdc1394 --disable-libgsm --disable-libilbc --disable-libvo-amrwbenc --disable-symver --disable-doc --enable-gpl --enable-nonfree --enable-ffmpeg --disable-ffplay --enable-avresample --disable-ffprobe --disable-libxcb --disable-postproc --enable-swscale --enable-indevs --enable-alsa --enable-outdevs --enable-pthreads --enable-zlib --enable-bzlib --enable-libfdk-aac --disable-libcdio --disable-gnutls --enable-openssl --enable-libdrm --enable-libopenh264 --enable-libvorbis --enable-muxer=ogg --enable-encoder=libvorbis --enable-vaapi --disable-vdpau --disable-mmal --disable-omx --disable-omx-rpi --disable-libopencv --enable-libopus --enable-libvpx --enable-libass --disable-libbluray --disable-libmfx --enable-librtmp --enable-libmp3lame --disable-libmodplug --enable-libspeex --enable-libtheora --enable-libwavpack --disable-iconv --enable-libfreetype --enable-fontconfig --enable-libopenjpeg --enable-libx264 --disable-libx265 --disable-libdav1d --disable-x86asm --disable-mmx --disable-sse --disable-sse2 --disable-sse3 --disable-ssse3 --disable-sse4 --disable-sse42 --disable-avx --disable-avx2 --enable-armv6 --enable-vfp --enable-neon --disable-altivec --extra-libs=-latomic --enable-pic --cpu=cortex-a7

libavutil 56. 31.100 / 56. 31.100

libavcodec 58. 54.100 / 58. 54.100

libavformat 58. 29.100 / 58. 29.100

libavdevice 58. 8.100 / 58. 8.100

libavfilter 7. 57.100 / 7. 57.100

libavresample 4. 0. 0 / 4. 0. 0

libswscale 5. 5.100 / 5. 5.100

libswresample 3. 5.100 / 3. 5.100

[video4linux2,v4l2 @ 0x72c00] The driver changed the time per frame from 1/10 to 1/5

Input #0, video4linux2,v4l2, from ‘/dev/video0’:

Duration: N/A, start: 1494.781436, bitrate: 165888 kb/s

Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc

Stream mapping:

Stream #0:0#0:0 (rawvideo (native) → h264 (libx264))

Press [q] to stop, [?] for help

[libx264 @ 0x76cd0] -qscale is ignored, -crf is recommended.

[libx264 @ 0x76cd0] using cpu capabilities: ARMv6 NEON

[libx264 @ 0x76cd0] profile High 4:2:2, level 4.0, 4:2:2, 8-bit

[libx264 @ 0x76cd0] 264 - core 157 - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - x264, the best H.264/AVC encoder - VideoLAN - 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=3 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=5 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, mp4, to ‘my.mp4’:

Metadata:

encoder         : Lavf58.29.100

Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv422p, 1920x1080, q=-1--1, 5 fps, 10240 tbn, 5 tbc

Metadata:

  encoder         : Lavc58.54.100 libx264

Side data:

  cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1

[ 1499.418094] ffmpeg invoked oom-killer: gfp_mask=0x100cca(GFP_HIGHUSER_MOVABLE), order=0, oom_score_adj=0

[ 1499.426912] CPU: 0 PID: 15332 Comm: ffmpeg Tainted: G O 5.4.31 #1

[ 1499.433547] Hardware name: STM32 (Device Tree Support)

[ 1499.438723] [] (unwind_backtrace) from [] (show_stack+0x10/0x14)

[ 1499.446456] [] (show_stack) from [] (dump_stack+0xb0/0xc4)

[ 1499.453687] [] (dump_stack) from [] (dump_header+0x54/0x208)

[ 1499.461094] [] (dump_header) from [] (oom_kill_process+0x174/0x180)

[ 1499.469109] [] (oom_kill_process) from [] (out_of_memory+0x108/0x334)

[ 1499.477301] [] (out_of_memory) from [] (__alloc_pages_slowpath+0xde8/0x1058)

[ 1499.486103] [] (__alloc_pages_slowpath) from [] (__alloc_pages_nodemask+0x228/0x348)

[ 1499.495601] [] (__alloc_pages_nodemask) from [] (handle_mm_fault+0x4dc/0xbe0)

[ 1499.504488] [] (handle_mm_fault) from [] (do_page_fault+0x114/0x3d4)

[ 1499.512592] [] (do_page_fault) from [] (do_DataAbort+0x3c/0xbc)

[ 1499.520260] [] (do_DataAbort) from [] (__dabt_usr+0x3c/0x40)

[ 1499.527660] Exception stack(0xc4bd3fb0 to 0xc4bd3ff8)

[ 1499.532718] 3fa0: 9a1f3000 00000040 a2d9d390 00000000

[ 1499.540911] 3fc0: a2c9d390 00000000 000003c0 0000031e 00000001 00000000 001ef130 00000000

[ 1499.549099] 3fe0: 00000438 beb2c73c 000001d0 b4a1ef3c 200f0010 ffffffff

[ 1499.559742] Mem-Info:

[ 1499.560744] active_anon:57927 inactive_anon:513 isolated_anon:0

[ 1499.560744] active_file:16 inactive_file:107 isolated_file:0

[ 1499.560744] unevictable:0 dirty:1 writeback:0 unstable:0

[ 1499.560744] slab_reclaimable:2858 slab_unreclaimable:6065

[ 1499.560744] mapped:32443 shmem:596 pagetables:505 bounce:0

[ 1499.560744] free:956 free_pcp:12 free_cma:100

[ 1499.594438] Node 0 active_anon:231720kB inactive_anon:2052kB active_file:52kB inactive_file:440kB unevictable:0kB isolated(anon):0kB isolated(file):0kB mapped:129768kB dirty:4kB writeback:0kB shmem:2384kB writeback_tmp:0kB unstable:0kB all_unreclaimable? no

[ 1499.616405] Normal free:3584kB min:2204kB low:2752kB high:3300kB active_anon:231604kB inactive_anon:2052kB active_file:0kB inactive_file:716kB unevictable:0kB writepending:4kB present:458752kB managed:435908kB mlocked:0kB kernel_stack:1016kB pagetables:2020kB bounce:0kB free_pcp:32kB local_pcp:32kB free_cma:204kB

[ 1499.643946] lowmem_reserve[]: 0 0 0

[ 1499.647382] Normal: 2894kB (U) 1018kB (UE) 5316kB (UE) 832kB (UE) 464kB (U) 0128kB 0256kB 0512kB 01024kB 02048kB 04096kB 08192kB = 3324kB

[ 1499.660812] 812 total pagecache pages

[ 1499.664410] 0 pages in swap cache

[ 1499.667781] Swap cache stats: add 0, delete 0, find 0/0

[ 1499.672946] Free swap = 0kB

[ 1499.675816] Total swap = 0kB

[ 1499.679166] 114688 pages RAM

[ 1499.681563] 0 pages HighMem/MovableOnly

[ 1499.685410] 5711 pages reserved

[ 1499.688602] 32768 pages cma reserved

[ 1499.693206] Tasks state (memory values in pages):

[ 1499.696819] [ pid ] uid tgid total_vm rss pgtables_bytes swapents oom_score_adj name

[ 1499.705583] [ 200] 0 200 24423 136 34816 0 -250 systemd-journal

[ 1499.714631] [ 206] 0 206 1802 68 12288 0 0 systemd-time-wa

[ 1499.724722] [ 214] 0 214 2052 154 14336 0 -1000 systemd-udevd

[ 1499.732601] [ 221] 1008 221 2025 92 12288 0 0 systemd-network

[ 1499.741627] [ 228] 1010 228 4203 93 16384 0 0 systemd-timesyn

[ 1499.751236] [ 232] 1009 232 2578 140 16384 0 0 systemd-resolve

[ 1499.760858] [ 239] 1000 239 1439 111 12288 0 -900 dbus-daemon

[ 1499.769164] [ 248] 0 248 25049 525 28672 0 0 pulseaudio

[ 1499.777098] [ 267] 0 267 5572 123 20480 0 0 gsettings-helpe

[ 1499.786122] [ 315] 0 315 8048 65 22528 0 0 adbd

[ 1499.794272] [ 330] 0 330 1851 85 14336 0 0 systemd-logind

[ 1499.804498] [ 368] 0 368 2079 88 12288 0 0 bluetoothd

[ 1499.812117] [ 372] 0 372 857 104 10240 0 0 bash

[ 1499.820051] [ 384] 0 384 1589 103 12288 0 -1000 sshd

[ 1499.828043] [ 410] 0 410 604 46 10240 0 0 usbipd

[ 1499.837531] [ 420] 0 420 77742 6087 221184 0 0 mxapp2

[ 1499.844554] [ 447] 0 447 4699 203 22528 0 0 nginx

[ 1499.852853] [ 449] 33 449 4767 262 24576 0 0 nginx

[ 1499.861041] [ 450] 33 450 4767 262 24576 0 0 nginx

[ 1499.870266] [ 477] 0 477 709 119 10240 0 0 dhcpcd

[ 1499.877493] [ 534] 1001 534 2007 141 16384 0 0 mosquitto

[ 1499.885990] [ 539] 0 539 13938 13363 61440 0 0 rpc.statd

[ 1499.895650] [ 543] 0 543 1254 73 12288 0 0 rpcbind

[ 1499.903630] [ 15332] 0 15332 118973 67977 376832 0 0 ffmpeg

[ 1499.911282] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/system.slice/system-serial\x2dgetty.slice/serial-getty@ttySTM0.service,task=ffmpeg,pid=15332,uid=0

[ 1499.930052] Out of memory: Killed process 15332 (ffmpeg) total-vm:475892kB, anon-rss:142236kB, file-rss:129672kB, shmem-rss:0kB, UID:0 pgtables:368kB oom_score_adj:0

[ 1500.038123] oom_reaper: reaped process 15332 (ffmpeg), now anon-rss:0kB, file-rss:129664kB, shmem-rss:0kB

Killed

frame采集到几十就直接打印下面的报错信息


板子资源利用情况