如何避免ffmpeg内存不足错误 [英] How can I avoid an ffmpeg out of memory error

查看:211
本文介绍了如何避免ffmpeg内存不足错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用具有复杂过滤功能的ffmpeg.输入的是不同的FULLHD监视摄像机视频集,每组10到15秒长.设置大小(每套视频数量)各不相同.要删除未更改的帧,请应用mpdecimate.为了避免由于移动灌木丛而触发但仍保留我想保留的对象,我应用了一个复杂的过滤器:

I use ffmpeg with complex filtering. Input are different sets of FULLHD surveilance camera videos each 10 to 15 seconds long. Set size (number of videos per set) varies. To remove unchanged frames I apply mpdecimate. To avoid being triggered by moving bushes but still keep objects I want to remain, I apply a complex filter:

  • 分割视频(原始视频和虚拟视频以检测运动/静像)
  • 按比例缩小虚拟对象(因此mpdecimate的8x8块度量与我要保留的移动对象的大小匹配)
  • 在虚拟对象上添加白色框以遮盖意外移动的物体
  • 将mpdecimate应用于虚拟对象以删除不变的帧
  • 将假人缩放回原始大小
  • 用剩余的虚拟帧覆盖剩余的虚拟帧

如果输入视频的数量很少(少于100个),则所有这些都可以正常工作.ffmpeg进程的内存消耗在2GiB和5GiB之间变化.

All this works fine if the number of input videos is small (less than 100). The memory consupmtion of the ffmpeg process varies somewhere between 2GiB and 5GiB.

如果输入文件的数量变大(例如200个),则内存消耗突然激增到疯狂的数量,直到内存(32GiB加33GiB交换)用完并杀死ffmpeg.我无法预测这种情况是否发生以及为什么发生.我有一个例子,其中一组340个视频使用6GiB工作.我尝试播放的超过100个视频中的任何其他视频,在不到两分钟的时间内耗尽了所有RAM,并且死了.

If the number of input files gets larger (say 200), the memory consumption suddenly jumps to insane numbers until memory (32GiB plus 33GiB swap) runs out and ffmpeg gets killed. I can not predict if and why this happens. I have one example, where a set of 340 videos worked using 6GiB. Any other set above 100 videos I tried eats all RAM in under two minutes and dies.

ffmpeg没有特别的错误消息.

There is no particular error message from ffmpeg.

dmesg说:

Out of memory: Kill process 29173 (ffmpeg)
Killed process 29173 (ffmpeg) total-vm:66707800kB

我的ffmpeg命令:

My ffmpeg command:

ffmpeg -f concat -safe 0 -i vidlist -vf 'split=2[full][masked];[masked]scale=w=iw/4:h=ih/4,drawbox=w=51:h=153:x=101:y=0:t=fill:c=white,drawbox=w=74:h=67:x=86:y=49:t=fill:c=white,drawbox=w=51:h=149:x=258:y=0:t=fill:c=white,drawbox=w=13:h=20:x=214:y=103:t=fill:c=white,drawbox=w=29:h=54:x=429:y=40:t=fill:c=white,drawbox=w=35:h=49:x=360:y=111:t=fill:c=white,drawbox=w=26:h=54:x=304:y=92:t=fill:c=white,drawbox=w=48:h=27:x=356:y=105:t=fill:c=white,drawbox=w=30:h=27:x=188:y=124:t=fill:c=white,drawbox=w=50:h=54:x=371:y=7:t=fill:c=white,drawbox=w=18:h=38:x=248:y=107:t=fill:c=white,drawbox=w=21:h=51:x=242:y=33:t=fill:c=white,mpdecimate=hi=64*80:lo=64*40:frac=0.001,scale=w=iw*4:h=ih*4[deduped];[deduped][full]overlay=shortest=1,setpts=N/(15*TB),mpdecimate=hi=64*80:lo=64*50:frac=0.001,setpts=N/(15*TB)' -r 15 -c:v libx265 -preset slower -crf 37 -pix_fmt yuv420p -an result.mkv

ffmpeg版本4.1.6

ffmpeg version 4.1.6

Debian 4.19.171-2

Debian 4.19.171-2

我希望可以以某种方式调整我的过滤器,以达到相同的结果,但不会消耗太多RAM-但我不知道如何.在合理的范围内,我不介意处理时间受到影响.任何提示表示赞赏.

I hope that my filter can be tuned in some way that achieves the same result but doesn't eat RAM that much - but I have no clue how. Within reasonable limits, I wouldn't mind if processing time suffers. Any hints appreciated.

推荐答案

似乎可以通过删除拆分过滤器来避免出现内存问题.无需将一个输入分成两个流(ffmpeg必须将其存储在内存中),同一输入可以被加载两次.

It seems the memory issue can be avoided by removing the split filter. Instead of spliting one input into two streams (that ffmpeg has to store in memory) the same input can be loaded twice.

因此,与其使用"full",不如使用"full".和虚拟"如下

So instead of using "full" and "dummy" as below

ffmpeg -i source -vf 'split=2[full][dummy];...;[dummy][full]overlay...

一个将使用"0:v"和"1:v"就像

one would use "0:v" and "1:v" as in

ffmpeg -i source -i scource -filter_complex '.....;[0:v][1:v]overlay...

我可以将其用于输入视频,但到目前为止

I get this to work with input videos, but so far I fail to do this with the concat demuxer as input.

任何提示都非常欢迎.

这篇关于如何避免ffmpeg内存不足错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆