mediacms-io / mediacms

MediaCMS is a modern, fully featured open source video and media CMS, written in Python/Django and React, featuring a REST API.
https://mediacms.io
GNU Affero General Public License v3.0
2.52k stars 459 forks source link

Add configuration to set how many threads each ffmpeg process can use #886

Open KyleMaas opened 9 months ago

KyleMaas commented 9 months ago

Description

I was running into issues where, while transcoding, a single server would get a load average of over 4x the number of cores it had. This turned out to be a combination of Celery running as many tasks concurrently as it could and each ffmpeg process using all cores. This would result in a ton of chunks' transcoding processes competing for CPU, which would cause them to time out. This change allows you to at least limit the number of threads that ffmpeg can use concurrently so you can actually tune transcoding CPU usage properly.

Steps

Pre-deploy

Post-deploy

tobocop2 commented 9 months ago

I noticed this as well, I think this should be merged in as well @mgogoulos

tobocop2 commented 9 months ago

@KyleMaas i think this threads setting should also be applied to the

produce_sprite_from_video and produce_thumbnails_from_video functions.

and this block

    if profile.extension == "gif":
        tf = create_temp_file(suffix=".gif")
        # -ss 5 start from 5 second. -t 25 until 25 sec
        command = [
            settings.FFMPEG_COMMAND,
            "-y",
            "-ss",
            "3",
            "-i",
            media.media_file.path,
            "-hide_banner",
            "-vf",
            "scale=344:-1:flags=lanczos,fps=1",
            "-t",
            "25",
            "-f",
            "gif",
            tf,
        ]

in tasks.py

These commands are vulnerable to the same problem.

KyleMaas commented 8 months ago

@tobocop2 Good idea. Implemented.

dogweather commented 8 months ago

Ping