mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Add Video jobs
This commit is contained in:
parent
836030c527
commit
7c85a6178c
2 changed files with 96 additions and 0 deletions
34
app/Jobs/VideoPipeline/VideoPostProcess.php
Normal file
34
app/Jobs/VideoPipeline/VideoPostProcess.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs\VideoPipeline;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
||||
class VideoPostProcess implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
62
app/Jobs/VideoPipeline/VideoThumbnail.php
Normal file
62
app/Jobs/VideoPipeline/VideoThumbnail.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs\VideoPipeline;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use FFMpeg;
|
||||
use App\Media;
|
||||
|
||||
class VideoThumbnail implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $media;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Media $media)
|
||||
{
|
||||
$this->media = $media;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$media = $this->media;
|
||||
$base = $media->media_path;
|
||||
$path = explode('/', $base);
|
||||
$name = last($path);
|
||||
try {
|
||||
$t = explode('.', $name);
|
||||
$t = $t[0].'_thumb.png';
|
||||
$i = count($path) - 1;
|
||||
$path[$i] = $t;
|
||||
$save = implode('/', $path);
|
||||
$video = FFMpeg::open($base);
|
||||
if($video->getDurationInSeconds() < 1) {
|
||||
$video->getFrameFromSeconds(1);
|
||||
} elseif($video->getDurationInSeconds() < 5)
|
||||
$video->getFrameFromSeconds(4);
|
||||
}
|
||||
$video->export()
|
||||
->save($save);
|
||||
|
||||
$media->thumbnail_path = $save;
|
||||
$media->save();
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue