TransWikia.com

Is there any way to limit FFmpeg’s memory usage?

Super User Asked by Will B on November 12, 2021

I am using FFmpeg via command line for some video encoding from within a Docker container on a VM running Windows Server 2016. My concern is that this is using up a large percentage of the available RAM. This is not desirable, as I have numerous other containers running on the same VM.

Is it possible to limit the RAM used by FFmpeg through a setting or command line argument? If not, how might I go about achieving a similar result?

Below are some (non-ideal) possibilities that I have considered outside of FFMPEG. I would appreciate any thoughts on these.

  • Use Windows System Resource Manager to limit process RAM usage
  • Apply logic that only allows FFmpeg to start an encode while 8+ GB of RAM is available
  • Launch it in a docker equipped with limited RAM

The problem with memory usage (4GB+) occurs when I am converting (small 35MB) videos to GIF via this command:

ffmpeg -i C:testvidmp4.mp4 -vf "fps=24,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" C:temptestgif.gif

2 Answers

I experienced extensive RAM usage when using the split filter. In some situations I got a lot less RAM usage when avoiding the split filter.

Instead of using split you can try to load the same input twice and process the two inputs individually until you merge them (potentially at the cost of some extra processing time).

So in your case try something like:

ffmpeg -i C:testvidmp4.mp4 -i C:testvidmp4.mp4 -vf "[0:v]fps=24,scale=320:-1:flags=lanczos[s0];[1:v]fps=24,scale=320:-1:flags=lanczos[s1];[s0]palettegen[p];[s1][p]paletteuse" C:temptestgif.gif

Answered by Silentfury on November 12, 2021

ffmpeg does not use any RAM, that it not actually needs. Typically this is very little.

If you ffmpeg processes really use a lot of RAM (a.o.t a misinterpretation of some reading), then limiting its RAM allotment will just make it crash with an OOM condition.

If you tell us about your ffmpeg command line, we might be able to suggest alternatives, that use less RAM.

Answered by Eugen Rieck on November 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP