laravel - 无法在 Linux 服务器上的 laravel 中使用 ffmpeg 将音频文件转换为 mp3

标签 laravel ffmpeg ffmpeg-php

我安装了 FFmpeg、php-ffmpeg、laravel-ffmpeg。然后我尝试在 laravel 上将视频和音频文件转换为 mp3。

然后它在 Windows10 XAMPP 上正常工作。
但是,当我在我的 linux 共享服务器上安装相同的,

得到错误:Class 'FFMpeg\Format\Audio\mp3' not found

A composer dependency is missing You might be missing a composer dependency. A possible package that was found is php-ffmpeg/extras.

所以,我做了composer require php-ffmpeg/extras并安装,但是,它仍然会产生相同的错误。
那么会有什么问题呢?

VoiceRecController.php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Post;
use App\User;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Auth;
use Illuminate\support\Facades\DB;
use FFMpeg;

class VoiceRecController extends Controller
{

    public function update(Request $request, $id)
    {
        $form = Post::findOrFail($id);

        if($request->capture->extension() == 'mp4'){

            $request->capture->storeAs('public/voice/', $form->id .'.mp4');

            // Open your video file
            $video =FFMpeg::fromDisk('public')->open('/voice/'. $form->id .'.mp4');

            // Set an audio format
            $audio_format = new FFMpeg\Format\Audio\mp3();

            // Extract the audio into a new file as mp3
            $video->save($audio_format, public_path().'/storage/voice/'. $form->id .'.mp3');

            if (file_exists(public_path().'/storage/voice/'. $form->id .'.mp3')){
                \File::delete(public_path().'/storage/voice/'. $form->id .'.mp4');
            }

        }elseif($request->capture->extension() == 'mp3' || $request->capture->extension() == 'mpga'){

            $request->capture->storeAs('public/voice/', $form->id .'.mp3');

        }elseif($request->capture->extension() == 'wav'){

            $request->capture->storeAs('public/voice/', $form->id .'.wav');

            // Open your video file
            $video =FFMpeg::fromDisk('public')->open('/voice/'. $form->id .'.wav');

            // Set an audio format
            $audio_format = new FFMpeg\Format\Audio\mp3();

            // Extract the audio into a new file as mp3
            $video->save($audio_format, public_path().'/storage/voice/'. $form->id .'.mp3');

            if (file_exists(public_path().'/storage/voice/'. $form->id .'.mp3')){
                \File::delete(public_path().'/storage/voice/'. $form->id .'.wav');
            }
        }else{
        $request->capture->store('public/voice/');
        }


        return redirect('/home/mypage');
    }

}

谢谢你。

最佳答案

你得到的错误是因为 Class被称为 \FFMpeg\Format\Audio\Mp3;大写 M .
按照示例代码正确使用它:

FFMpeg::fromDisk('public')
    ->open('song.3gp')
    ->export()
    ->toDisk('public')
    ->inFormat(new \FFMpeg\Format\Audio\Mp3)
    ->save('song_converted.mp3');

关于laravel - 无法在 Linux 服务器上的 laravel 中使用 ffmpeg 将音频文件转换为 mp3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61949633/

相关文章:

php - Laravel 5 : Event class namespacing/class not found

php - Laravel 关系返回 null

javascript - Laravel 注销按钮收到警告消息

ffmpeg - 将容器从 mkv 更改为 m2v - 音频不传输

unix - ffmpeg 未知输入格式 : 'lavfi'

php - 编码一次后尝试使用 PHP-FFMpeg 打开文件

centos 6上的ffmpeg安装错误

laravel - foreach 和同一张表的无限 TreeView

android - FFmpeg 相机编码 h264 mp4 muxing atom avcC 太小

php - 我如何在 laravel 4 中使用 php-FFMpeg?