[FFmpeg] Copy FFmpeg plugin from v2

This commit is contained in:
Hugo Sales 2021-04-14 15:44:45 +00:00
parent 155f30e816
commit f8199159c3
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -18,18 +18,26 @@
* Animated GIF resize support via PHP-FFMpeg * Animated GIF resize support via PHP-FFMpeg
* *
* @package GNUsocial * @package GNUsocial
*
* @author Bruno Casteleiro <up201505347@fc.up.pt> * @author Bruno Casteleiro <up201505347@fc.up.pt>
* @copyright 2020 Free Software Foundation, Inc http://www.fsf.org * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later * @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'; const PLUGIN_VERSION = '0.1.0';
/**
* Handle resizing GIF files
*/
public function onStartResizeImageFile( public function onStartResizeImageFile(
ImageFile $imagefile, ImageFile $imagefile,
string $outpath, string $outpath,
@ -57,8 +65,8 @@ class FFmpegPlugin extends Plugin
// Create FFMpeg instance // Create FFMpeg instance
// Need to explictly tell the drivers location or it won't find them // Need to explictly tell the drivers location or it won't find them
$ffmpeg = FFMpeg\FFMpeg::create([ $ffmpeg = FFMpeg\FFMpeg::create([
'ffmpeg.binaries' => exec("which ffmpeg"), 'ffmpeg.binaries' => exec('which ffmpeg'),
'ffprobe.binaries' => exec("which ffprobe") 'ffprobe.binaries' => exec('which ffprobe'),
]); ]);
// FFmpeg can't edit existing files in place, // FFmpeg can't edit existing files in place,
@ -131,12 +139,13 @@ class FFmpegPlugin extends Plugin
/** /**
* Suffix version of tempnam. * Suffix version of tempnam.
* Courtesy of tomas at slax dot org: * Courtesy of tomas at slax dot org:
*
* @see https://www.php.net/manual/en/function.tempnam.php#98232 * @see https://www.php.net/manual/en/function.tempnam.php#98232
*/ */
private function tempnam_sfx(string $dir, string $suffix): string private function tempnam_sfx(string $dir, string $suffix): string
{ {
do { do {
$file = $dir . "/" . mt_rand() . $suffix; $file = $dir . '/' . mt_rand() . $suffix;
$fp = @fopen($file, 'x'); $fp = @fopen($file, 'x');
} while (!$fp); } while (!$fp);
@ -150,9 +159,8 @@ class FFmpegPlugin extends Plugin
'version' => self::PLUGIN_VERSION, 'version' => self::PLUGIN_VERSION,
'author' => 'Bruno Casteleiro', 'author' => 'Bruno Casteleiro',
'homepage' => 'https://notabug.org/diogo/gnu-social/src/nightly/plugins/FFmpeg', 'homepage' => 'https://notabug.org/diogo/gnu-social/src/nightly/plugins/FFmpeg',
'rawdescription' => 'rawdescription' => // TRANS: Plugin description.
// TRANS: Plugin description. _m('Use PHP-FFMpeg for resizing animated GIFs'), ];
_m('Use PHP-FFMpeg for resizing animated GIFs')];
return true; return true;
} }
} }