summaryrefslogtreecommitdiff
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
parentcc5e12a25f626dd5b01ca48ecf30661c2168f776 (diff)
Inital commitHEADmain
-rw-r--r--.gitignore1
-rw-r--r--README.md14
-rw-r--r--app/VideoProcessor.php37
-rw-r--r--config/app.php.example7
-rw-r--r--scripts/run.php64
5 files changed, 122 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7a901ba
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+config/app.php
diff --git a/README.md b/README.md
index 98417b0..3fcbc38 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,15 @@
# xplane-video
-Process outputted videos from xplane \ No newline at end of file
+Process outputted videos from xplane
+
+## Configuration
+Copy the `config/app.php.example` file to `config/app.php` and adjust the paths to your preffered options.
+
+## Execution
+`php scripts/run.php` interactively lists videos and allows for specific video processing
+
+`php scripts/run.php --pretend` interactive lists videos and shows what commands would be run without any execution.
+
+## TODO
+Currently the thing that works is processing a single video.
+Eventually this will be able to process multiple videos, and cobine videos!
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;
+ }
+}
diff --git a/config/app.php.example b/config/app.php.example
new file mode 100644
index 0000000..eb5d771
--- /dev/null
+++ b/config/app.php.example
@@ -0,0 +1,7 @@
+<?php
+
+return [
+ 'xplane_path' => FULL PATH TO THE XPLANE DIR,
+ 'archive_path' => WHERE WE COPY THE ORIGINAL XPLANE VIDEOS TOO,
+ 'output_path' => WHERE THE PROCESSED VIDEO WILL END UP,
+];
diff --git a/scripts/run.php b/scripts/run.php
new file mode 100644
index 0000000..0d90f7f
--- /dev/null
+++ b/scripts/run.php
@@ -0,0 +1,64 @@
+<?php
+
+$base_path = realpath(__DIR__ . '/..');
+
+// Load VideoProcessor class
+require_once($base_path . '/app/VideoProcessor.php');
+
+// Load config
+$config = include_once($base_path . '/config/app.php');
+
+// Process arguments
+if (count($argv) === 1) {
+ $pretend = false;
+} else {
+ if (count($argv) > 2) {
+ echo "Error. Too many arguments." . PHP_EOL;
+ exit;
+ }
+
+ if ($argv[1] !== '--pretend') {
+ echo "Error. Argument `" . $argv[1] . "` is not supported." . PHP_EOL;
+ exit;
+ }
+
+ $pretend = true;
+}
+
+$video_processor = new VideoProcessor($config);
+
+// Lets get the list of replays
+$files = glob($config['xplane_path'] . '/Output/*.avi');
+
+echo count($files) . " video file(s) found." . PHP_EOL;
+
+foreach ($files as $index => $file) {
+ $file_path_parts = explode('/', $file);
+ echo "[$index] " . $file_path_parts[count($file_path_parts) - 1] . PHP_EOL;
+}
+
+echo PHP_EOL . "Please enter the video(s) you want to process, or enter 'a' for all!" . PHP_EOL;
+echo "For example, '0,1' will process video 0 and 1 and combine them!" . PHP_EOL;
+
+$handle = fopen("php://stdin", "r");
+$line = trim(fgets($handle), "\n");
+
+if ($line === 'a') {
+ echo "Error. Not yet implemeneted." . PHP_EOL;
+ exit;
+} elseif (strpos($line, ',') !== false) {
+ echo "Error. Not yet implemeneted." . PHP_EOL;
+ exit;
+} else {
+ if (!array_key_exists($line, $files)) {
+ echo "Error: '$line' is not a valid option." . PHP_EOL;
+ exit;
+ }
+
+ $out = $video_processor->process($files[$line], $pretend);
+
+ if ($out) {
+ $pretend_string = $pretend ? '(Pretend) ' : '';
+ echo $pretend_string . "Processing complete!" . PHP_EOL;
+ }
+}