summaryrefslogtreecommitdiff
path: root/lib/file.php
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-10-01 22:19:15 +0500
committerilotterytea <iltsu@alright.party>2025-10-01 22:19:15 +0500
commit7022695c057d2d3cb526db92de2ffdf54ba8d10e (patch)
treecbd251b9beec397607e5dda6895806ebe4fbefa3 /lib/file.php
parent21c125471b96176bbee0ea8cb8e3ef3b708eb7eb (diff)
feat: remove letterboxing from videos
Diffstat (limited to 'lib/file.php')
-rw-r--r--lib/file.php21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/file.php b/lib/file.php
index 0b250ca..ebfc009 100644
--- a/lib/file.php
+++ b/lib/file.php
@@ -129,4 +129,25 @@ function strip_exif(string $file_path)
$file_path = escapeshellarg($file_path);
$output = shell_exec("exiftool -q -EXIF= $file_path $file_path");
return empty($output);
+}
+
+function remove_video_letterbox(string $input_path, string $output_path)
+{
+ $input_path = escapeshellarg($input_path);
+ $output_path = escapeshellarg($output_path);
+ $output = shell_exec("ffmpeg -nostdin -i $input_path -vf cropdetect=24:16:0 -f null - 2>&1");
+
+ if (preg_match_all('/crop=\d+:\d+:\d+:\d+/', $output, $matches)) {
+ $area = end($matches);
+ $area = end($area);
+ } else {
+ throw new RuntimeException('Could not detect crop parameters. Try upload the video without "Remove letterbox" option.');
+ }
+
+ $area = escapeshellarg($area);
+
+ $output = [];
+ exec("ffmpeg -nostdin -i $input_path -vf $area -c:a copy $output_path 2>&1", $output, $code);
+
+ return $code == 0;
} \ No newline at end of file