Skip to content

Commit

Permalink
use configuration + automatic detection instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Aug 7, 2023
1 parent 3b65c35 commit 2aa301c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/Image/Handlers/GoogleMotionPictureHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public function load(NativeLocalFile $file, int $videoLength = 0): void
$file->close();

$ffmpeg = FFMpeg::create([
'ffmpeg.binaries' => '/usr/bin/ffmpeg',
'ffprobe.binaries' => '/usr/bin/ffprobe',
'ffmpeg.binaries' => Configs::getValueAsString('ffmpeg_path'),
'ffprobe.binaries' => Configs::getValueAsString('ffprobe_path'),
]);
$audioOrVideo = $ffmpeg->open($this->workingCopy->getRealPath());
if ($audioOrVideo instanceof Video) {
Expand Down
4 changes: 2 additions & 2 deletions app/Image/Handlers/VideoHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function load(NativeLocalFile $file): void
}
try {
$ffmpeg = FFMpeg::create([
'ffmpeg.binaries' => '/usr/bin/ffmpeg',
'ffprobe.binaries' => '/usr/bin/ffprobe',
'ffmpeg.binaries' => Configs::getValueAsString('ffmpeg_path'),
'ffprobe.binaries' => Configs::getValueAsString('ffprobe_path'),
]);
$audioOrVideo = $ffmpeg->open($file->getRealPath());
if ($audioOrVideo instanceof Video) {
Expand Down
64 changes: 64 additions & 0 deletions database/migrations/2023_08_07_182802_add_config_ffmpeg_path.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

use App\Facades\Helpers;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use function Safe\exec;

/**
* Add two new configuration to give the ability to set which path the binaries are found.
*/
return new class() extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
$path_ffmpeg = '/usr/bin/ffmpeg';
$path_ffprobe = '/usr/bin/ffprobe';

if (Helpers::isExecAvailable()) {
try {
$cmd_output_ffmpeg = exec('command -v ffmpeg');
$cmd_output_ffprobe = exec('command -v ffprobe');
} catch (\Exception $e) {
$cmd_output_ffmpeg = false;
$cmd_output_ffprobe = false;
}
$path_ffmpeg = $cmd_output_ffmpeg === false ? '/usr/bin/ffmpeg' : $cmd_output_ffmpeg;
$path_ffprobe = $cmd_output_ffprobe === false ? '/usr/bin/ffprobe' : $cmd_output_ffprobe;
}

DB::table('configs')->insert([
[
'key' => 'ffmpeg_path',
'value' => $path_ffmpeg,
'confidentiality' => 1,
'cat' => 'Image Processing',
'type_range' => 'string',
'description' => 'Path to the binary of ffmpeg',
],
[
'key' => 'ffprobe_path',
'value' => $path_ffprobe,
'confidentiality' => 1,
'cat' => 'Image Processing',
'type_range' => 'string',
'description' => 'Path to the binary of ffprobe',
],
]);
}

/**
* Reverse the migrations.
*
* @throws InvalidArgumentException
*/
public function down(): void
{
DB::table('configs')
->where('key', '=', 'ffmpeg_path')
->orWhere('key', '=', 'ffprobe_path')
->delete();
}
};

0 comments on commit 2aa301c

Please sign in to comment.