Sanasar Yuzbashyan
Sanasar Yuzbashyan

Reputation: 764

How to reduce usage of CPU/memory by ffmpeg?

I know there are many questions about this topic, but I still haven't found what I'm looking for. I am using ffmpeg on the website to create a video from image+audio+waveform. In the beginning my code used 100% of CPU to create video. After I started looking for a performance solution, I found several solutions and used them. I added the following commands
nice -19 cpulimit -l 30 -- ffmpeg -y -threads 1 -i ... after which everything worked very well and the CPU usage did not exceed 35-45%. But when I tried to run this command at the same time 4 times everything got really bad. Here is a picture of what happened.

enter image description here

This is my code

nice -19 cpulimit -l 30 -- ffmpeg -y -i image.jpg -i audio.mp3 -filter_complex "[0:v]scale=1280x720[image]; [image]drawbox=x=0:y=720:w=1280:h=130:color=red@1:t=fill[img];[1:a]showwaves=s=1280x130:colors=green:mode=cline,format=yuva420p[wave];[img][wave]overlay=0:350[outv]" map 1:a -c:a copy -map "[outv]" -c:v libx264 -preset medium -threads 1 output.mp4

And now I cannot understand how I can organize all this on a production server where 1000 users can simultaneously run this command when they create a video. I thought it would be better if a separate server was used for such resource-intensive processes so that the work of the site would not interrupt. But still, how can I organize this whole difficult process when I have a lot of users on my site, and they can simultaneously use this functionality? Thank you in advance.

Upvotes: 1

Views: 1284

Answers (1)

mPrinC
mPrinC

Reputation: 9401

You should use some task manager (like Celery) or queue broker (like RabbitMQ) and schedule your users and handle your parallel tasks.

Additionally, it is smarter to have to independent servers, one for handling web services and the 2nd one handling video processing. All that can be managed with the above-mentioned tools

Upvotes: 1

Related Questions