how to use or import ffmpeg in a laravel controller

人走茶凉 提交于 2021-01-07 01:27:05

问题


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


回答1:


Use below code in your controller above class

use FFMpeg;
use FFMpeg\Coordinate\Dimension;
use FFMpeg\Format\Video\X264;

Open file using FFMpeg in your controller method

$media = FFMpeg::open($file_path);


来源:https://stackoverflow.com/questions/65087821/how-to-use-or-import-ffmpeg-in-a-laravel-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!