From f8199159c39d1220d9f6b59c7c2c9cdd34cbea68 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Wed, 14 Apr 2021 15:44:45 +0000 Subject: [PATCH] [FFmpeg] Copy FFmpeg plugin from v2 --- .../FFmpeg/{FFmpegPlugin.php => FFmpeg.php} | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) rename plugins/FFmpeg/{FFmpegPlugin.php => FFmpeg.php} (85%) diff --git a/plugins/FFmpeg/FFmpegPlugin.php b/plugins/FFmpeg/FFmpeg.php similarity index 85% rename from plugins/FFmpeg/FFmpegPlugin.php rename to plugins/FFmpeg/FFmpeg.php index c939f10edb..7973a1de54 100644 --- a/plugins/FFmpeg/FFmpegPlugin.php +++ b/plugins/FFmpeg/FFmpeg.php @@ -18,22 +18,30 @@ * Animated GIF resize support via PHP-FFMpeg * * @package GNUsocial + * * @author Bruno Casteleiro * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later - * @link http://www.gnu.org/software/social/ + * + * @see http://www.gnu.org/software/social/ */ -defined('GNUSOCIAL') || die(); +namespace Plugin\FFmpeg; -class FFmpegPlugin extends Plugin +use App\Core\Module; +use Plugin\Media\Util\ImageFile; + +class FFmpeg extends Module { const PLUGIN_VERSION = '0.1.0'; + /** + * Handle resizing GIF files + */ public function onStartResizeImageFile( ImageFile $imagefile, string $outpath, - array $box + array $box ): bool { switch ($imagefile->mimetype) { case 'image/gif': @@ -57,8 +65,8 @@ class FFmpegPlugin extends Plugin // Create FFMpeg instance // Need to explictly tell the drivers location or it won't find them $ffmpeg = FFMpeg\FFMpeg::create([ - 'ffmpeg.binaries' => exec("which ffmpeg"), - 'ffprobe.binaries' => exec("which ffprobe") + 'ffmpeg.binaries' => exec('which ffmpeg'), + 'ffprobe.binaries' => exec('which ffprobe'), ]); // FFmpeg can't edit existing files in place, @@ -131,13 +139,14 @@ class FFmpegPlugin extends Plugin /** * Suffix version of tempnam. * Courtesy of tomas at slax dot org: + * * @see https://www.php.net/manual/en/function.tempnam.php#98232 */ private function tempnam_sfx(string $dir, string $suffix): string { do { - $file = $dir . "/" . mt_rand() . $suffix; - $fp = @fopen($file, 'x'); + $file = $dir . '/' . mt_rand() . $suffix; + $fp = @fopen($file, 'x'); } while (!$fp); fclose($fp); @@ -147,12 +156,11 @@ class FFmpegPlugin extends Plugin public function onPluginVersion(array &$versions): bool { $versions[] = ['name' => 'FFmpeg', - 'version' => self::PLUGIN_VERSION, - 'author' => 'Bruno Casteleiro', - 'homepage' => 'https://notabug.org/diogo/gnu-social/src/nightly/plugins/FFmpeg', - 'rawdescription' => - // TRANS: Plugin description. - _m('Use PHP-FFMpeg for resizing animated GIFs')]; + 'version' => self::PLUGIN_VERSION, + 'author' => 'Bruno Casteleiro', + 'homepage' => 'https://notabug.org/diogo/gnu-social/src/nightly/plugins/FFmpeg', + 'rawdescription' => // TRANS: Plugin description. + _m('Use PHP-FFMpeg for resizing animated GIFs'), ]; return true; } }