FFMpeg combined with file upload

Would be awesome to integrate FFMpeg into fileuploading so you can upload videos with filepond and they get resized in a way that the ratio is kept and they are all converted to h264

You can roll this into your own code @ the save() portion of your file upload. There wouldn’t need to be (actually, shouldn’t be) FFMPEG integration at the livewire level as this would overly conflate livewire while narrowing its purpose. Also, if you’re transcoding, you should probably do that on a queue so as not to tie up your main web thread waiting for a response.

And here comes the problem … how can I dispatch a job to the queue in livewire?


namespace App\Http\Livewire;

use App\Http\Requests\StoreVideoRequest;
use App\Jobs\ConvertVideoForStreaming;
use App\Models\Video;
use Livewire\Component;
use Livewire\WithFileUploads;

class Create extends Component
    use WithFileUploads;

    public $video;
    public $title;

    public function render()
        return view('create')->layout('layouts.app');

    public function upload()
            'title' => 'required',
            'video' => 'max:1000000|required|file|mimetypes:video/mp4,video/mpeg,video/x-matroska',

        $video = Video::create([
            'disk'          => 'videos_disk',
            'original_name' => $this->video->getClientOriginalName(),
            'path'          => $this->video->store('/', 'videos_disk'),
            'streaming_path'=> null,
            'title'         => $this->title,

        $this->dispatch(new ConvertVideoForStreaming($video));

        return response()->json([
            'id' => $video->id,
        ], 201);

this doesn’t work because the dispatch trait doesn’t exist for the livewire component


Method App\Http\Livewire\Create::dispatch does not exist.


Hide solutions

## Bad Method Call

Did you mean App\Http\Livewire\Create::getDispatchQueue() ?

and if i add the trait like


namespace Livewire;

use Illuminate\View\View;
use BadMethodCallException;
use Illuminate\Support\Str;
use Illuminate\Routing\Route;
use Illuminate\Support\ViewErrorBag;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Container\Container;
use Livewire\Exceptions\CannotUseReservedLivewireComponentProperties;
use Livewire\Exceptions\PropertyNotFoundException;
use DispatchesJobs;

abstract class Component
    use Macroable { __call as macroCall; }

    use ComponentConcerns\ValidatesInput,

it still doesn’t work same error message

I also tried to use getDispatchQueue() but that doesnt work either.

How can I tell livewire to call a jobclass and add the job to the queue?

Solved by @skywalker needed to put the trait in the Create class after use FileUploads.

1 Like

Hey, @reniar1

I’m Glade one of my answers fit your need, can you please refer to it?