If multiple videos are uploaded in a directory, thumbnails will be generated at the same time when they are accessed for the first time, which will cause the server with low configuration to crash.
Submitted almost at the same time
Yes of course. They are requested as soon as the visitors browser is trying to display them, which is often at the same time for several thumbnails. What do you propose?amwpsaa wrote:Submitted almost at the same time
Can you please tell me exactly how it "crashes directly"? I saw your screenshot, and that is NOT crash, but TIMEOUT. If the server crashes, it means it dies and requires restart. FFmpeg is command-line, and is not part of PHP ... PHP just waits for it to execute. I would like to understand how server crashes from this ... Screenshots or errorlog?amwpsaa wrote:After my testing, 10 videos can cause the low-configuration server to crash directly,
Is this some solution you have implemented? If so, please tell me how ...amwpsaa wrote:The solution I came up with: 1. Use the queue method to submit processing. 2, use a timer, the interval must be to process a request
$cmd = escapeshellarg( ...
set_time_limit(300); // seconds $cmd = escapeshellarg( ...
I don't think this is related. I have seen FFmpeg create 0kb thumbnails when it encounters video formats that it cannot process for some reason. We cannot detect this through PHP. Besides, if there is a PHP timeout while FFmpeg is processing, the PHP will stop processing without creating the thumbnail.amwpsaa wrote:and there will be a part of the thumbnail size of 0, not displayed properly.
So you added -threads 2 and removed -t 1? I don't see how "threads" will help much, because the lower the value, the less CPU used, but the slower the process will be. The total CPU required to process video thumbnail requests will remain the same. As for removing "-t 1" yes that can speed up requests, because FFmpeg doesn't have to fast-forward to 1 second into the video. However, my tests showed that without this value, thumbnails were often created from the very beginning of videos, often causing a black thumbnail.amwpsaa wrote:Code
// ffmpeg command $cmd = escapeshellarg(config::$config['video_ffmpeg_path']) . ' -i ' . escapeshellarg($path) . ' -threads 2 -an -ss 1 -s 480x320 -vf "thumbnail,scale=480:320:force_original_aspect_ratio=increase,crop=480:320" -r 1 -y -f image2 -vframes 1 ' . $cache . ' 2>&1';
$cmd = escapeshellarg(...
$cmd = escapeshellarg(config::$config['video_ffmpeg_path']) . ' -ss 3 -t 1 -hide_banner -i "' . str_replace('"', '\"', $path) . '" -vframes:v 1 -an -vf "thumbnail,scale=480:320:force_original_aspect_ratio=increase,crop=480:320" -r 1 -y -f mjpeg "' . $cache . '" 2>&1';