summaryrefslogtreecommitdiff
path: root/app/VideoProcessor.php
diff options
context:
space:
mode:
authorFBeans <phil@pgburton.com>2022-03-06 16:26:07 +0000
committerFBeans <phil@pgburton.com>2022-03-06 16:26:07 +0000
commit88667d540736c39b7a78601d7abb6f3108a7a65c (patch)
treeea13cf9914b502d8749b94db36074defbefc812a /app/VideoProcessor.php
parentcc5e12a25f626dd5b01ca48ecf30661c2168f776 (diff)
Inital commitHEADmain
Diffstat (limited to 'app/VideoProcessor.php')
-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;
+ }
+}