continue;
}
- // Конвертация
+ // Конвертация (вывод в лог-файл, чтобы не переполнять буфер exec)
+ $logFile = Yii::getAlias('@runtime') . '/ffmpeg_last.log';
$cmd = sprintf(
- 'nice -n 19 timeout 600 ffmpeg -y -i %s -c:v libx264 -preset fast -crf 23 -c:a aac -movflags +faststart %s 2>&1',
+ 'nice -n 19 timeout 1800 ffmpeg -y -i %s -c:v libx264 -preset fast -crf 23 -c:a aac -movflags +faststart %s >%s 2>&1',
escapeshellarg($sourcePath),
- escapeshellarg($mp4Path)
+ escapeshellarg($mp4Path),
+ escapeshellarg($logFile)
);
$startTime = microtime(true);
- exec($cmd, $cmdOutput, $returnCode);
+ $returnCode = 0;
+ system($cmd, $returnCode);
$elapsed = round(microtime(true) - $startTime, 1);
if ($returnCode !== 0 || !file_exists($mp4Path)) {
- $error = implode("\n", array_slice($cmdOutput, -5));
+ $error = is_file($logFile) ? implode("\n", array_slice(file($logFile, FILE_IGNORE_NEW_LINES), -5)) : '';
$this->stderr(" — ОШИБКА ({$elapsed}s, code={$returnCode})\n");
Yii::error("ConvertVideo: ошибка #{$file->id}: {$error}", 'video');
if (file_exists($mp4Path)) {
}
}
- $cmdOutput = [];
-
// Пауза между файлами
if ($this->sleep > 0 && $i < $total - 1) {
sleep($this->sleep);