summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/VideoProcessor.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/app/VideoProcessor.php b/app/VideoProcessor.php
new file mode 100644
index 0000000..60b0a80
--- /dev/null
+++ b/app/VideoProcessor.php
@@ -0,0 +1,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;
+ }
+}