Timeout error while running FFmpeg as a process in php

Viewed 1039

I'm trying to create a process for FFmpeg video compression at runtime. In my local system, it runs within 30 seconds. When I tried to run it in the server, it starts throwing a timeout error after 60 seconds. When I manually ran the command in the server, it took around 2 minutes. I came to know that some configuration in php.ini needs to be modified. I tried changing the configuration of the process to 300 seconds. Still, the same timeout error is being outputted.

The process "/usr/bin/ffmpeg -i '/var/temp/5e7de5a9de7c2/creme bulee-01-infuse
the cream and milk.mp4' -s 1668x2224 -c:a copy '/var/temp/5e7de5a9de7c2/compre
ssed/temp_creme bulee-01-infuse the cream and milk_1668x2224.mp4'" exceeded th
e timeout of 60 seconds.

In php.ini, I have the following configuration:

max_execution_time = 300 
max_input_time = 300

How do I stop my process from timing out?

2 Answers

I was have same error, you need to add settings in FFMpeg::create and use FFMpeg::create

$ffmpeg = FFMpeg::create(
  array(
   'timeout' => 0, // The timeout for the underlying process
  )
);
$ffmpeg->open($video_path);

More info here https://github.com/PHP-FFMpeg/PHP-FFMpeg

max_execution_time directive in php.ini does not affect shell commands as noted in the manual (see https://www.php.net/manual/en/function.set-time-limit.php for details)

My wild guess is that you are using Symfony\Component\Process\Process as by default it's timeout is exactly 60 seconds and your error message looks familiar. If I'm right, please try increasing the timeout:

$process = new Process($ffmpeg_cmdline);
$process->setTimeout(3600);
$process->run();
Related