John Davidson

php - how to use or import ffmpeg in a laravel controller

0 comments
Message:


i have already installed the laravel-ffmpeg via composer in my project


composer require pbmedia/laravel-ffmpeg

then i added class to config/app.php file as documentation says


// config/app.php


'providers' => [
...
ProtoneMedia\LaravelFFMpeg\Support\ServiceProvider::class,
...
];

'aliases' => [
...
'FFMpeg' => ProtoneMedia\LaravelFFMpeg\Support\FFMpeg::class
...
];

then publish this config file


php artisan vendor:publish --provider="ProtoneMedia\LaravelFFMpeg\Support\ServiceProvider"

now my question is to use this package in my project, how should i use this into my controller
i saw many post and ques regarding this and i get these


use FFMpeg;
use FFMpeg\FFMpeg;
use Pbmedia\LaravelFFMpeg\FFMpeg;
use ProtoneMedia\LaravelFFMpeg\FFMpeg;
.
.
.

which one is correct, my goal is to trim a video, but which one works for that i am so confused


//config/laravel-ffmpeg.php


<?php

return [
'ffmpeg' => [
'binaries' => env('FFMPEG_BINARIES', 'ffmpeg'),
'threads' => 12,
],

'ffprobe' => [
'binaries' => env('FFPROBE_BINARIES', 'ffprobe'),
],

'timeout' => 3600,

'enable_logging' => true,

'set_command_and_error_output_on_exception' => false,
];

please help me out, thanks in advance



My Answer:
[
// Other providers
Pbmedia\LaravelFFMpeg\FFMpegServiceProvider::class,
]

'aliases' => [
// Other aliases
'FFMpeg' => Pbmedia\LaravelFFMpeg\FFMpegFacade::class,
]

__Now, you can use FFMpeg in your Laravel controller by importing the facade and using it like this:__

php
use FFMpeg;

public function convertVideo()
{
FFMpeg::fromDisk('videos')
->open('video.mp4')
->export()
->toDisk('converted_videos')
->inFormat(new X264)
->save('video_converted.mp4');
}


__Make sure to replace the disk names and file names with your actual values.__

Rate this post

5 of 5 based on 1467 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us