1
I have a script that goes through a directory looking for video files in it and then I use the shell_exec
with the ffmpeg
to convert the same, the problem is that my site is falling while running the script, after booting the same on the server, the site falls and cannot access until I terminate the script, I am using the Wamp installed on a Windows Server 2012.
I think maybe the problem is in memory_limit
in PHP.ini which is in 128m
, but not sure, there is some solution to prevent my site from falling during that process?
This is my summary script:
if($handle = opendir($diretorio)){
while ($entry = readdir($handle)){
$ext = strtolower(pathinfo($entry, PATHINFO_EXTENSION));
if(in_array($ext, $types)){
$ep = explode('.', $entry);
$input = $diretorio.$entry;
$cmd = $ffmpeg.' -i '.$input.' -hide_banner 2>&1 &';
$exec = shell_exec($cmd);
$data = trim($exec);
$x = getStreams($data);
$video_key = array_search('Video', array_column($x, 'formato'));
$video_map = $x[$video_key]["tempo"];
foreach ($x as $index => $value){
#esse if se repete mais 4x procurando outros formatos e/ou idiomas
if($value["formato"] === "Audio" && ($value["idioma"] === "jpn" || $value["idioma"] === "eng")){
$audio_map = $value["tempo"];
$output_legendado = $dir_original_saida.$ep["0"].".mp4";
if (!is_dir($dir_original_saida)) {
mkdir($dir_original_saida, 0777, true);
}
if(!file_exists($output_legendado)){
$query = " -sn -map $video_map -map $audio_map -vcodec libx264 -acodec aac -ab 128k -y -movflags +faststart $output_legendado ";
}
}
}
$cmd_con = $ffmpeg." -i $input $query 2>&1 &";
$out = exec($cmd_con);
echo "<pre>";
print_r($out);
echo "</pre>";
}
}
closedir($handle);
}
Ever tried running the code on the command line? It’s always good to separate the presentation part of your page from various routines. Make your code more testable and modularized, so you’ll know what your limits are
– Jefferson Quesado
Do you have an example of how I can run this code on the @Jeffersonquesado command line
– Leo Letto
I’ll need more space than available in comment, wait
– Jefferson Quesado