blob: 60b0a80ae46ceb48129d63811b63e9614401e361 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
<?php
class VideoProcessor
{
protected array $config;
public function __construct (array $config)
{
$this->config = $config;
}
public function process(string $path, bool $pretend = false): bool
{
$path_parts = explode('/', $path);
$filename = $path_parts[count($path_parts) - 1];
$output_path = $this->config['output_path'] . '/' . rtrim($filename, "avi") . "mp4";
$ffmpeg_command = "ffmpeg -i \"$path\" -c:v libx264 -crf 26 -preset fast -c:a aac -b:a 128k \"$output_path\"";
if ($pretend) {
echo "`" . $ffmpeg_command . "`" . PHP_EOL;
} else {
exec($ffmpeg_command);
}
$archive_path = $this->config['archive_path'] . '/' . $filename;
if ($pretend) {
echo "rename($path, $archive_path)" . PHP_EOL;
} else {
rename($path, $archive_path);
}
return true;
}
}
|